| Issue |
114194
|
| Summary |
[X86][CodeGen] Miscompilation due to transformation in LiveRangeShrink
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
MuellerMP
|
Invoking LLC with the sample IR code below results in a miscompile:
The reload of spilled stack values is hoisted in front of the start of a landingpad, resulting in undefined behavior when unwinding.
The issue can be reproduced in godbolt: https://llvm.godbolt.org/z/rnxzE19eP
If we look at the opt pipeline viewer, we can see that lrshrink is hoisting the add for two phis in front of the EHLabel.
Sample IR code:
```llvm
target triple = "x86_64-unknown-linux-gnu"
declare i32 @__gxx_personality_v0(...)
declare void @maythrow()
declare void @cleanup(i32)
@external_bool = external global i1
@externalA = external global i32
@externalB = external global i32
@externalC = external global i32
@externalD = external global i32
define void @test() personality ptr @__gxx_personality_v0 {
%1 = load i1, ptr @external_bool
br i1 %1, label %branchA, label %branchB
branchA:
%valueA = load i32, ptr @externalA
%valueC = load i32, ptr @externalC
; force spill
call void asm sideeffect "", "~{rbp},~{rsi},~{rdi},~{rcx},~{rbx},~{r12},~{r13},~{r14},~{r15},~{flags}"()
invoke void @maythrow() to label %end unwind label %lpad
branchB:
%valueB = load i32, ptr @externalB
%valueD = load i32, ptr @externalD
; force spill
call void asm sideeffect "", "~{rbp},~{rsi},~{rdi},~{rcx},~{rbx},~{r12},~{r13},~{r14},~{r15},~{flags}"()
invoke void @maythrow() to label %end unwind label %lpad
lpad:
%phiValue = phi i32 [%valueA, %branchA], [%valueB, %branchB]
%phiValue2 = phi i32 [%valueC, %branchA], [%valueD, %branchB]
%lp = landingpad { ptr, i32 }
cleanup
%3 = add i32 %phiValue2, %phiValue
call void @cleanup(i32 %3)
resume { ptr, i32 } %lp
end:
ret void
}
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs