This is an archive of the discontinued LLVM Phabricator instance.

[GuardWidening] Choose right point for generating wide condition for branches. PR60234
ClosedPublic

Authored by mkazantsev on Jan 26 2023, 11:46 PM.

Details

Summary

When guards are represented as widenable branches, there is a tricky
situation when the branch stays in loop but widenable condition doesn't.
It means that the widenable condition is loop-invariant, and some other
optimizations could have done changes using this fact.

If widening is allowed to create widened condition inside this loop,
and join the loop-invariant wc with some non-invariant facts, it can
cause miscompile. See example of this at https://github.com/llvm/llvm-project/issues/60234.

The solution is to adjust the point of generationg the wide condition,
and therefore of hoisting all related parts there. It should not be before
the branch, but before the widenable_condition call. The fact that wc()
and the wide condition are in the same block guarantees that they will
not violate the invariance property for any loop.

Diff Detail

Event Timeline

mkazantsev created this revision.Jan 26 2023, 11:46 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 26 2023, 11:46 PM
mkazantsev requested review of this revision.Jan 26 2023, 11:46 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 26 2023, 11:46 PM
apilipenko accepted this revision.Jan 30 2023, 11:03 AM
This revision is now accepted and ready to land.Jan 30 2023, 11:03 AM
This revision was landed with ongoing or failed builds.Jan 30 2023, 10:13 PM
This revision was automatically updated to reflect the committed changes.
mkazantsev reopened this revision.Jan 31 2023, 4:12 AM
This revision is now accepted and ready to land.Jan 31 2023, 4:12 AM