[PATCH] D146699: [GuardWidening] Freeze the introduced use.

Serguei Katkov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 23 01:20:46 PDT 2023


skatkov created this revision.
skatkov added reviewers: apilipenko, mkazantsev, reames, nikic.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
skatkov requested review of this revision.
Herald added a project: LLVM.

Guard widening optimization is able to move the condition from one
guard to the previous one. As a result if the condition is poison
and orginal second guard is never executed but the first one does,
we introduce undefined behavior which was not observed in original
program.

To resolve the issue we must freeze the condition we are moving.
However optimization itself does not know how to work with freeze.
Additionally optimization is written in incremental way.
For example we have three guards
G1(base + 8 < L)
G2(base + 16 < L)
G3(base + 24 < L)

On the first step GW will combine G1 and G2 as
G1(base + 8 < L && freeze(base + 16 < L))
G2(true)
G3(base + 24 < L)
while combining G1 and G3 base appears to be different.

To keep optimization enabled after freezing the moving condition, the
freeze instruction is pushed as much as possible and later all uses
of frozen values are replaced with frozen version.

This is similar what instruction combining does but more aggressively.


https://reviews.llvm.org/D146699

Files:
  llvm/lib/Transforms/Scalar/GuardWidening.cpp
  llvm/test/Transforms/GuardWidening/basic-loop.ll
  llvm/test/Transforms/GuardWidening/basic.ll
  llvm/test/Transforms/GuardWidening/basic_widenable_condition_guards.ll
  llvm/test/Transforms/GuardWidening/hang.ll
  llvm/test/Transforms/GuardWidening/loop-schedule.ll
  llvm/test/Transforms/GuardWidening/loop_invariant_widenable_condition.ll
  llvm/test/Transforms/GuardWidening/mixed_guards.ll
  llvm/test/Transforms/GuardWidening/posion.ll
  llvm/test/Transforms/GuardWidening/range-check-merging.ll
  llvm/test/Transforms/GuardWidening/two_forms_behavior_consistency.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146699.507639.patch
Type: text/x-patch
Size: 50512 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230323/c57590bf/attachment-0001.bin>


More information about the llvm-commits mailing list