[PATCH] D154953: [InstSimplify] Remove the remainder loop if we know the mask is always true

Allen zhong via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 18 00:59:22 PDT 2023


Allen marked an inline comment as done.
Allen added inline comments.


================
Comment at: llvm/lib/Analysis/InstructionSimplify.cpp:1283
+    const APInt *RemC;
+    if (match(Op0, m_Power2(RemC))) {
+      KnownBits Known = computeKnownBits(Op1, Q.DL, 0, Q.AC, Q.CxtI, Q.DT);
----------------
goldstein.w.n wrote:
> move the match of Op0 against a constant to before the far more expensive `isKnownToBeAPowerOfTwo` check on Op1.
Done, thanks


================
Comment at: llvm/lib/Analysis/InstructionSimplify.cpp:1286
+      unsigned MaxActiveBits = Known.countMaxActiveBits();
+      if (MaxActiveBits <= RemC->logBase2())
+        return ConstantInt::getNullValue(Op0->getType());
----------------
nikic wrote:
> This check looks a bit roundabout. I think what you actually want to check is that `Known.getMaxValue().ule(*RemC)`?
I still use the **getActiveBits**  because the value of **Known.getMaxValue()** is not a power-of-two value. 
For example, we can easily get the the ConstantRange(8, 16) from the **vscale_range(1,16)**, but then the 
**Known = ConstantRange(8, 16)->toKnownBits()** will get the value of **Known.getMaxValue()** is 31 instead of 16,
so I can't compare them with its value directly.

I also change the boundary test for test case **urem_vscale_range **and **urem_shl_vscale_out_of_range**


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

https://reviews.llvm.org/D154953



More information about the llvm-commits mailing list