[PATCH] D136233: [SimpleLoopUnswitch] Inject loop-invariant conditions and unswitch them when it's profitable

Artur Pilipenko via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 24 12:43:46 PST 2023


apilipenko added a comment.

It occurred to me that this is an optimization only if the injected condition is likely. Then we would likely take the version with the loop with the removed loop variant condition. Otherwise, we spend code size and add an extra check before executing the loop with both loop variant conditions. I suggest using the profiling info on the branch to be eliminated to decide whether this is profitable.



================
Comment at: llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp:2880-2915
+/// Tries to canonicalize condition described by:
+///
+///   br (LHS pred RHS), label IfTrue, label IfFalse
+///
+/// into its equivalent where `Pred` is something that we support for injected
+/// invariants (so far it is limited to ult), LHS in canonicalized form is
+/// non-invariant and RHS is an invariant.
----------------
Can be separated to a follow up patch.


================
Comment at: llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp:3036
+  ICmpInst::Predicate NonStrictPred = ICmpInst::getNonStrictPredicate(Pred);
+  for (auto Prev = Compares.begin(), Next = Compares.begin() + 1;
+       Next != Compares.end(); ++Prev, ++Next) {
----------------



================
Comment at: llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp:3100
+      continue;
+    if (!matchPredicate(Pred, LHS, RHS, IfTrue, IfFalse, L))
+      continue;
----------------
canonicalizePredicate is probably a better name, as you match the predicate just below.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D136233/new/

https://reviews.llvm.org/D136233



More information about the llvm-commits mailing list