[PATCH] D43833: [InstCombine] Split the FP constant code out of lookThroughFPExtensions and use nullptr as a sentinel.
Phabricator via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 28 12:16:52 PST 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rL326361: [InstCombine] Split the FP constant code out of lookThroughFPExtensions and useā¦ (authored by ctopper, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D43833?vs=136158&id=136356#toc
Repository:
rL LLVM
https://reviews.llvm.org/D43833
Files:
llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp
Index: llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp
===================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp
@@ -1420,29 +1420,34 @@
return nullptr;
}
+static Constant *shrinkFPConstant(ConstantFP *CFP) {
+ if (CFP->getType() == Type::getPPC_FP128Ty(CFP->getContext()))
+ return nullptr; // No constant folding of this.
+ // See if the value can be truncated to half and then reextended.
+ if (Constant *NewCFP = fitsInFPType(CFP, APFloat::IEEEhalf()))
+ return NewCFP;
+ // See if the value can be truncated to float and then reextended.
+ if (Constant *NewCFP = fitsInFPType(CFP, APFloat::IEEEsingle()))
+ return NewCFP;
+ if (CFP->getType()->isDoubleTy())
+ return nullptr; // Won't shrink.
+ if (Constant *NewCFP = fitsInFPType(CFP, APFloat::IEEEdouble()))
+ return NewCFP;
+ // Don't try to shrink to various long double types.
+ return nullptr;
+}
+
/// Look through floating-point extensions until we get the source value.
static Value *lookThroughFPExtensions(Value *V) {
while (auto *FPExt = dyn_cast<FPExtInst>(V))
V = FPExt->getOperand(0);
// If this value is a constant, return the constant in the smallest FP type
// that can accurately represent it. This allows us to turn
// (float)((double)X+2.0) into x+2.0f.
- if (auto *CFP = dyn_cast<ConstantFP>(V)) {
- if (CFP->getType() == Type::getPPC_FP128Ty(V->getContext()))
- return V; // No constant folding of this.
- // See if the value can be truncated to half and then reextended.
- if (Value *V = fitsInFPType(CFP, APFloat::IEEEhalf()))
- return V;
- // See if the value can be truncated to float and then reextended.
- if (Value *V = fitsInFPType(CFP, APFloat::IEEEsingle()))
- return V;
- if (CFP->getType()->isDoubleTy())
- return V; // Won't shrink.
- if (Value *V = fitsInFPType(CFP, APFloat::IEEEdouble()))
- return V;
- // Don't try to shrink to various long double types.
- }
+ if (auto *CFP = dyn_cast<ConstantFP>(V))
+ if (Constant *NewCFP = shrinkFPConstant(CFP))
+ return NewCFP;
return V;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43833.136356.patch
Type: text/x-patch
Size: 2243 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180228/1f7658ef/attachment.bin>
More information about the llvm-commits
mailing list