[llvm] ValueTracking: simplify udiv/urem recurrences (PR #108973)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 22 07:07:16 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:
Oh I see, I got myself a bit confused. This makes sense. Sorry for the confusion.
https://github.com/llvm/llvm-project/pull/108973
More information about the llvm-commits
mailing list