[llvm] r346241 - [InstCombine] rearrange code for fcmp+fpext; NFCI
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 6 08:37:35 PST 2018
Author: spatel
Date: Tue Nov 6 08:37:35 2018
New Revision: 346241
URL: http://llvm.org/viewvc/llvm-project?rev=346241&view=rev
Log:
[InstCombine] rearrange code for fcmp+fpext; NFCI
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp?rev=346241&r1=346240&r2=346241&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp Tue Nov 6 08:37:35 2018
@@ -5409,29 +5409,6 @@ Instruction *InstCombiner::visitFCmpInst
Constant *RHSC;
if (match(Op0, m_Instruction(LHSI)) && match(Op1, m_Constant(RHSC))) {
switch (LHSI->getOpcode()) {
- case Instruction::FPExt: {
- // fcmp (fpext x), C -> fcmp x, (fptrunc C) if fptrunc is lossless
- FPExtInst *LHSExt = cast<FPExtInst>(LHSI);
- ConstantFP *RHSF = dyn_cast<ConstantFP>(RHSC);
- if (!RHSF)
- break;
-
- const fltSemantics &FPSem = LHSExt->getSrcTy()->getFltSemantics();
- bool Lossy;
- APFloat F = RHSF->getValueAPF();
- F.convert(FPSem, APFloat::rmNearestTiesToEven, &Lossy);
-
- // Avoid lossy conversions and denormals.
- // Zero is a special case that's OK to convert.
- APFloat Fabs = F;
- Fabs.clearSign();
- if (!Lossy &&
- ((Fabs.compare(APFloat::getSmallestNormalized(FPSem)) !=
- APFloat::cmpLessThan) || Fabs.isZero()))
- return new FCmpInst(Pred, LHSExt->getOperand(0),
- ConstantFP::get(RHSC->getContext(), F));
- break;
- }
case Instruction::PHI:
// Only fold fcmp into the PHI if the phi and fcmp are in the same
// block. If in the same block, we're encouraging jump threading. If
@@ -5483,12 +5460,33 @@ Instruction *InstCombiner::visitFCmpInst
}
}
- // fcmp (fpext X), (fpext Y) -> fcmp X, Y
- if (match(Op0, m_FPExt(m_Value(X))) && match(Op1, m_FPExt(m_Value(Y))) &&
- X->getType() == Y->getType()) {
- Instruction *NewFCmp = new FCmpInst(Pred, X, Y);
- NewFCmp->copyFastMathFlags(&I);
- return NewFCmp;
+ if (match(Op0, m_FPExt(m_Value(X)))) {
+ if (match(Op1, m_FPExt(m_Value(Y))) && X->getType() == Y->getType()) {
+ // fcmp (fpext X), (fpext Y) -> fcmp X, Y
+ Instruction *NewFCmp = new FCmpInst(Pred, X, Y);
+ NewFCmp->copyFastMathFlags(&I);
+ return NewFCmp;
+ }
+
+ // TODO: Use m_APFloat to handle vector splats.
+ ConstantFP *C;
+ if (match(Op1, m_ConstantFP(C))) {
+ // fcmp (fpext X), C -> fcmp X, (fptrunc C) if fptrunc is lossless
+ const fltSemantics &FPSem = X->getType()->getFltSemantics();
+ bool Lossy;
+ APFloat F = C->getValueAPF();
+ F.convert(FPSem, APFloat::rmNearestTiesToEven, &Lossy);
+
+ // Avoid lossy conversions and denormals.
+ // Zero is a special case that's OK to convert.
+ APFloat Fabs = F;
+ Fabs.clearSign();
+ if (!Lossy &&
+ ((Fabs.compare(APFloat::getSmallestNormalized(FPSem)) !=
+ APFloat::cmpLessThan) || Fabs.isZero()))
+ // TODO: Propagate FMF.
+ return new FCmpInst(Pred, X, ConstantFP::get(C->getContext(), F));
+ }
}
if (I.getType()->isVectorTy())
More information about the llvm-commits
mailing list