Skip to content

Commit b242ae3

Browse files
committed
[AArch64][GlobalISel] Protect against undef first element in CombineShuffleConcat.
In case the first element is undef, we need to look through to find a valid type for the inputs.
1 parent a2f9d1d commit b242ae3

File tree

2 files changed

+70
-1
lines changed

2 files changed

+70
-1
lines changed

llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,13 @@ bool CombinerHelper::matchCombineShuffleConcat(MachineInstr &MI,
445445

446446
void CombinerHelper::applyCombineShuffleConcat(MachineInstr &MI,
447447
SmallVector<Register> &Ops) {
448-
LLT SrcTy = MRI.getType(Ops[0]);
448+
LLT SrcTy;
449+
for (Register &Reg : Ops) {
450+
if (Reg != 0)
451+
SrcTy = MRI.getType(Reg);
452+
}
453+
assert(SrcTy.isValid() && "Unexpected full undef vector in concat combine");
454+
449455
Register UndefReg = 0;
450456

451457
for (Register &Reg : Ops) {

llvm/test/CodeGen/AArch64/concat-vector.ll

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,3 +271,66 @@ define <8 x i16> @concat_v8s16_v2s16_reg(<2 x i16> %A, <2 x i16> %B, <2 x i16> %
271271
%d = shufflevector <8 x i16> %b, <8 x i16> %c, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 8, i32 9, i32 10, i32 11>
272272
ret <8 x i16> %d
273273
}
274+
275+
define <4 x i16> @concat_undef_first_use_first(ptr %p1, ptr %p2) {
276+
; CHECK-SD-LABEL: concat_undef_first_use_first:
277+
; CHECK-SD: // %bb.0:
278+
; CHECK-SD-NEXT: ld1r { v0.2s }, [x0]
279+
; CHECK-SD-NEXT: ret
280+
;
281+
; CHECK-GI-LABEL: concat_undef_first_use_first:
282+
; CHECK-GI: // %bb.0:
283+
; CHECK-GI-NEXT: ldrh w8, [x0]
284+
; CHECK-GI-NEXT: ldrh w9, [x0, #2]
285+
; CHECK-GI-NEXT: fmov s1, w8
286+
; CHECK-GI-NEXT: mov v1.h[1], w9
287+
; CHECK-GI-NEXT: mov v0.s[1], v1.s[0]
288+
; CHECK-GI-NEXT: // kill: def $d0 killed $d0 killed $q0
289+
; CHECK-GI-NEXT: ret
290+
%l1 = load <2 x i16>, ptr %p1
291+
%l2 = load <2 x i16>, ptr %p2
292+
%ext1 = shufflevector <2 x i16> %l1, <2 x i16> poison, <8 x i32> <i32 0, i32 1, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
293+
%ext2 = shufflevector <2 x i16> %l1, <2 x i16> poison, <8 x i32> <i32 0, i32 1, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
294+
%t = shufflevector <8 x i16> %ext1, <8 x i16> %ext2, <4 x i32> <i32 poison, i32 poison, i32 0, i32 1>
295+
ret <4 x i16> %t
296+
}
297+
298+
define <4 x i16> @concat_undef_first_use_second(ptr %p1, ptr %p2) {
299+
; CHECK-SD-LABEL: concat_undef_first_use_second:
300+
; CHECK-SD: // %bb.0:
301+
; CHECK-SD-NEXT: ld1r { v0.2s }, [x0]
302+
; CHECK-SD-NEXT: ret
303+
;
304+
; CHECK-GI-LABEL: concat_undef_first_use_second:
305+
; CHECK-GI: // %bb.0:
306+
; CHECK-GI-NEXT: ldrh w8, [x0]
307+
; CHECK-GI-NEXT: ldrh w9, [x0, #2]
308+
; CHECK-GI-NEXT: fmov s1, w8
309+
; CHECK-GI-NEXT: mov v1.h[1], w9
310+
; CHECK-GI-NEXT: mov v0.s[1], v1.s[0]
311+
; CHECK-GI-NEXT: // kill: def $d0 killed $d0 killed $q0
312+
; CHECK-GI-NEXT: ret
313+
%l1 = load <2 x i16>, ptr %p1
314+
%l2 = load <2 x i16>, ptr %p2
315+
%ext1 = shufflevector <2 x i16> %l1, <2 x i16> poison, <8 x i32> <i32 0, i32 1, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
316+
%ext2 = shufflevector <2 x i16> %l1, <2 x i16> poison, <8 x i32> <i32 0, i32 1, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
317+
%t = shufflevector <8 x i16> %ext1, <8 x i16> %ext2, <4 x i32> <i32 poison, i32 poison, i32 8, i32 9>
318+
ret <4 x i16> %t
319+
}
320+
321+
define <4 x i16> @concat_undef_first_use_undef(ptr %p1, ptr %p2) {
322+
; CHECK-SD-LABEL: concat_undef_first_use_undef:
323+
; CHECK-SD: // %bb.0:
324+
; CHECK-SD-NEXT: ldr s0, [x0]
325+
; CHECK-SD-NEXT: ret
326+
;
327+
; CHECK-GI-LABEL: concat_undef_first_use_undef:
328+
; CHECK-GI: // %bb.0:
329+
; CHECK-GI-NEXT: ret
330+
%l1 = load <2 x i16>, ptr %p1
331+
%l2 = load <2 x i16>, ptr %p2
332+
%ext1 = shufflevector <2 x i16> %l1, <2 x i16> poison, <8 x i32> <i32 0, i32 1, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
333+
%ext2 = shufflevector <2 x i16> %l1, <2 x i16> poison, <8 x i32> <i32 0, i32 1, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
334+
%t = shufflevector <8 x i16> %ext1, <8 x i16> %ext2, <4 x i32> <i32 poison, i32 poison, i32 2, i32 3>
335+
ret <4 x i16> %t
336+
}

0 commit comments

Comments
 (0)