[llvm] 14fae4d - [InstCombine] Add undef elements support for shrinkFPConstantVector
Chenbing Zheng via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 24 19:40:22 PDT 2022
Author: Chenbing Zheng
Date: 2022-08-25T10:38:48+08:00
New Revision: 14fae4d136036d7967a3d819945677f7a892f2da
URL: https://github.com/llvm/llvm-project/commit/14fae4d136036d7967a3d819945677f7a892f2da
DIFF: https://github.com/llvm/llvm-project/commit/14fae4d136036d7967a3d819945677f7a892f2da.diff
LOG: [InstCombine] Add undef elements support for shrinkFPConstantVector
Reviewed By: RKSimon, spatel
Differential Revision: https://reviews.llvm.org/D132343
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
llvm/test/Transforms/InstCombine/fpextend.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
index d68169db61cf..1e6149220159 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
@@ -1659,7 +1659,6 @@ static Type *shrinkFPConstant(ConstantFP *CFP) {
// 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);
auto *CVVTy = dyn_cast<FixedVectorType>(V->getType());
@@ -1673,6 +1672,9 @@ static Type *shrinkFPConstantVector(Value *V) {
// For fixed-width vectors we find the minimal type by looking
// through the constant values of the vector.
for (unsigned i = 0; i != NumElts; ++i) {
+ if (isa<UndefValue>(CV->getAggregateElement(i)))
+ continue;
+
auto *CFP = dyn_cast_or_null<ConstantFP>(CV->getAggregateElement(i));
if (!CFP)
return nullptr;
@@ -1688,7 +1690,7 @@ static Type *shrinkFPConstantVector(Value *V) {
}
// Make a vector type from the minimal type.
- return FixedVectorType::get(MinType, NumElts);
+ return MinType ? FixedVectorType::get(MinType, NumElts) : nullptr;
}
/// Find the minimum FP type we can safely truncate to.
diff --git a/llvm/test/Transforms/InstCombine/fpextend.ll b/llvm/test/Transforms/InstCombine/fpextend.ll
index c991f5d8c957..a41f2a4ca300 100644
--- a/llvm/test/Transforms/InstCombine/fpextend.ll
+++ b/llvm/test/Transforms/InstCombine/fpextend.ll
@@ -83,12 +83,9 @@ define <2 x float> @test6(<2 x float> %x) nounwind {
}
; Test with an undef element
-; TODO: Support undef elements.
define <2 x float> @test6_undef(<2 x float> %x) nounwind {
; CHECK-LABEL: @test6_undef(
-; CHECK-NEXT: [[T1:%.*]] = fpext <2 x float> [[X:%.*]] to <2 x double>
-; CHECK-NEXT: [[T3:%.*]] = fadd <2 x double> [[T1]], <double 0.000000e+00, double undef>
-; CHECK-NEXT: [[T34:%.*]] = fptrunc <2 x double> [[T3]] to <2 x float>
+; CHECK-NEXT: [[T34:%.*]] = fadd <2 x float> [[X:%.*]], <float 0.000000e+00, float undef>
; CHECK-NEXT: ret <2 x float> [[T34]]
;
%t1 = fpext <2 x float> %x to <2 x double>
More information about the llvm-commits
mailing list