[PATCH] D68360: PR41162 Implement LKK remainder and divisibility algorithms [urem]

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 7 15:11:31 PDT 2019


lebedev.ri added a comment.

It looks that we now use hacker's deligth lowering for urem?
Where is that lowering being performed?



================
Comment at: llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp:4934
+    const APInt &D = DivisorConstant->getAPIntValue();
+    APInt C = APInt::getMaxValue(F).udiv(D.zext(F)).uadd_sat(APInt(F, 1));
+    SDValue AproximateReciprocal = DAG.getConstant(C, DL, FVT.getScalarType());
----------------
This should be a simple `add`.


================
Comment at: llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp:4941-4943
+    if (!D.isStrictlyPositive() || D.isMaxValue() || D.isOneValue() ||
+        D.isPowerOf2()) {
+      // Divisor must be in the range of (1,2^N)
----------------
There is no such restriction.


================
Comment at: llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp:4944-4945
+      // Divisor must be in the range of (1,2^N)
+      // We can lower remainder of division by powers of two much better
+      // elsewhere.
+      return false;
----------------
I believe what you want to do, is to check whether *all* divisors are powers of two, and avoid *this* fold then.
If at least one of them is not a power of two this should still be good.
That being said many of the test changes look like regressions.


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

https://reviews.llvm.org/D68360





More information about the llvm-commits mailing list