[PATCH] D142693: [GuardWidening] Choose right point for generating wide condition for branches. PR60234

Max Kazantsev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 26 23:46:37 PST 2023


mkazantsev created this revision.
mkazantsev added reviewers: apilipenko, skatkov, reames, anna.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
mkazantsev requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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.


https://reviews.llvm.org/D142693

Files:
  llvm/lib/Transforms/Scalar/GuardWidening.cpp
  llvm/test/Transforms/GuardWidening/basic_widenable_condition_guards.ll
  llvm/test/Transforms/GuardWidening/loop_invariant_widenable_condition.ll
  llvm/test/Transforms/GuardWidening/mixed_guards.ll
  llvm/test/Transforms/GuardWidening/pr60234.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142693.492651.patch
Type: text/x-patch
Size: 17057 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230127/699e0ca0/attachment-0001.bin>


More information about the llvm-commits mailing list