From: Sanjay Patel Date: Fri, 3 Sep 2021 18:04:32 +0000 (-0400) Subject: [InstCombine] reduce code duplication; NFC X-Git-Tag: upstream/15.0.7~32274 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d1458903eb5a215aa7eb29229fddb429c7d23ffa;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 0ff23b4..79b4943 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -3175,25 +3175,26 @@ Instruction *InstCombinerImpl::foldICmpEqIntrinsicWithConstant( ICmpInst &Cmp, IntrinsicInst *II, const APInt &C) { Type *Ty = II->getType(); unsigned BitWidth = C.getBitWidth(); + const ICmpInst::Predicate Pred = Cmp.getPredicate(); + switch (II->getIntrinsicID()) { case Intrinsic::abs: // abs(A) == 0 -> A == 0 // abs(A) == INT_MIN -> A == INT_MIN if (C.isNullValue() || C.isMinSignedValue()) - return new ICmpInst(Cmp.getPredicate(), II->getArgOperand(0), - ConstantInt::get(Ty, C)); + return new ICmpInst(Pred, II->getArgOperand(0), ConstantInt::get(Ty, C)); break; case Intrinsic::bswap: // bswap(A) == C -> A == bswap(C) - return new ICmpInst(Cmp.getPredicate(), II->getArgOperand(0), + return new ICmpInst(Pred, II->getArgOperand(0), ConstantInt::get(Ty, C.byteSwap())); case Intrinsic::ctlz: case Intrinsic::cttz: { // ctz(A) == bitwidth(A) -> A == 0 and likewise for != if (C == BitWidth) - return new ICmpInst(Cmp.getPredicate(), II->getArgOperand(0), + return new ICmpInst(Pred, II->getArgOperand(0), ConstantInt::getNullValue(Ty)); // ctz(A) == C -> A & Mask1 == Mask2, where Mask2 only has bit C set @@ -3207,9 +3208,8 @@ Instruction *InstCombinerImpl::foldICmpEqIntrinsicWithConstant( APInt Mask2 = IsTrailing ? APInt::getOneBitSet(BitWidth, Num) : APInt::getOneBitSet(BitWidth, BitWidth - Num - 1); - return new ICmpInst(Cmp.getPredicate(), - Builder.CreateAnd(II->getArgOperand(0), Mask1), - ConstantInt::get(Ty, Mask2)); + return new ICmpInst(Pred, Builder.CreateAnd(II->getArgOperand(0), Mask1), + ConstantInt::get(Ty, Mask2)); } break; } @@ -3219,8 +3219,9 @@ Instruction *InstCombinerImpl::foldICmpEqIntrinsicWithConstant( // popcount(A) == bitwidth(A) -> A == -1 and likewise for != bool IsZero = C.isNullValue(); if (IsZero || C == BitWidth) - return new ICmpInst(Cmp.getPredicate(), II->getArgOperand(0), - IsZero ? Constant::getNullValue(Ty) : Constant::getAllOnesValue(Ty)); + return new ICmpInst(Pred, II->getArgOperand(0), + IsZero ? Constant::getNullValue(Ty) + : Constant::getAllOnesValue(Ty)); break; } @@ -3229,7 +3230,7 @@ Instruction *InstCombinerImpl::foldICmpEqIntrinsicWithConstant( // uadd.sat(a, b) == 0 -> (a | b) == 0 if (C.isNullValue()) { Value *Or = Builder.CreateOr(II->getArgOperand(0), II->getArgOperand(1)); - return new ICmpInst(Cmp.getPredicate(), Or, Constant::getNullValue(Ty)); + return new ICmpInst(Pred, Or, Constant::getNullValue(Ty)); } break; } @@ -3237,8 +3238,8 @@ Instruction *InstCombinerImpl::foldICmpEqIntrinsicWithConstant( case Intrinsic::usub_sat: { // usub.sat(a, b) == 0 -> a <= b if (C.isNullValue()) { - ICmpInst::Predicate NewPred = Cmp.getPredicate() == ICmpInst::ICMP_EQ - ? ICmpInst::ICMP_ULE : ICmpInst::ICMP_UGT; + ICmpInst::Predicate NewPred = + Pred == ICmpInst::ICMP_EQ ? ICmpInst::ICMP_ULE : ICmpInst::ICMP_UGT; return new ICmpInst(NewPred, II->getArgOperand(0), II->getArgOperand(1)); } break;