[llvm] 340ae45 - [InstCombine] use isKnownNonNegative() for readability; NFCI
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 16 08:14:02 PDT 2022
Author: Sanjay Patel
Date: 2022-10-16T10:59:56-04:00
New Revision: 340ae45be06ae663e73edbee3f942f5dcd13c58e
URL: https://github.com/llvm/llvm-project/commit/340ae45be06ae663e73edbee3f942f5dcd13c58e
DIFF: https://github.com/llvm/llvm-project/commit/340ae45be06ae663e73edbee3f942f5dcd13c58e.diff
LOG: [InstCombine] use isKnownNonNegative() for readability; NFCI
This should be functionally equivalent - both calls are thin
wrappers around computeKnownBits(). We'll probably want to use
known-bits directly in follow-up patches because that could
determine "exact" for example (see issue #58348).
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
index cc90ded72f585..b98e6736ccf94 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
@@ -1332,12 +1332,9 @@ Instruction *InstCombinerImpl::visitSDiv(BinaryOperator &I) {
ConstantInt::getAllOnesValue(Ty));
}
- // If the sign bits of both operands are zero (i.e. we can prove they are
- // unsigned inputs), turn this into a udiv.
- APInt Mask(APInt::getSignMask(Ty->getScalarSizeInBits()));
- if (MaskedValueIsZero(Op0, Mask, 0, &I)) {
- if (MaskedValueIsZero(Op1, Mask, 0, &I)) {
- // X sdiv Y -> X udiv Y, iff X and Y don't have sign bit set
+ if (isKnownNonNegative(Op0, DL, 0, &AC, &I, &DT)) {
+ // If both operands are unsigned, turn this into a udiv.
+ if (isKnownNonNegative(Op1, DL, 0, &AC, &I, &DT)) {
auto *BO = BinaryOperator::CreateUDiv(Op0, Op1, I.getName());
BO->setIsExact(I.isExact());
return BO;
More information about the llvm-commits
mailing list