From: Roman Lebedev Date: Fri, 30 Dec 2022 16:15:43 +0000 (+0300) Subject: [NFC][CVP] `processURem()`: add statistic and increase readability X-Git-Tag: upstream/17.0.6~22436 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3cb827f9d3e9c502a1a08f1de1980e906aa30c3d;p=platform%2Fupstream%2Fllvm.git [NFC][CVP] `processURem()`: add statistic and increase readability --- 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; }