| Issue |
159610
|
| Summary |
[LoongArch64] Miscompilation at -O2/O3
|
| Labels |
miscompilation,
backend:loongarch
|
| Assignees |
|
| Reporter |
XChy
|
Testcase:
```llvm
target datalayout = "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128"
target triple = "loongarch64-unknown-linux-musl"
@BS_CHECKSUM = global i64 0
@.str = constant [32 x i8] c"BackSmith Checksum = 0x%016llx\0A\00"
define i64 @func_14() {
entry:
callbr void asm sideeffect "", "!i"()
to label %asm.fallthrough [label %BS_LABEL_0]
asm.fallthrough: ; preds = %entry
br label %BS_LABEL_0
BS_LABEL_0: ; preds = %BS_LABEL_0, %asm.fallthrough, %entry
%l_1780.1 = phi i16 [ 0, %BS_LABEL_0 ], [ 0, %entry ], [ 1, %asm.fallthrough ]
%p_16.addr.0 = phi i32 [ 0, %BS_LABEL_0 ], [ 1, %entry ], [ 0, %asm.fallthrough ]
callbr void asm sideeffect "", "!i"()
to label %asm.fallthrough66 [label %BS_LABEL_0]
asm.fallthrough66: ; preds = %BS_LABEL_0
%0 = insertelement <4 x i32> zeroinitializer, i32 %p_16.addr.0, i64 0
%vecinit5 = insertelement <4 x i32> %0, i32 %p_16.addr.0, i64 1
%conv6 = zext <4 x i32> %vecinit5 to <4 x i64>
%vecext = extractelement <4 x i64> %conv6, i64 0
%tobool25.not = icmp eq i64 %vecext, 0
%cond = select i1 %tobool25.not, i64 1, i64 -1
%1 = insertelement <4 x i64> zeroinitializer, i64 %cond, i64 0
%vecext29 = extractelement <4 x i64> %conv6, i64 1
%tobool30.not = icmp eq i64 %vecext29, 0
%cond35 = select i1 %tobool30.not, i64 1, i64 -1
%vecinit61 = insertelement <4 x i64> %1, i64 %cond35, i64 1
%vecext62 = extractelement <4 x i64> %vecinit61, i16 %l_1780.1
store i64 %vecext62, ptr @BS_CHECKSUM, align 8
ret i64 0
}
define i32 @main() {
entry:
%call2 = call i64 @func_14()
%0 = load i64, ptr @BS_CHECKSUM, align 8
%call1 = call i32 (ptr, ...) @printf(ptr @.str, i64 %0)
ret i32 0
}
```
Commands:
```bash
> clang --target=loongarch64-unknown-linux-musl --gcc-toolchain=/opt/loongarch64 --sysroot=/opt/loongarch64/loongarch64-unknown-linux-musl/sysroot -DARCH_LOONGARCH64 -static -O2 reduced.ll
> qemu-loongarch64 a.out
BackSmith Checksum = 0xffffffffffffffff
```
```bash
> clang --target=loongarch64-unknown-linux-musl --gcc-toolchain=/opt/loongarch64 --sysroot=/opt/loongarch64/loongarch64-unknown-linux-musl/sysroot -DARCH_LOONGARCH64 -static -O0 reduced.ll
> qemu-loongarch64 a.out
BackSmith Checksum = 0x0000000000000001
```
This testcase is run with [llubi](https://github.com/dtcxzyw/llvm-ub-aware-interpreter), and shows no UB. Let me know if you want unreduced C testcase.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs