[llvm] [InstCombine] Fold negation of unsigned div of non-negatives (PR #84951)
Antonio Frighetto via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 13 09:28:04 PDT 2024
================
@@ -2062,6 +2062,25 @@ static Instruction *foldSubOfMinMax(BinaryOperator &I,
return nullptr;
}
+/// Fold `sub 0, (udiv nneg X, nneg C)` into `sdiv nneg X, -C`
+static Instruction *foldNegationOfUDivOfNonNegatives(BinaryOperator &I,
+ InstCombinerImpl &IC) {
+ Value *RHS = I.getOperand(1);
+ Value *X;
+ Constant *C;
+
+ const auto &SQ = IC.getSimplifyQuery().getWithInstruction(&I);
+ if (match(RHS, m_OneUse(m_UDiv(m_Value(X), m_Constant(C)))) &&
+ isKnownNonNegative(X, SQ) && isKnownNonNegative(C, SQ)) {
----------------
antoniofrighetto wrote:
Looks like ValueTracking results are suboptimal for the splat one? (https://alive2.llvm.org/ce/z/ZzGqrF).
https://github.com/llvm/llvm-project/pull/84951
More information about the llvm-commits
mailing list