Issue 175303
Summary [X86][SDAG] Miscompilation at O2
Labels backend:X86, miscompilation, llvm:SelectionDAG, generated by fuzzer
Assignees dtcxzyw
Reporter dtcxzyw
    Reproducer: https://godbolt.org/z/a9s4dE8vW
```
; bin/lli test.ll
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@g_223 = global i8 1
@.str.37 = constant [15 x i8] c"checksum = %X\0A\00"

define i32 @main() {
entry:
  %g_223.promoted.i = load i8, ptr @g_223, align 1
  %0 = insertelement <16 x i8> zeroinitializer, i8 %g_223.promoted.i, i64 0
  %1 = add <16 x i8> %0, <i8 -1, i8 -2, i8 -3, i8 -4, i8 -5, i8 -6, i8 -7, i8 -8, i8 -9, i8 -10, i8 -11, i8 -12, i8 -13, i8 -14, i8 -15, i8 -16>
  %2 = lshr <16 x i8> %1, splat (i8 6)
  %3 = shl <16 x i8> splat (i8 1), %2
  %4 = tail call i8 @llvm.vector.reduce.xor.v16i8(<16 x i8> %3)
  %conv5 = zext i8 %4 to i32
  %call.i1754 = tail call i32 (ptr, ...) @printf(ptr @.str.37, i32 %conv5)
  ret i32 0
}

declare i32 @printf(ptr, ...)
```
lli output:
```
checksum = 21
```
llubi output:
```
Entering function main
  %g_223.promoted.i = load i8, ptr @g_223, align 1 -> i8 1
  %0 = insertelement <16 x i8> zeroinitializer, i8 %g_223.promoted.i, i64 0 -> { i8 1, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0 }
  %1 = add <16 x i8> %0, <i8 -1, i8 -2, i8 -3, i8 -4, i8 -5, i8 -6, i8 -7, i8 -8, i8 -9, i8 -10, i8 -11, i8 -12, i8 -13, i8 -14, i8 -15, i8 -16> -> { i8 0, i8 -2, i8 -3, i8 -4, i8 -5, i8 -6, i8 -7, i8 -8, i8 -9, i8 -10, i8 -11, i8 -12, i8 -13, i8 -14, i8 -15, i8 -16 }
  %2 = lshr <16 x i8> %1, splat (i8 6) -> { i8 0, i8 3, i8 3, i8 3, i8 3, i8 3, i8 3, i8 3, i8 3, i8 3, i8 3, i8 3, i8 3, i8 3, i8 3, i8 3 }
  %3 = shl <16 x i8> splat (i8 1), %2 -> { i8 1, i8 8, i8 8, i8 8, i8 8, i8 8, i8 8, i8 8, i8 8, i8 8, i8 8, i8 8, i8 8, i8 8, i8 8, i8 8 }
  %4 = tail call i8 @llvm.vector.reduce.xor.v16i8(<16 x i8> %3) -> i8 9
  %conv5 = zext i8 %4 to i32 -> i32 9
  %call.i1754 = tail call i32 (ptr, ...) @printf(ptr @.str.37, i32 %conv5)
    Printf: checksum = 9
   -> i32 13
  ret i32 0
Exiting function main
```
When you replace `%g_223.promoted.i` with 1, the return value is constant folded to 9.

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to