Issue 237850
Summary [AArch64] Big-endian: i1-vector argument passed on the stack is silently miscompiled
Labels
Assignees
Reporter dongjianqiang2
    On aarch64_be, when a fixed-width i1-vector argument does not fit the NEON argument registers and is passed on the stack (here: after four
<4 x i64> arguments), the callee reconstructs it wrongly: only the last lane survives, the rest read as zero — and some patterns crash at runtime. Assertion builds catch it instead:

```
llc: llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:7375:
llvm::SelectionDAG::getNode(...): Assertion `VT.isInteger() &&
N1.getValueType().isInteger() && "Invalid TRUNCATE!"' failed.
Stack dump:
2.      Running pass 'AArch64 Instruction Selection' on function '@f'
```

Built from getCopyFromParts during SelectionDAGISel::LowerArguments: an ISD::TRUNCATE with a non-integer operand. No SVE and no attributes are needed — plain `llc -mtriple=aarch64_be-linux-gnu`. Reproducer (self-checking; the caller passes mask <1,0,1,0>, the callee reads it back and exits with 100 + observed value):

```llvm
target datalayout = "E-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32"
target triple = "aarch64_be-linux-gnu"

@mbuf = global i64 zeroinitializer, align 8

define void @f(<4 x i64> %v0, <4 x i64> %v1, <4 x i64> %v2, <4 x i64> %v3,
               <4 x i1> %m) {
entry:
  %e0 = extractelement <4 x i1> %m, i32 0
  %e1 = extractelement <4 x i1> %m, i32 1
  %e2 = extractelement <4 x i1> %m, i32 2
  %e3 = extractelement <4 x i1> %m, i32 3
  %z0 = zext i1 %e0 to i64
  %z1 = zext i1 %e1 to i64
  %z2 = zext i1 %e2 to i64
  %z3 = zext i1 %e3 to i64
  %s1 = shl i64 %z1, 1
  %s2 = shl i64 %z2, 2
  %s3 = shl i64 %z3, 3
  %o1 = or i64 %z0, %s1
  %o2 = or i64 %s2, %s3
  %om = or i64 %o1, %o2
  store i64 %om, ptr @mbuf
  ret void
}

define void @_start() {
entry:
  call void @f(<4 x i64> zeroinitializer,
               <4 x i64> zeroinitializer,
               <4 x i64> zeroinitializer,
               <4 x i64> zeroinitializer,
               <4 x i1> <i1 1, i1 0, i1 1, i1 0>)
  %lm = load i64, ptr @mbuf
  %bad = icmp ne i64 %lm, 5
  br i1 %bad, label %report, label %ok
report:
  ; exit(100 + observed mask value) so the exit code shows what arrived
  %obs = and i64 %lm, 255
  %code = add i64 %obs, 100
  call void asm sideeffect "mov x8, #93\0Asvc #0", "{x0},~{x8}"(i64 %code)
  unreachable
ok:
  call void asm sideeffect "mov x8, #93\0Amov x0, #0\0Asvc #0", "~{x8}"()
  unreachable
}
```

Results (run statically under qemu-aarch64_be; LE = same IR with LE datalayout/triple):

- LE: exit 0 — the mask reads 5, for every mask pattern below.
- BE, Release: compiles with no diagnostic. Mask patterns:
  `<1,0,1,0>` reads **0** (exit 100), `<0,1,0,1>` reads **8**,
  `<0,0,0,1>` reads 8 (correct — nothing to lose in the low lanes); with
  `-mattr=+sve` the first run even segfaulted, later runs read 8. The
  callee reads the wrong stack slot: whatever is left there, not the
  mask.
- BE, assertions: the assertion above.

https://godbolt.org/z/hn9ehWd5b

With three or fewer <4 x i64> arguments the mask stays in a NEON register and everything works — the stack-passed case is the broken one.
test/CodeGen/AArch64/fixed-length-sve-interleave.ll (<4 x i1>) and combine-storetomstore.ll (<8 x i1>) hit the same assertion with `-mtriple=aarch64_be -mattr=+sve` on an assertions build, and compile silently otherwise.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to