Skip to content

Commit aec4860

Browse files
committed
[VectorCombine] Add constant splat handling for shuffleToIdentity
This adds splat constants, which can be treated like any other splat which makes them very simple. Other constants are not handled yet, they are planned in a later patch.
1 parent 335e00f commit aec4860

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

llvm/lib/Transforms/Vectorize/VectorCombine.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1789,6 +1789,17 @@ bool VectorCombine::foldShuffleToIdentity(Instruction &I) {
17891789
IdentityLeafs.insert(FrontV);
17901790
continue;
17911791
}
1792+
// Look for constants, for the moment only supporting constant splats.
1793+
if (auto *C = dyn_cast<Constant>(FrontV);
1794+
C && C->getSplatValue() &&
1795+
all_of(drop_begin(Item), [Item](InstLane &IL) {
1796+
Value *FrontV = Item.front().first;
1797+
Value *V = IL.first;
1798+
return !V || V == FrontV;
1799+
})) {
1800+
SplatLeafs.insert(FrontV);
1801+
continue;
1802+
}
17921803
// Look for a splat value.
17931804
if (all_of(drop_begin(Item), [Item](InstLane &IL) {
17941805
auto [FrontV, FrontLane] = Item.front();

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

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

282282
define <8 x i8> @constantsplat(<8 x i8> %a) {
283283
; CHECK-LABEL: @constantsplat(
284-
; CHECK-NEXT: [[AB:%.*]] = shufflevector <8 x i8> [[A:%.*]], <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
285-
; CHECK-NEXT: [[AT:%.*]] = shufflevector <8 x i8> [[A]], <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>
286-
; CHECK-NEXT: [[ABT:%.*]] = add <4 x i8> [[AT]], <i8 10, i8 10, i8 10, i8 10>
287-
; CHECK-NEXT: [[ABB:%.*]] = add <4 x i8> [[AB]], <i8 10, i8 10, i8 10, i8 10>
288-
; 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>
284+
; CHECK-NEXT: [[R:%.*]] = add <8 x i8> [[A:%.*]], <i8 10, i8 10, i8 10, i8 10, i8 10, i8 10, i8 10, i8 10>
289285
; CHECK-NEXT: ret <8 x i8> [[R]]
290286
;
291287
%ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
@@ -332,11 +328,7 @@ define <8 x i8> @constantdiff2(<8 x i8> %a) {
332328

333329
define <8 x half> @constantsplatf(<8 x half> %a) {
334330
; CHECK-LABEL: @constantsplatf(
335-
; CHECK-NEXT: [[AB:%.*]] = shufflevector <8 x half> [[A:%.*]], <8 x half> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
336-
; CHECK-NEXT: [[AT:%.*]] = shufflevector <8 x half> [[A]], <8 x half> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>
337-
; CHECK-NEXT: [[ABT:%.*]] = fadd <4 x half> [[AT]], <half 0xH4900, half 0xH4900, half 0xH4900, half 0xH4900>
338-
; CHECK-NEXT: [[ABB:%.*]] = fadd <4 x half> [[AB]], <half 0xH4900, half 0xH4900, half 0xH4900, half 0xH4900>
339-
; 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>
331+
; CHECK-NEXT: [[R:%.*]] = fadd <8 x half> [[A:%.*]], <half 0xH4900, half 0xH4900, half 0xH4900, half 0xH4900, half 0xH4900, half 0xH4900, half 0xH4900, half 0xH4900>
340332
; CHECK-NEXT: ret <8 x half> [[R]]
341333
;
342334
%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)