<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/154612>154612</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
SimplifyCFG causes miscompilation
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
zitongzhoueric
</td>
</tr>
</table>
<pre>
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" }
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJysll-P4yYbxT8NvkEe4Qf_vfBFZrJ59Urbm3ZVqVcVtrFDi8ECPMnOp6-wHSeZOrMdaaWRBszPh8N5CIZZKzrFeYmSZ5TsAza6ozblm3BadW9HPXIj6qDSzffym8aGD0Y3Y80R3eGjc4NFdIfggODApHjl8CTla_-kTYfgUHMEhzcEhy9_mH74gsju21FY_PXr77_g__-Ka91wLCxuJes63uBWG9wLW-t-EJI5oRU-HbnCoxWqw1b0gxTt97rtENmhlCx_ZNfwViiOG6v_lLpmEgsKGMXEmhpBjqDACCjBKHtGZIcxgiTCiO4xkx73NIIXzKToFI4vCPwYobfI4MwVyS9I_APEOm345Jf4ocGZyd77ya5YfINteUqmCaVmzcX0B3D6GTibl9I0WNnTHDEkiQe90oXKPyNZfAaOyJaBfDFQrNhc236Ut1i2YBFZubnAlp_dBYoi7DQW6XXKucJCOae9M5HGy6tOT9W81uZSOXqzCrpd7dvRpR1vbJ0ovqaz7JxHup5-WPgo3gpzLr2o-wErvgYwlXOOqDJYRDPqH0pWcTl1s_uud4DILsr8OXC_V6OPtnRlriIUFpH8IuLfKB6tfystII_oqNjCo4dbj2wdBrAVF0QbcQHc5QP0vhvPKwX6E-KC-CYuSP5rXB5OH8GQPD6ibg1C-pFDyBaH2a3DT50NUGxGnq-RXxMv7iKm5L4bzVYo-XfiH565W4nT6CeUjcIi4p_Rhz_b91KGrwcVpV4p2896zDkjqtFxu3zn6N5_67DSQkn_YVR6VCehGjyeHKskxwigNazn4aCFctwgAET3CIBJifxeB-iFCiXvmAxfee20CU-icccVJAumdOgMGwahurBnN4AzI18Y61j9dzgY7WalamxbbkIr3viK5wvrmOm4C-thXIfOeRqm8f14y5kbDbcrhOC57vUr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