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

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 20 10:38:35 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))
----------------
RKSimon wrote:

This is starting to have a lot of code similar to canEvaluateTruncated in InstCombineCasts.cpp - can we reuse that code somehow - move it to ValueTracking.h or something?

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


More information about the llvm-commits mailing list