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

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 30 02:05:35 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:

It would be safer to use a worklist instead of recursion here.

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


More information about the llvm-commits mailing list