Issue 154612
Summary SimplifyCFG causes miscompilation
Labels new issue
Assignees
Reporter zitongzhoueric
    To reproduce: https://alive2.llvm.org/ce/z/EYrmpE
This LLVM IR code is flagged for miscompilation when using simplifycfg
```
define dso_local i32 @src() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store i32 0, ptr %1, align 4
  store i32 4, ptr %2, align 4
  %5 = load i32, ptr %2, align 4
  %6 = load i32, ptr %2, align 4
  %7 = add nsw i32 %5, %6
  %8 = load i32, ptr %2, align 4
  %9 = load i32, ptr %2, align 4
  %10 = add nsw i32 %8, %9
  %11 = mul nsw i32 %7, %10
  %12 = sext i32 %11 to i64
  %13 = inttoptr i64 %12 to ptr
  store ptr %13, ptr %3, align 8
  store ptr %3, ptr %4, align 8
  %14 = load ptr, ptr %3, align 8
  %15 = load i32, ptr %14, align 4
  %16 = icmp ne i32 %15, 0
  br i1 %16, label %17, label %18

17:
  store i32 1, ptr %1, align 4
  br label %32

18:
  %19 = load ptr, ptr %4, align 8
  %20 = load ptr, ptr %19, align 8
  %21 = load i32, ptr %20, align 4
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %23, label %24

23:
  store i32 1, ptr %1, align 4
  br label %32

24:
  %25 = load ptr, ptr %4, align 8
 %26 = load ptr, ptr %25, align 8
  store i32 1, ptr %26, align 4
  br label %27

27:
  %28 = load i32, ptr %2, align 4
  %29 = icmp ne i32 %28, 0
 br i1 %29, label %30, label %31

30:
  store i32 0, ptr %1, align 4
  br label %32

31:
  store i32 1, ptr %1, align 4
  br label %32

32:
 %33 = load i32, ptr %1, align 4
  ret i32 %33
}

attributes #0 = { noinline nounwind uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to