[all-commits] [llvm/llvm-project] f4b236: [GuardWidening] Freeze the introduced use.

serguei-katkov via All-commits all-commits at lists.llvm.org
Wed Mar 29 02:31:14 PDT 2023

  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: f4b2360cecd4c92e85bccb1443f2ef425fc6a77b
  Author: Serguei Katkov <serguei.katkov at azul.com>
  Date:   2023-03-29 (Wed, 29 Mar 2023)

  Changed paths:
    M llvm/lib/Transforms/Scalar/GuardWidening.cpp
    M llvm/test/Transforms/GuardWidening/basic-loop.ll
    M llvm/test/Transforms/GuardWidening/basic.ll
    M llvm/test/Transforms/GuardWidening/basic_widenable_condition_guards.ll
    M llvm/test/Transforms/GuardWidening/hang.ll
    M llvm/test/Transforms/GuardWidening/loop-schedule.ll
    M llvm/test/Transforms/GuardWidening/loop_invariant_widenable_condition.ll
    M llvm/test/Transforms/GuardWidening/mixed_guards.ll
    M llvm/test/Transforms/GuardWidening/posion.ll
    M llvm/test/Transforms/GuardWidening/profile-based-profitability-intrinsics.ll
    M llvm/test/Transforms/GuardWidening/profile-based-profitability_explicit.ll
    M llvm/test/Transforms/GuardWidening/range-check-merging.ll
    M llvm/test/Transforms/GuardWidening/two_forms_behavior_consistency.ll

  Log Message:
  [GuardWidening] Freeze the introduced use.

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

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))
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 freezed values are replaced with frozen version.

This is similar what instruction combining does but more aggressevely.

Reviewed By: mkazantsev
Differential Revision: https://reviews.llvm.org/D146699

More information about the All-commits mailing list