[llvm] [InstCombine] Infer exact division from a known-zero remainder (PR #221509)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 5 21:02:45 PDT 2026
================
@@ -1318,6 +1318,39 @@ static Value *foldIDivShl(BinaryOperator &I, InstCombiner::BuilderTy &Builder) {
return nullptr;
}
+/// Return true if a matching remainder is known to be zero at the division.
+static bool isKnownExactFromRem(const BinaryOperator &Div,
+ const SimplifyQuery &Q) {
+ assert((Div.getOpcode() == Instruction::SDiv ||
+ Div.getOpcode() == Instruction::UDiv) &&
+ "Expected integer divide");
+
+ unsigned RemOpcode = Div.getOpcode() == Instruction::SDiv ? Instruction::SRem
+ : Instruction::URem;
+
+ Value *Op0 = Div.getOperand(0);
+ Value *Op1 = Div.getOperand(1);
+
+ // A matching remainder uses both operands. Avoid scanning constants, whose
+ // users may be shared across functions or whose use-lists may be unavailable.
+ Value *V = isa<Constant>(Op0) ? Op1 : Op0;
+ if (isa<Constant>(V))
+ return false;
+
+ for (User *U : V->users()) {
----------------
ZERICO2005 wrote:
I would appreciate some guidance on how to bound this search here.
https://github.com/llvm/llvm-project/pull/221509
More information about the llvm-commits
mailing list