[llvm] 3cb827f - [NFC][CVP] `processURem()`: add statistic and increase readability
Roman Lebedev via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 30 08:41:17 PST 2022
Author: Roman Lebedev
Date: 2022-12-30T19:40:46+03:00
New Revision: 3cb827f9d3e9c502a1a08f1de1980e906aa30c3d
URL: https://github.com/llvm/llvm-project/commit/3cb827f9d3e9c502a1a08f1de1980e906aa30c3d
DIFF: https://github.com/llvm/llvm-project/commit/3cb827f9d3e9c502a1a08f1de1980e906aa30c3d.diff
LOG: [NFC][CVP] `processURem()`: add statistic and increase readability
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 0fca45200be04..5c3fdc1451e93 100644
--- a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
+++ b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
@@ -94,6 +94,7 @@ STATISTIC(NumSaturating,
"Number of saturating arithmetics converted to normal arithmetics");
STATISTIC(NumNonNull, "Number of function pointer arguments marked non-null");
STATISTIC(NumMinMax, "Number of llvm.[us]{min,max} intrinsics removed");
+STATISTIC(NumURemExpanded, "Number of bound urem's expanded");
namespace {
@@ -772,14 +773,20 @@ static bool processURem(BinaryOperator *Instr, LazyValueInfo *LVI) {
assert(Instr->getOpcode() == Instruction::URem);
assert(!Instr->getType()->isVectorTy());
- // X % Y -> X for X < Y
- if (LVI->getConstantRange(Instr->getOperand(0), Instr)
- .icmp(ICmpInst::ICMP_ULT,
- LVI->getConstantRange(Instr->getOperand(1), Instr))) {
- Instr->replaceAllUsesWith(Instr->getOperand(0));
+ 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;
}
+
return false;
}
More information about the llvm-commits
mailing list