[all-commits] [llvm/llvm-project] 0b5bb6: [GuardWidening] Freeze the introduced use. Re-land.

serguei-katkov via All-commits all-commits at lists.llvm.org
Wed Mar 29 21:36:43 PDT 2023

  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 0b5bb6923f09ebc257ebed4ace1d8b6b113b2bf5
  Author: Serguei Katkov <serguei.katkov at azul.com>
  Date:   2023-03-30 (Thu, 30 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. Re-land.

Non-determenism is fixed.

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.

More information about the All-commits mailing list