[llvm] ValueTracking: simplify udiv/urem recurrences (PR #108973)

via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 21 16:03:33 PDT 2024


================
@@ -1543,6 +1543,29 @@ static void computeKnownBitsFromOperator(const Operator *I,
         }
         break;
       }
+
+      case Instruction::UDiv: {
+        // For UDiv, the result can never exceed either the numerator, or the
+        // start value, whichever is greater. The case where the PHI is not
+        // the numerator of the UDiv is already handled by other code.
+        if (BO->getOperand(0) != P)
+          break;
+        [[fallthrough]];
+      }
+
+      case Instruction::URem: {
+        // For URem, the result can never exceed the start value.
+        SimplifyQuery RecQ = Q.getWithoutCondContext();
+
+        unsigned OpNum = P->getOperand(0) == R ? 0 : 1;
+        Instruction *RInst = P->getIncomingBlock(OpNum)->getTerminator();
+
+        RecQ.CxtI = RInst;
+        computeKnownBits(R, DemandedElts, Known2, Depth + 1, RecQ);
+        Known.Zero.setHighBits(Known2.countMinLeadingZeros());
----------------
goldsteinn wrote:

How does that differ from RHS vs LHS?

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


More information about the llvm-commits mailing list