[PATCH] D132343: [InstCombine] Add undef elements support for shrinkFPConstantVector
Chenbing.Zheng via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 21 20:40:20 PDT 2022
Chenbing.Zheng created this revision.
Chenbing.Zheng added reviewers: spatel, craig.topper, RKSimon, benshi001.
Chenbing.Zheng added a project: LLVM.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
Chenbing.Zheng requested review of this revision.
Herald added subscribers: llvm-commits, jacquesguan.
This patch add support for undef elements vector in shrinkFPConstantVector
function.
Repository:
rG LLVM Github Monorepo
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());
@@ -1675,7 +1674,7 @@
for (unsigned i = 0; i != NumElts; ++i) {
auto *CFP = dyn_cast_or_null<ConstantFP>(CV->getAggregateElement(i));
if (!CFP)
- return nullptr;
+ continue;
Type *T = shrinkFPConstant(CFP);
if (!T)
@@ -1688,7 +1687,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.454366.patch
Type: text/x-patch
Size: 1916 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220822/123237ca/attachment.bin>
More information about the llvm-commits
mailing list