https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106114

--- Comment #7 from Andrew Macleod <amacleod at redhat dot com> ---
The routine which tries to fold relations in && or || statements is getting
stale information.

GORI maintains a dependency cache which is mostly use by the temporal mechanism
to decide when statements are out of date.  It is a shortcut that is used to
prevent constant re-scanning of statements to find any ssa-names in the operand
list.

AS its intended use is dependency tracking, it is allowed to get out of date if
statements are rewritten (additional dependencies may just result in missed
opportunities)

IN this case, _16 and _17 is dependent on a.0_1, and DOM rewrites them, and
eventually the new name a.1_15 is processed and that dependency is added.

relation_fold_and_or erroneously accesses these cache values thinking its a
shortcut to looking at the statements, and then things the 2 relations feeding 
_18 = _16 | _17
are  comparisons between a.0_1 and a.1_15, and with a < and >=,  decides the
condition can be folded.

Using the cache for this purpose is incorrect.  Instead, it should simply query
the operands and ensure they are both ssa-names, and proceed.

Patch in testing.

This is less likely to occur in GCC12 as less places rewrite the IL under the
covers, but it should still be applied ot that branch just in case.

Reply via email to