DeadStoreElimination does eliminate a store if it stores a value which was loaded from the same memory location.
So far this worked only if the store is in the same block as the load. This patch allows that the load is in another block than the store.
Example:
define i32 @test26(i1, i32*) {
entry:
%l2 = load i32, i32* %1, align 4 br i1 %0, label %bb1, label %bb2
bb1:
br label %bb3
bb2:
; This store is redundant store i32 %l2, i32* %1, align 4 br label %bb3
bb3:
ret i32 0
}
I think you'd be better to phrase the non-local query here so that it benefits both sub-optimizations.