[PATCH] D157292: Reland [ValueTracking] Improve the coverage of isKnownToBeAPowerOfTwo for vscale

Allen zhong via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 7 08:59:11 PDT 2023


Allen updated this revision to Diff 547811.
Allen retitled this revision from "[ValueTracking] Fix the correct of isKnownToBeAPowerOfTwo" to "Reland [ValueTracking] Improve the coverage of isKnownToBeAPowerOfTwo for vscale".
Allen edited the summary of this revision.
Allen added a comment.

rebase after revert of  f6c726472df1 <https://reviews.llvm.org/rGf6c726472df1ebc8489e178a2d299cb3950efbfe>


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

https://reviews.llvm.org/D157292

Files:
  llvm/lib/Analysis/ValueTracking.cpp


Index: llvm/lib/Analysis/ValueTracking.cpp
===================================================================
--- llvm/lib/Analysis/ValueTracking.cpp
+++ llvm/lib/Analysis/ValueTracking.cpp
@@ -2024,6 +2024,20 @@
     return F->hasFnAttribute(Attribute::VScaleRange);
   }
 
+  const APInt *Shift;
+  if (Q.CxtI && match(V, m_Shl(m_VScale(), m_APInt(Shift)))) {
+    const Function *F = Q.CxtI->getFunction();
+    // The vscale_range indicates vscale is a power-of-two.
+    if (F->hasFnAttribute(Attribute::VScaleRange)) {
+      Attribute Attr = F->getFnAttribute(Attribute::VScaleRange);
+      if (std::optional<unsigned> MaxVScale = Attr.getVScaleRangeMax()) {
+        unsigned Bitwidth = V->getType()->getScalarSizeInBits();
+        if (Log2_32(*MaxVScale) + Shift->getZExtValue() < Bitwidth)
+          return true;
+      }
+    }
+  }
+
   // 1 << X is clearly a power of two if the one is not shifted off the end.  If
   // it is shifted off the end then the result is undefined.
   if (match(V, m_Shl(m_One(), m_Value())))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157292.547811.patch
Type: text/x-patch
Size: 1038 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230807/ad48592f/attachment.bin>


More information about the llvm-commits mailing list