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

Noah Goldstein via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 7 09:45:18 PDT 2023


goldstein.w.n added inline comments.


================
Comment at: llvm/lib/Analysis/ValueTracking.cpp:2028
+  const APInt *Shift;
+  if (Q.CxtI && match(V, m_Shl(m_VScale(), m_APInt(Shift)))) {
+    const Function *F = Q.CxtI->getFunction();
----------------
More robust would be to match shift as a value and use `ComputeKnownBits` to get max shift cnt.


================
Comment at: llvm/lib/Analysis/ValueTracking.cpp:2031
+    // The vscale_range indicates vscale is a power-of-two.
+    if (F->hasFnAttribute(Attribute::VScaleRange)) {
+      Attribute Attr = F->getFnAttribute(Attribute::VScaleRange);
----------------
If we have `OrZero` don't need the extra logic.


================
Comment at: llvm/lib/Analysis/ValueTracking.cpp:2035
+        unsigned Bitwidth = V->getType()->getScalarSizeInBits();
+        if (Log2_32(*MaxVScale) + Shift->getZExtValue() < Bitwidth)
+          return true;
----------------
Keep these as APInt to avoid overflow / handle abnormal types like i128


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

https://reviews.llvm.org/D157292



More information about the llvm-commits mailing list