[PATCH] D114873: [SLP]Introduce isUndefVector function to check for undef vectors.
Alexey Bataev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 1 07:47:10 PST 2021
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
ABataev marked an inline comment as done.
Closed by commit rGcc30fbf2425c: [SLP]Introduce isUndefVector function to check for undef vectors. (authored by ABataev).
Changed prior to commit:
https://reviews.llvm.org/D114873?vs=391004&id=391025#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D114873/new/
https://reviews.llvm.org/D114873
Files:
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
llvm/test/Transforms/SLPVectorizer/X86/insert-element-build-vector-const-undef.ll
Index: llvm/test/Transforms/SLPVectorizer/X86/insert-element-build-vector-const-undef.ll
===================================================================
--- llvm/test/Transforms/SLPVectorizer/X86/insert-element-build-vector-const-undef.ll
+++ llvm/test/Transforms/SLPVectorizer/X86/insert-element-build-vector-const-undef.ll
@@ -18,8 +18,7 @@
; CHECK-NEXT: [[TMP7:%.*]] = insertelement <2 x float> [[TMP6]], float [[B1]], i32 1
; CHECK-NEXT: [[TMP8:%.*]] = select <2 x i1> [[TMP3]], <2 x float> [[TMP5]], <2 x float> [[TMP7]]
; CHECK-NEXT: [[TMP9:%.*]] = shufflevector <2 x float> [[TMP8]], <2 x float> poison, <4 x i32> <i32 0, i32 1, i32 undef, i32 undef>
-; CHECK-NEXT: [[RB1:%.*]] = shufflevector <4 x float> <float poison, float poison, float undef, float undef>, <4 x float> [[TMP9]], <4 x i32> <i32 4, i32 5, i32 2, i32 3>
-; CHECK-NEXT: ret <4 x float> [[RB1]]
+; CHECK-NEXT: ret <4 x float> [[TMP9]]
;
%c0 = extractelement <4 x i32> %c, i32 0
%c1 = extractelement <4 x i32> %c, i32 1
Index: llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
===================================================================
--- llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -283,6 +283,26 @@
return false;
}
+/// Checks if the given value is actually an undefined constant vector.
+static bool isUndefVector(const Value *V) {
+ if (isa<UndefValue>(V))
+ return true;
+ auto *C = dyn_cast<Constant>(V);
+ if (!C)
+ return false;
+ if (!C->containsUndefOrPoisonElement())
+ return false;
+ auto *VecTy = dyn_cast<FixedVectorType>(C->getType());
+ if (!VecTy)
+ return false;
+ for (unsigned I = 0, E = VecTy->getNumElements(); I != E; ++I) {
+ if (Constant *Elem = C->getAggregateElement(I))
+ if (!isa<UndefValue>(Elem))
+ return false;
+ }
+ return true;
+}
+
/// Checks if the vector of instructions can be represented as a shuffle, like:
/// %x0 = extractelement <4 x i8> %x, i32 0
/// %x3 = extractelement <4 x i8> %x, i32 3
@@ -350,7 +370,7 @@
return None;
auto *Vec = EI->getVectorOperand();
// We can extractelement from undef or poison vector.
- if (isa<UndefValue>(Vec))
+ if (isUndefVector(Vec))
continue;
// All vector operands must have the same number of vector elements.
if (cast<FixedVectorType>(Vec->getType())->getNumElements() != Size)
@@ -4786,7 +4806,7 @@
return !is_contained(E->Scalars,
cast<Instruction>(V)->getOperand(0));
}));
- if (isa<UndefValue>(FirstInsert->getOperand(0))) {
+ if (isUndefVector(FirstInsert->getOperand(0))) {
Cost += TTI->getShuffleCost(TTI::SK_PermuteSingleSrc, SrcVecTy, Mask);
} else {
SmallVector<int> InsertMask(NumElts);
@@ -6151,7 +6171,7 @@
V = Builder.CreateShuffleVector(V, Mask);
if ((!IsIdentity || Offset != 0 ||
- !isa<UndefValue>(FirstInsert->getOperand(0))) &&
+ !isUndefVector(FirstInsert->getOperand(0))) &&
NumElts != NumScalars) {
SmallVector<int> InsertMask(NumElts);
std::iota(InsertMask.begin(), InsertMask.end(), 0);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D114873.391025.patch
Type: text/x-patch
Size: 3229 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211201/fb7effde/attachment.bin>
More information about the llvm-commits
mailing list