[llvm] [LoopPeel] Peel iterations based on and, or conditions (PR #73413)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 1 00:29:28 PST 2023


================
@@ -351,11 +351,19 @@ static unsigned countToEliminateCompares(Loop &L, unsigned MaxPeelCount,
     MaxPeelCount =
         std::min((unsigned)SC->getAPInt().getLimitedValue() - 1, MaxPeelCount);
 
-  auto ComputePeelCount = [&](Value *Condition) -> void {
+  std::function<void(Value *)> ComputePeelCount =
+      [&](Value *Condition) -> void {
     if (!Condition->getType()->isIntegerTy())
       return;
 
     Value *LeftVal, *RightVal;
+    if (match(Condition, m_And(m_Value(LeftVal), m_Value(RightVal))) ||
+        match(Condition, m_Or(m_Value(LeftVal), m_Value(RightVal)))) {
+      ComputePeelCount(LeftVal);
+      ComputePeelCount(RightVal);
----------------
nikic wrote:

Generally, if we do recursion we should either use a worklist instead or have a depth limit. In this case either is fine really, as it's unlikely we'll recurse deeply enough to reach a cutoff for any practically relevant code.

https://github.com/llvm/llvm-project/pull/73413


More information about the llvm-commits mailing list