[llvm] 46a285a - [IRBuilder] add/use wrapper to create a generic compare based on predicate type; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 18 12:48:18 PDT 2020
Author: Sanjay Patel
Date: 2020-06-18T15:47:06-04:00
New Revision: 46a285ad9e34dc6ccfd2530835687cac4cd67e3e
URL: https://github.com/llvm/llvm-project/commit/46a285ad9e34dc6ccfd2530835687cac4cd67e3e
DIFF: https://github.com/llvm/llvm-project/commit/46a285ad9e34dc6ccfd2530835687cac4cd67e3e.diff
LOG: [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.
Added:
Modified:
llvm/include/llvm/IR/IRBuilder.h
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
llvm/lib/Transforms/Utils/LoopUtils.cpp
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
llvm/lib/Transforms/Vectorize/VectorCombine.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h
index d6bb479fdf2d..ec042f0740fc 100644
--- a/llvm/include/llvm/IR/IRBuilder.h
+++ b/llvm/include/llvm/IR/IRBuilder.h
@@ -2281,6 +2281,13 @@ class IRBuilderBase {
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
diff ers from CreateFCmp only if IsFPConstrained is true.
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index a7b9ecb9bf3b..53a3af03e46f 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<FCmpInst>(Cmp);
-
Value *V1, *V2;
ArrayRef<int> 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<VectorType>(V1Ty)->getElementCount(),
ScalarC);
SmallVector<int, 8> 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 442efdbcaf71..1f97f0c1ac99 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<Constant>(I.getOperand(1));
for (unsigned i = 0; i != NumPHIValues; ++i) {
Value *InV = nullptr;
- if (Constant *InC = dyn_cast<Constant>(PN->getIncomingValue(i)))
+ if (auto *InC = dyn_cast<Constant>(PN->getIncomingValue(i)))
InV = ConstantExpr::getCompare(CI->getPredicate(), InC, C);
- else if (isa<ICmpInst>(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<BinaryOperator>(&I)) {
diff --git a/llvm/lib/Transforms/Utils/LoopUtils.cpp b/llvm/lib/Transforms/Utils/LoopUtils.cpp
index 16603bfd0eb1..2c664412192b 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 a6183b11536f..1afd120e1e7e 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<CmpInst>(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 05f9c6f7daff..5cbe3d85fb7a 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<CmpInst>(&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");
More information about the llvm-commits
mailing list