Issue 135182
Summary [IndVarSimplify] Miscompilation at -O3
Labels miscompilation, loopoptim
Assignees dtcxzyw
Reporter dtcxzyw
    Reproducer: https://godbolt.org/z/zcneEahn3
```
; bin/opt -passes=indvars test.ll -S
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_150 = global [1 x [9 x i32]] [[9 x i32] [i32 -581671216, i32 -581671216, i32 -581671216, i32 -581671216, i32 -581671216, i32 -581671216, i32 -581671216, i32 -581671216, i32 -581671216]]
@crc32_context = global i32 -1
@crc32_tab = global [256 x i32] zeroinitializer
@.str.24 = constant [15 x i8] c"checksum = %X\0A\00"

define i32 @main() {
entry:
  call fastcc void @crc32_gentab()
  %call2 = call fastcc i32 @func_125()
  %0 = load i32, ptr @g_150, align 4
  %conv13 = sext i32 %0 to i64
  call fastcc void @transparent_crc(i64 %conv13)
  %1 = load i32, ptr @crc32_context, align 4
 call fastcc void @platform_main_end(i32 %1)
  ret i32 0
}

define fastcc void @crc32_gentab() {
entry:
  store i32 1, ptr @crc32_tab, align 4
  ret void
}

define fastcc i32 @func_125() {
entry:
  br label %for.body21

for.body21:                                       ; preds = %for.body21, %entry
  %storemerge629 = phi i8 [ -12, %entry ], [ %dec, %for.body21 ]
  %conv29 = sext i8 %storemerge629 to i16
  %conv1.i = sext i8 %storemerge629 to i16
  %add.i = add i16 %conv29, %conv1.i
  %conv55 = zext i16 %add.i to i32
  store i32 %conv55, ptr @g_150, align 4
  %dec = add i8 %storemerge629, 1
  br i1 false, label %for.body21, label %for.end234

for.end234:                                       ; preds = %for.body21
  ret i32 0
}

define fastcc void @transparent_crc(i64 %val) {
entry:
  %shr4.i = lshr i64 %val, 16
  %idxprom.i.i = and i64 %shr4.i, 1
  %arrayidx.i.i = getelementptr [256 x i32], ptr @crc32_tab, i64 0, i64 %idxprom.i.i
  %0 = load i32, ptr %arrayidx.i.i, align 4
  store i32 %0, ptr @crc32_context, align 4
  ret void
}

declare i32 @printf(ptr, ...)

define fastcc void @platform_main_end(i32 %crc) {
entry:
  %call = call i32 (ptr, ...) @printf(ptr @.str.24, i32 %crc)
  ret void
}
```
Output:
```
define fastcc i32 @func_125() {
  br label %for.body21

for.body21:                                       ; preds = %for.body21, %entry
  store i32 131048, ptr @g_150, align 4
  br i1 false, label %for.body21, label %for.end234

for.end234: ; preds = %for.body21
  ret i32 0
}
```
`store i32 131048, ptr @g_150, align 4` should be `store i32 65512, ptr @g_150, align 4`
llvm version: f819f46284f2a79790038e1f6649172789734ae8

_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to