[PATCH] D132343: [InstCombine] Add undef elements support for shrinkFPConstantVector
Chenbing.Zheng via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 22 23:57:39 PDT 2022
Chenbing.Zheng updated this revision to Diff 454710.
Chenbing.Zheng added a comment.
address comment
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D132343/new/
https://reviews.llvm.org/D132343
Files:
llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
llvm/test/Transforms/InstCombine/fpextend.ll
Index: llvm/test/Transforms/InstCombine/fpextend.ll
===================================================================
--- llvm/test/Transforms/InstCombine/fpextend.ll
+++ llvm/test/Transforms/InstCombine/fpextend.ll
@@ -83,12 +83,9 @@
}
; 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>
Index: llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
@@ -1659,7 +1659,6 @@
// 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 @@
// 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 @@
}
// 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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132343.454710.patch
Type: text/x-patch
Size: 2034 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220823/c64ff1f9/attachment.bin>
More information about the llvm-commits
mailing list