Skip to content

Commit 745110b

Browse files
committed
[VectorCombine] Add constant splat handling for shuffleToIdentity
This just adds splat constants, which can be treated like any other splat which hopefully makes them very simple. I will rebase over llvm#92766, but already had the patch for this version.
1 parent 285f139 commit 745110b

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

llvm/lib/Transforms/Vectorize/VectorCombine.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1739,6 +1739,15 @@ bool VectorCombine::foldShuffleToIdentity(Instruction &I) {
17391739
IdentityLeafs.insert(Item[0].first);
17401740
continue;
17411741
}
1742+
// Look for constants, for the moment only supporting constant splats.
1743+
if (isa<Constant>(Item[0].first) &&
1744+
cast<Constant>(Item[0].first)->getSplatValue() &&
1745+
all_of(drop_begin(Item), [&](InstLane &IL) {
1746+
return !IL.first || IL.first == Item[0].first;
1747+
})) {
1748+
SplatLeafs.insert(Item[0].first);
1749+
continue;
1750+
}
17421751
// Look for a splat value.
17431752
if (all_of(drop_begin(Item), [&](InstLane &IL) {
17441753
return !IL.first ||

llvm/test/Transforms/VectorCombine/AArch64/shuffletoidentity.ll

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -268,11 +268,7 @@ define <8 x i8> @undeflane(<8 x i8> %a, <8 x i8> %b) {
268268

269269
define <8 x i8> @constantsplat(<8 x i8> %a) {
270270
; CHECK-LABEL: @constantsplat(
271-
; CHECK-NEXT: [[AB:%.*]] = shufflevector <8 x i8> [[A:%.*]], <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
272-
; CHECK-NEXT: [[AT:%.*]] = shufflevector <8 x i8> [[A]], <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>
273-
; CHECK-NEXT: [[ABT:%.*]] = add <4 x i8> [[AT]], <i8 10, i8 10, i8 10, i8 10>
274-
; CHECK-NEXT: [[ABB:%.*]] = add <4 x i8> [[AB]], <i8 10, i8 10, i8 10, i8 10>
275-
; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x i8> [[ABT]], <4 x i8> [[ABB]], <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
271+
; CHECK-NEXT: [[R:%.*]] = add <8 x i8> [[A:%.*]], <i8 10, i8 10, i8 10, i8 10, i8 10, i8 10, i8 10, i8 10>
276272
; CHECK-NEXT: ret <8 x i8> [[R]]
277273
;
278274
%ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
@@ -319,11 +315,7 @@ define <8 x i8> @constantdiff2(<8 x i8> %a) {
319315

320316
define <8 x half> @constantsplatf(<8 x half> %a) {
321317
; CHECK-LABEL: @constantsplatf(
322-
; CHECK-NEXT: [[AB:%.*]] = shufflevector <8 x half> [[A:%.*]], <8 x half> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
323-
; CHECK-NEXT: [[AT:%.*]] = shufflevector <8 x half> [[A]], <8 x half> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>
324-
; CHECK-NEXT: [[ABT:%.*]] = fadd <4 x half> [[AT]], <half 0xH4900, half 0xH4900, half 0xH4900, half 0xH4900>
325-
; CHECK-NEXT: [[ABB:%.*]] = fadd <4 x half> [[AB]], <half 0xH4900, half 0xH4900, half 0xH4900, half 0xH4900>
326-
; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x half> [[ABT]], <4 x half> [[ABB]], <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
318+
; CHECK-NEXT: [[R:%.*]] = fadd <8 x half> [[A:%.*]], <half 0xH4900, half 0xH4900, half 0xH4900, half 0xH4900, half 0xH4900, half 0xH4900, half 0xH4900, half 0xH4900>
327319
; CHECK-NEXT: ret <8 x half> [[R]]
328320
;
329321
%ab = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>

0 commit comments

Comments
 (0)