[llvm] 6cd4a6f - [InstCombine] reduce code duplication; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 17 05:01:37 PDT 2020
Author: Sanjay Patel
Date: 2020-08-17T08:01:27-04:00
New Revision: 6cd4a6f6b27eea40dbddccb21c206fb4d4354c53
URL: https://github.com/llvm/llvm-project/commit/6cd4a6f6b27eea40dbddccb21c206fb4d4354c53
DIFF: https://github.com/llvm/llvm-project/commit/6cd4a6f6b27eea40dbddccb21c206fb4d4354c53.diff
LOG: [InstCombine] reduce code duplication; NFC
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 203c8c7f1c1b..fb8b640c7c93 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
@@ -1114,6 +1114,7 @@ Instruction *InstCombinerImpl::visitSDiv(BinaryOperator &I) {
return Common;
Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);
+ Type *Ty = I.getType();
Value *X;
// sdiv Op0, -1 --> -Op0
// sdiv Op0, (sext i1 X) --> -Op0 (because if X is 0, the op is undefined)
@@ -1123,7 +1124,7 @@ Instruction *InstCombinerImpl::visitSDiv(BinaryOperator &I) {
// X / INT_MIN --> X == INT_MIN
if (match(Op1, m_SignMask()))
- return new ZExtInst(Builder.CreateICmpEQ(Op0, Op1), I.getType());
+ return new ZExtInst(Builder.CreateICmpEQ(Op0, Op1), Ty);
// sdiv exact X, 1<<C --> ashr exact X, C iff 1<<C is non-negative
// sdiv exact X, -1<<C --> -(ashr exact X, C)
@@ -1133,7 +1134,7 @@ Instruction *InstCombinerImpl::visitSDiv(BinaryOperator &I) {
if (DivisorWasNegative)
Op1 = ConstantExpr::getNeg(cast<Constant>(Op1));
auto *AShr = BinaryOperator::CreateExactAShr(
- Op0, getLogBase2(I.getType(), cast<Constant>(Op1)), I.getName());
+ Op0, getLogBase2(Ty, cast<Constant>(Op1)), I.getName());
if (!DivisorWasNegative)
return AShr;
Builder.Insert(AShr);
@@ -1157,7 +1158,7 @@ Instruction *InstCombinerImpl::visitSDiv(BinaryOperator &I) {
Constant *NarrowDivisor =
ConstantExpr::getTrunc(cast<Constant>(Op1), Op0Src->getType());
Value *NarrowOp = Builder.CreateSDiv(Op0Src, NarrowDivisor);
- return new SExtInst(NarrowOp, Op0->getType());
+ return new SExtInst(NarrowOp, Ty);
}
// -X / C --> X / -C (if the negation doesn't overflow).
@@ -1165,7 +1166,7 @@ Instruction *InstCombinerImpl::visitSDiv(BinaryOperator &I) {
// checking if all elements are not the min-signed-val.
if (!Op1C->isMinSignedValue() &&
match(Op0, m_NSWSub(m_Zero(), m_Value(X)))) {
- Constant *NegC = ConstantInt::get(I.getType(), -(*Op1C));
+ Constant *NegC = ConstantInt::get(Ty, -(*Op1C));
Instruction *BO = BinaryOperator::CreateSDiv(X, NegC);
BO->setIsExact(I.isExact());
return BO;
@@ -1180,7 +1181,7 @@ Instruction *InstCombinerImpl::visitSDiv(BinaryOperator &I) {
// 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(I.getType()->getScalarSizeInBits()));
+ 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
More information about the llvm-commits
mailing list