summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorCraig Topper <craig.topper@intel.com>2018-03-05 18:04:12 +0000
committerCraig Topper <craig.topper@intel.com>2018-03-05 18:04:12 +0000
commit8452faceaee4a4adee5194d6c6ec7caad760c670 (patch)
treec70425fb66d6de1d27ea7a9538f6b38b1fc98400 /llvm/lib
parent75bc70fb56eb710ee90002b043d982abcf8c043e (diff)
downloadbcm5719-llvm-8452faceaee4a4adee5194d6c6ec7caad760c670.tar.gz
bcm5719-llvm-8452faceaee4a4adee5194d6c6ec7caad760c670.zip
[InstCombine] Add constant vector support to getMinimumFPType for visitFPTrunc.
This patch teaches getMinimumFPType to support shrinking a vector of ConstantFPs. This should improve our ability to combine vector fptrunc with fp binops. Differential Revision: https://reviews.llvm.org/D43774 llvm-svn: 326729
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
index fa47be2491d..1bc5a5706ef 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
@@ -1435,6 +1435,36 @@ static Type *shrinkFPConstant(ConstantFP *CFP) {
return nullptr;
}
+// Determine if this is a vector of ConstantFPs and if so, return the minimal
+// type we can safely truncate all elements to.
+// TODO: Make these support undef elements.
+static Type *shrinkFPConstantVector(Value *V) {
+ auto *CV = dyn_cast<Constant>(V);
+ if (!CV || !CV->getType()->isVectorTy())
+ return nullptr;
+
+ Type *MinType = nullptr;
+
+ unsigned NumElts = CV->getType()->getVectorNumElements();
+ for (unsigned i = 0; i != NumElts; ++i) {
+ auto *CFP = dyn_cast_or_null<ConstantFP>(CV->getAggregateElement(i));
+ if (!CFP)
+ return nullptr;
+
+ Type *T = shrinkFPConstant(CFP);
+ if (!T)
+ return nullptr;
+
+ // If we haven't found a type yet or this type has a larger mantissa than
+ // our previous type, this is our new minimal type.
+ if (!MinType || T->getFPMantissaWidth() > MinType->getFPMantissaWidth())
+ MinType = T;
+ }
+
+ // Make a vector type from the minimal type.
+ return VectorType::get(MinType, NumElts);
+}
+
/// Find the minimum FP type we can safely truncate to.
static Type *getMinimumFPType(Value *V) {
if (auto *FPExt = dyn_cast<FPExtInst>(V))
@@ -1447,6 +1477,10 @@ static Type *getMinimumFPType(Value *V) {
if (Type *T = shrinkFPConstant(CFP))
return T;
+ // Try to shrink a vector of FP constants.
+ if (Type *T = shrinkFPConstantVector(V))
+ return T;
+
return V->getType();
}
OpenPOWER on IntegriCloud