[llvm] 0daa114 - [CVP] Avoid duplicate range fetch (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 13 05:57:14 PST 2023
Author: Nikita Popov
Date: 2023-01-13T14:56:07+01:00
New Revision: 0daa1142ea52b80b2fb38cc88da425189c801bf8
URL: https://github.com/llvm/llvm-project/commit/0daa1142ea52b80b2fb38cc88da425189c801bf8
DIFF: https://github.com/llvm/llvm-project/commit/0daa1142ea52b80b2fb38cc88da425189c801bf8.diff
LOG: [CVP] Avoid duplicate range fetch (NFC)
In preparation for switching this to use getConstantRangeAtUse().
Added:
Modified:
llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
index 258db6224d157..77570221ddd36 100644
--- a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
+++ b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
@@ -769,7 +769,7 @@ static bool narrowSDivOrSRem(BinaryOperator *Instr, LazyValueInfo *LVI) {
return true;
}
-static bool expandURem(BinaryOperator *Instr, LazyValueInfo *LVI) {
+static bool processURem(BinaryOperator *Instr, LazyValueInfo *LVI) {
assert(Instr->getOpcode() == Instruction::URem);
assert(!Instr->getType()->isVectorTy());
@@ -779,6 +779,14 @@ static bool expandURem(BinaryOperator *Instr, LazyValueInfo *LVI) {
ConstantRange XCR = LVI->getConstantRange(X, Instr);
ConstantRange YCR = LVI->getConstantRange(Y, Instr);
+ // X u% Y -> X iff X u< Y
+ if (XCR.icmp(ICmpInst::ICMP_ULT, YCR)) {
+ Instr->replaceAllUsesWith(X);
+ Instr->eraseFromParent();
+ ++NumURemExpanded;
+ return true;
+ }
+
// Given
// R = X u% Y
// We can represent the modulo operation as a loop/self-recursion:
@@ -807,7 +815,8 @@ static bool expandURem(BinaryOperator *Instr, LazyValueInfo *LVI) {
YCR.umul_sat(APInt(YCR.getBitWidth(), 2))) &&
!YCR.isAllNegative())
return false;
- IRBuilder<> B{Instr};
+
+ IRBuilder<> B(Instr);
// NOTE: this transformation introduces two uses of X,
// but it may be undef so we must freeze it first.
X = B.CreateFreeze(X, X->getName() + ".frozen");
@@ -821,30 +830,6 @@ static bool expandURem(BinaryOperator *Instr, LazyValueInfo *LVI) {
return true;
}
-static bool processURem(BinaryOperator *Instr, LazyValueInfo *LVI) {
- assert(Instr->getOpcode() == Instruction::URem);
- assert(!Instr->getType()->isVectorTy());
-
- Value *X = Instr->getOperand(0);
- Value *Y = Instr->getOperand(1);
-
- ConstantRange XCR = LVI->getConstantRange(X, Instr);
- ConstantRange YCR = LVI->getConstantRange(Y, Instr);
-
- // X u% Y -> X iff X u< Y
- if (XCR.icmp(ICmpInst::ICMP_ULT, YCR)) {
- Instr->replaceAllUsesWith(X);
- Instr->eraseFromParent();
- ++NumURemExpanded;
- return true;
- }
-
- if (expandURem(Instr, LVI))
- return true;
-
- return false;
-}
-
/// Try to shrink a udiv/urem's width down to the smallest power of two that's
/// sufficient to contain its operands.
static bool narrowUDivOrURem(BinaryOperator *Instr, LazyValueInfo *LVI) {
More information about the llvm-commits
mailing list