https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90036
--- Comment #16 from Jeffrey A. Law <law at gcc dot gnu.org> ---
So it's not full formed yet, but a bit of framework where we could detect this
case is starting to form. I want to get this recorded for future work.
The key blocks (using a gcc-15 development compiler) look something like this:
;; basic block 2, loop depth 0
;; pred: ENTRY
_1 = vptr_14(D) == 0;
_2 = ownvptr_15(D) != 0;
_3 = _1 | _2;
if (_3 != 0)
goto <bb 4>; [67.00%]
else
goto <bb 3>; [33.00%]
;; succ: 4
;; 3
;; basic block 3, loop depth 0
;; pred: 2
[ blah blah blah ]
if (definition_29 != 0)
goto <bb 8>; [100.00%]
else
goto <bb 9>; [0.00%]
;; succ: 8
;; 9
;; basic block 4, loop depth 0
;; pred: 2
if (vptr_14(D) != 0)
goto <bb 5>; [25.37%]
else
goto <bb 9>; [74.63%]
;; succ: 5
;; 9
;; basic block 5, loop depth 0
;; pred: 4
# definition_10 = PHI <0(4)>
# vstring_9 = PHI <0B(4)>
if (_2 != 0)
goto <bb 7>; [80.00%]
else
goto <bb 6>; [20.00%]
What we want to prove is that _2 must have the value 0 if we have reached block
#5 so that we can statically prove bb5 never transfers control to bb6. How do
we do that.
When we traverse 2->4 we will record that _3 is nonzero. When we traverse 4->5
we record that vptr_14 is nonzero. This is already in place.
When we record that vptr_14 is nonzero we could look at the uses of vptr_14 and
see if any of those simplify. In this case we would be able to note that _1 is
zero and we can record that as a conditional equivalence on the 4->5 edge. I
suspect this is similar to the backpropagation bits already in DOM. That in
turn means that we know the value of _2 as well as ownvptr_15 != 0 which can be
recorded as conditional equivalences as well. We might need to use the
Ranger's solver for those.
Thus when we get into bb5 we have a conditional equivalence that _2 != 0 which
allows us to statically route block 5 to block 7, skipping block 6 which has
the unreachable NULL use.
I think where's an old Wuninitialized regression that would likely be fixed by
that scheme as well. I haven't walked through things deeply, but it seems
viable at the surface.