[llvm] [SLP]Add better minbitwidth analysis for udiv/urem instructions. (PR #85928)

Alexey Bataev via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 20 10:41:05 PDT 2024


================
@@ -14165,6 +14165,28 @@ bool BoUpSLP::collectValuesToDemote(
       return false;
     break;
   }
+  case Instruction::UDiv:
+  case Instruction::URem: {
+    if (ITE->UserTreeIndices.size() > 1 && !IsPotentiallyTruncated(I, BitWidth))
+      return false;
+    // UDiv and URem can be truncated if all the truncated bits are zero.
+    if (!AttemptCheckBitwidth(
+            [&](unsigned BitWidth, unsigned OrigBitWidth) {
+              assert(BitWidth <= OrigBitWidth && "Unexpected bitwidths!");
+              APInt Mask = APInt::getBitsSetFrom(OrigBitWidth, BitWidth);
+              return MaskedValueIsZero(I->getOperand(0), Mask,
+                                       SimplifyQuery(*DL)) &&
+                     MaskedValueIsZero(I->getOperand(1), Mask,
+                                       SimplifyQuery(*DL));
+            },
+            NeedToExit))
----------------
alexey-bataev wrote:

Yeah, I thought about this. Actually, only the code for shifts/div/rem is duplicated, all other code is unique and/or requires some extra processing, which canEvaluateTruncated does not have. We can think about it later.

https://github.com/llvm/llvm-project/pull/85928


More information about the llvm-commits mailing list