Missed dead store elimination on the normal path due to the presence of an unwind edge
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
The following reduced IR is derived from https://github.com/LibRaw/LibRaw/blob/71581b37ae323b46d038f9710b438b6be919a87a/src/utils/open.cpp#L262
In the reduced IR, the two `store i32 0, ptr %4, align 4` instructions are redundant.
Similar patterns have also been observed in other projects, such as [Ipopt](https://github.com/coin-or/Ipopt/blob/4667204c76e534d3e4df6b1462f258a4f9c681bd/src/LinAlg/IpDenseVector.cpp#L22) and [EASTL](https://github.com/electronicarts/EASTL/blob/e323f67e5d93fdadcd44f7998069d804697b1945/test/source/TestTupleVector.cpp#L15).
https://godbolt.org/z/f3oG4oGaE
```llvm
declare ptr @_Znwm() local_unnamed_addr
define noundef i32 @_ZN6LibRaw10open_bayerEPKhjtttttthhjjj(ptr writeonly captures(none) %0, i1 %cond) local_unnamed_addr personality ptr null {
%2 = invoke ptr @_Znwm(i64 0)
to label %3 unwind label %5
3:
%4 = getelementptr i8, ptr %0, i64 540
store i32 0, ptr %4, align 4
br i1 %cond, label %7, label %8
5:
%6 = landingpad { ptr, i32 }
cleanup
catch ptr null
resume { ptr, i32 } zeroinitializer
7:
store i64 0, ptr %0, align 8
br label %8
8:
store i32 0, ptr %4, align 4
ret i32 0
}
```
Expected:
```llvm
define noundef i32 @_ZN6LibRaw10open_bayerEPKhjtttttthhjjj(ptr writeonly captures(none) %0, i1 %cond) local_unnamed_addr personality ptr null {
%2 = invoke ptr @_Znwm(i64 0)
to label %3 unwind label %4
3:
br i1 %cond, label %6, label %7
4:
%5 = landingpad { ptr, i32 }
cleanup
catch ptr null
resume { ptr, i32 } zeroinitializer
6:
store i64 0, ptr %0, align 8
br label %7
7:
%8 = getelementptr i8, ptr %0, i64 540
store i32 0, ptr %8, align 4
ret i32 0
}
```
Contributor guide
Assessment
This issue has not been assessed yet.