[PATCH] D126925: [ValueTracking] Relaxed requirement of UseInstrInfo in power of 2 recurrece check

William Junda Huang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 2 14:50:13 PDT 2022


huangjd created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
huangjd requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

add isExact check for recurrence using division operator


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126925

Files:
  llvm/lib/Analysis/ValueTracking.cpp


Index: llvm/lib/Analysis/ValueTracking.cpp
===================================================================
--- llvm/lib/Analysis/ValueTracking.cpp
+++ llvm/lib/Analysis/ValueTracking.cpp
@@ -2066,7 +2066,8 @@
   switch (BO->getOpcode()) {
   case Instruction::Mul:
     // Power of two is closed under multiplication.
-    return (OrZero || BO->hasNoUnsignedWrap() || BO->hasNoSignedWrap()) &&
+    return (OrZero || Q.IIQ.hasNoUnsignedWrap(BO) ||
+            Q.IIQ.hasNoSignedWrap(BO)) &&
            isKnownToBeAPowerOfTwo(Step, OrZero, Depth, Q);
   case Instruction::SDiv:
     // Start value must not be signmask for signed division, so simply being a
@@ -2077,16 +2078,17 @@
   case Instruction::UDiv:
     // Divisor must be a power of two.
     // If OrZero is false, cannot guarantee induction variable is non-zero after
-    // division, same for Shr.
-    return OrZero && isKnownToBeAPowerOfTwo(Step, false, Depth, Q);
+    // division, same for Shr, unless it is exact division.
+    return (OrZero || Q.IIQ.isExact(BO)) &&
+           isKnownToBeAPowerOfTwo(Step, false, Depth, Q);
   case Instruction::Shl:
-    return OrZero || BO->hasNoUnsignedWrap() || BO->hasNoSignedWrap();
+    return OrZero || Q.IIQ.hasNoUnsignedWrap(BO) || Q.IIQ.hasNoSignedWrap(BO);
   case Instruction::AShr:
     if (!match(Start, m_Power2()) || match(Start, m_SignMask()))
       return false;
     LLVM_FALLTHROUGH;
   case Instruction::LShr:
-    return OrZero;
+    return OrZero || Q.IIQ.isExact(BO);
   default:
     return false;
   }
@@ -2189,7 +2191,7 @@
     Query RecQ = Q;
 
     // Check if it is an induction variable and always power of two.
-    if (Q.IIQ.UseInstrInfo && isPowerOfTwoRecurrence(PN, OrZero, Depth, RecQ))
+    if (isPowerOfTwoRecurrence(PN, OrZero, Depth, RecQ))
       return true;
 
     // Recursively check all incoming values. Limit recursion to 2 levels, so


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126925.433895.patch
Type: text/x-patch
Size: 1894 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220602/50e68293/attachment.bin>


More information about the llvm-commits mailing list