From 3cb827f9d3e9c502a1a08f1de1980e906aa30c3d Mon Sep 17 00:00:00 2001 From: Roman Lebedev Date: Fri, 30 Dec 2022 19:15:43 +0300 Subject: [PATCH] [NFC][CVP] `processURem()`: add statistic and increase readability --- .../Transforms/Scalar/CorrelatedValuePropagation.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp index 0fca452..5c3fdc1 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; } -- 2.7.4