From: Sanjay Patel Date: Mon, 5 Sep 2022 14:47:38 +0000 (-0400) Subject: [InstCombine] reduce code duplication; NFC X-Git-Tag: upstream/17.0.6~34324 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=dd6eb4d67f234afe115981957f91f5d81eba9db6;p=platform%2Fupstream%2Fllvm.git [InstCombine] reduce code duplication; NFC --- diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index 0173f9e3..febfc13 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -1548,16 +1548,17 @@ Instruction *InstCombinerImpl::foldICmpTruncConstant(ICmpInst &Cmp, ConstantInt::get(V->getType(), 1)); } + Type *SrcTy = X->getType(); unsigned DstBits = Trunc->getType()->getScalarSizeInBits(), - SrcBits = X->getType()->getScalarSizeInBits(); + SrcBits = SrcTy->getScalarSizeInBits(); if (Cmp.isEquality() && Trunc->hasOneUse()) { // Canonicalize to a mask and wider compare if the wide type is suitable: // (trunc X to i8) == C --> (X & 0xff) == (zext C) - if (!X->getType()->isVectorTy() && shouldChangeType(DstBits, SrcBits)) { - Constant *Mask = ConstantInt::get(X->getType(), - APInt::getLowBitsSet(SrcBits, DstBits)); + if (!SrcTy->isVectorTy() && shouldChangeType(DstBits, SrcBits)) { + Constant *Mask = + ConstantInt::get(SrcTy, APInt::getLowBitsSet(SrcBits, DstBits)); Value *And = Builder.CreateAnd(X, Mask); - Constant *WideC = ConstantInt::get(X->getType(), C.zext(SrcBits)); + Constant *WideC = ConstantInt::get(SrcTy, C.zext(SrcBits)); return new ICmpInst(Pred, And, WideC); } @@ -1570,7 +1571,7 @@ Instruction *InstCombinerImpl::foldICmpTruncConstant(ICmpInst &Cmp, // Pull in the high bits from known-ones set. APInt NewRHS = C.zext(SrcBits); NewRHS |= Known.One & APInt::getHighBitsSet(SrcBits, SrcBits - DstBits); - return new ICmpInst(Pred, X, ConstantInt::get(X->getType(), NewRHS)); + return new ICmpInst(Pred, X, ConstantInt::get(SrcTy, NewRHS)); } } @@ -1583,11 +1584,10 @@ Instruction *InstCombinerImpl::foldICmpTruncConstant(ICmpInst &Cmp, if (isSignBitCheck(Pred, C, TrueIfSigned) && match(X, m_Shr(m_Value(ShOp), m_APInt(ShAmtC))) && DstBits == SrcBits - ShAmtC->getZExtValue()) { - return TrueIfSigned - ? new ICmpInst(ICmpInst::ICMP_SLT, ShOp, - ConstantInt::getNullValue(X->getType())) - : new ICmpInst(ICmpInst::ICMP_SGT, ShOp, - ConstantInt::getAllOnesValue(X->getType())); + return TrueIfSigned ? new ICmpInst(ICmpInst::ICMP_SLT, ShOp, + ConstantInt::getNullValue(SrcTy)) + : new ICmpInst(ICmpInst::ICMP_SGT, ShOp, + ConstantInt::getAllOnesValue(SrcTy)); } return nullptr;