From: Sanjay Patel Date: Thu, 18 Jun 2020 19:44:02 +0000 (-0400) Subject: [IRBuilder] add/use wrapper to create a generic compare based on predicate type; NFC X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=46a285ad9e34dc6ccfd2530835687cac4cd67e3e;p=platform%2Fupstream%2Fllvm.git [IRBuilder] add/use wrapper to create a generic compare based on predicate type; NFC The predicate can always be used to distinguish between icmp and fcmp, so we don't need to keep repeating this check in the callers. --- diff --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h index d6bb479..ec042f0 100644 --- a/llvm/include/llvm/IR/IRBuilder.h +++ b/llvm/include/llvm/IR/IRBuilder.h @@ -2281,6 +2281,13 @@ public: return CreateFCmpHelper(P, LHS, RHS, Name, FPMathTag, false); } + Value *CreateCmp(CmpInst::Predicate Pred, Value *LHS, Value *RHS, + const Twine &Name = "", MDNode *FPMathTag = nullptr) { + return CmpInst::isFPPredicate(Pred) + ? CreateFCmp(Pred, LHS, RHS, Name, FPMathTag) + : CreateICmp(Pred, LHS, RHS, Name); + } + // Create a signaling floating-point comparison (i.e. one that raises an FP // exception whenever an input is any NaN, signaling or quiet). // Note that this differs from CreateFCmp only if IsFPConstrained is true. diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index a7b9ecb..53a3af0 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -5410,8 +5410,6 @@ static Instruction *foldVectorCmp(CmpInst &Cmp, InstCombiner::BuilderTy &Builder) { const CmpInst::Predicate Pred = Cmp.getPredicate(); Value *LHS = Cmp.getOperand(0), *RHS = Cmp.getOperand(1); - bool IsFP = isa(Cmp); - Value *V1, *V2; ArrayRef M; if (!match(LHS, m_Shuffle(m_Value(V1), m_Undef(), m_Mask(M)))) @@ -5423,8 +5421,7 @@ static Instruction *foldVectorCmp(CmpInst &Cmp, Type *V1Ty = V1->getType(); if (match(RHS, m_Shuffle(m_Value(V2), m_Undef(), m_SpecificMask(M))) && V1Ty == V2->getType() && (LHS->hasOneUse() || RHS->hasOneUse())) { - Value *NewCmp = IsFP ? Builder.CreateFCmp(Pred, V1, V2) - : Builder.CreateICmp(Pred, V1, V2); + Value *NewCmp = Builder.CreateCmp(Pred, V1, V2); return new ShuffleVectorInst(NewCmp, UndefValue::get(NewCmp->getType()), M); } @@ -5445,8 +5442,7 @@ static Instruction *foldVectorCmp(CmpInst &Cmp, C = ConstantVector::getSplat(cast(V1Ty)->getElementCount(), ScalarC); SmallVector NewM(M.size(), MaskSplatIndex); - Value *NewCmp = IsFP ? Builder.CreateFCmp(Pred, V1, C) - : Builder.CreateICmp(Pred, V1, C); + Value *NewCmp = Builder.CreateCmp(Pred, V1, C); return new ShuffleVectorInst(NewCmp, UndefValue::get(NewCmp->getType()), NewM); } diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp index 442efdb..1f97f0c 100644 --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -1084,14 +1084,11 @@ Instruction *InstCombiner::foldOpIntoPhi(Instruction &I, PHINode *PN) { Constant *C = cast(I.getOperand(1)); for (unsigned i = 0; i != NumPHIValues; ++i) { Value *InV = nullptr; - if (Constant *InC = dyn_cast(PN->getIncomingValue(i))) + if (auto *InC = dyn_cast(PN->getIncomingValue(i))) InV = ConstantExpr::getCompare(CI->getPredicate(), InC, C); - else if (isa(CI)) - InV = Builder.CreateICmp(CI->getPredicate(), PN->getIncomingValue(i), - C, "phitmp"); else - InV = Builder.CreateFCmp(CI->getPredicate(), PN->getIncomingValue(i), - C, "phitmp"); + InV = Builder.CreateCmp(CI->getPredicate(), PN->getIncomingValue(i), + C, "phitmp"); NewPN->addIncoming(InV, PN->getIncomingBlock(i)); } } else if (auto *BO = dyn_cast(&I)) { diff --git a/llvm/lib/Transforms/Utils/LoopUtils.cpp b/llvm/lib/Transforms/Utils/LoopUtils.cpp index 16603bf..2c66441 100644 --- a/llvm/lib/Transforms/Utils/LoopUtils.cpp +++ b/llvm/lib/Transforms/Utils/LoopUtils.cpp @@ -870,14 +870,7 @@ Value *llvm::createMinMaxOp(IRBuilderBase &Builder, FastMathFlags FMF; FMF.setFast(); Builder.setFastMathFlags(FMF); - - Value *Cmp; - if (RK == RecurrenceDescriptor::MRK_FloatMin || - RK == RecurrenceDescriptor::MRK_FloatMax) - Cmp = Builder.CreateFCmp(P, Left, Right, "rdx.minmax.cmp"); - else - Cmp = Builder.CreateICmp(P, Left, Right, "rdx.minmax.cmp"); - + Value *Cmp = Builder.CreateCmp(P, Left, Right, "rdx.minmax.cmp"); Value *Select = Builder.CreateSelect(Cmp, Left, Right, "rdx.minmax.select"); return Select; } diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index a6183b1..1afd120 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -4280,12 +4280,7 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E) { } CmpInst::Predicate P0 = cast(VL0)->getPredicate(); - Value *V; - if (E->getOpcode() == Instruction::FCmp) - V = Builder.CreateFCmp(P0, L, R); - else - V = Builder.CreateICmp(P0, L, R); - + Value *V = Builder.CreateCmp(P0, L, R); propagateIRFlags(V, E->Scalars, VL0); if (NeedToShuffleReuses) { V = Builder.CreateShuffleVector(V, UndefValue::get(VecTy), diff --git a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp index 05f9c6f..5cbe3d8 100644 --- a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp +++ b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp @@ -169,9 +169,7 @@ static void foldExtExtCmp(Instruction *Ext0, Instruction *Ext1, IRBuilder<> Builder(&I); CmpInst::Predicate Pred = cast(&I)->getPredicate(); Value *V0 = Ext0->getOperand(0), *V1 = Ext1->getOperand(0); - Value *VecCmp = - Ext0->getType()->isFloatingPointTy() ? Builder.CreateFCmp(Pred, V0, V1) - : Builder.CreateICmp(Pred, V0, V1); + Value *VecCmp = Builder.CreateCmp(Pred, V0, V1); Value *Extract = Builder.CreateExtractElement(VecCmp, Ext0->getOperand(1)); I.replaceAllUsesWith(Extract); } @@ -413,8 +411,7 @@ static bool scalarizeBinopOrCmp(Instruction &I, V1 = ConstantExpr::getExtractElement(VecC1, Builder.getInt64(Index)); Value *Scalar = - IsCmp ? Opcode == Instruction::FCmp ? Builder.CreateFCmp(Pred, V0, V1) - : Builder.CreateICmp(Pred, V0, V1) + IsCmp ? Builder.CreateCmp(Pred, V0, V1) : Builder.CreateBinOp((Instruction::BinaryOps)Opcode, V0, V1); Scalar->setName(I.getName() + ".scalar");