summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorCraig Topper <craig.topper@intel.com>2018-02-28 20:14:34 +0000
committerCraig Topper <craig.topper@intel.com>2018-02-28 20:14:34 +0000
commitb95298b041c4adc5df405f9549b7aef46948915f (patch)
tree7e4af9dd20d3e5f38862381b237cc3d719b9e4ac /llvm/lib
parent7440135e621107eeca788106f9a5e610dcde30aa (diff)
downloadbcm5719-llvm-b95298b041c4adc5df405f9549b7aef46948915f.tar.gz
bcm5719-llvm-b95298b041c4adc5df405f9549b7aef46948915f.zip
[InstCombine] Split the FP constant code out of lookThroughFPExtensions and use nullptr as a sentinel
Currently this code's control flow very much assumes that there are no meaningful checks after determining that it's a ConstantFP. So whenever it wants to stop it just does "return V". But V is also the variable name it uses when it wants to return a new value. So 'return V' appears multiple times with different meanings. This patch just moves all the code into a helper function and returns nullptr when it wants to stop. I've split this from D43774 while I try to figure out how to best handle the vector case there. But this change by itself at least seemed like a readability improvement. Differential Revision: https://reviews.llvm.org/D43833 llvm-svn: 326361
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp35
1 files changed, 20 insertions, 15 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
index 7026b24f4df..7ed792af1f3 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
@@ -1420,6 +1420,23 @@ static Constant *fitsInFPType(ConstantFP *CFP, const fltSemantics &Sem) {
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))
@@ -1428,21 +1445,9 @@ static Value *lookThroughFPExtensions(Value *V) {
// 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;
}
OpenPOWER on IntegriCloud