Skip to content

Commit ced70f6

Browse files
[fixup] Guard against extracting a fixed-length vector
1 parent 450b580 commit ced70f6

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20572,7 +20572,7 @@ static SDValue tryCombineWhileLo(SDNode *N,
2057220572

2057320573
EVT HalfVec = Lo->getValueType(0);
2057420574
if (HalfVec != Hi->getValueType(0) ||
20575-
HalfVec.getVectorMinNumElements() != HalfSize)
20575+
HalfVec.getVectorElementCount() != ElementCount::getScalable(HalfSize))
2057620576
return SDValue();
2057720577

2057820578
SelectionDAG &DAG = DCI.DAG;

llvm/test/CodeGen/AArch64/get-active-lane-mask-extract.ll

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ define void @test_boring_case_2x2bit_mask(i64 %i, i64 %n) #0 {
8585
ret void
8686
}
8787

88-
88+
; Negative test for when not extracting exactly two halves of the source vector
8989
define void @test_partial_extract(i64 %i, i64 %n) #0 {
9090
; CHECK-SVE-LABEL: test_partial_extract:
9191
; CHECK-SVE: // %bb.0:
@@ -111,6 +111,46 @@ define void @test_partial_extract(i64 %i, i64 %n) #0 {
111111
ret void
112112
}
113113

114+
;; Negative test for when extracting a fixed-length vector.
115+
define void @test_fixed_extract(i64 %i, i64 %n) #0 {
116+
; CHECK-SVE-LABEL: test_fixed_extract:
117+
; CHECK-SVE: // %bb.0:
118+
; CHECK-SVE-NEXT: whilelo p0.h, x0, x1
119+
; CHECK-SVE-NEXT: cset w8, mi
120+
; CHECK-SVE-NEXT: mov z0.h, p0/z, #1 // =0x1
121+
; CHECK-SVE-NEXT: umov w9, v0.h[4]
122+
; CHECK-SVE-NEXT: umov w10, v0.h[1]
123+
; CHECK-SVE-NEXT: umov w11, v0.h[5]
124+
; CHECK-SVE-NEXT: fmov s0, w8
125+
; CHECK-SVE-NEXT: fmov s1, w9
126+
; CHECK-SVE-NEXT: mov v0.s[1], w10
127+
; CHECK-SVE-NEXT: // kill: def $d0 killed $d0 killed $q0
128+
; CHECK-SVE-NEXT: mov v1.s[1], w11
129+
; CHECK-SVE-NEXT: // kill: def $d1 killed $d1 killed $q1
130+
; CHECK-SVE-NEXT: b use
131+
;
132+
; CHECK-SVE2p1-LABEL: test_fixed_extract:
133+
; CHECK-SVE2p1: // %bb.0:
134+
; CHECK-SVE2p1-NEXT: whilelo p0.h, x0, x1
135+
; CHECK-SVE2p1-NEXT: cset w8, mi
136+
; CHECK-SVE2p1-NEXT: mov z0.h, p0/z, #1 // =0x1
137+
; CHECK-SVE2p1-NEXT: umov w9, v0.h[4]
138+
; CHECK-SVE2p1-NEXT: umov w10, v0.h[1]
139+
; CHECK-SVE2p1-NEXT: umov w11, v0.h[5]
140+
; CHECK-SVE2p1-NEXT: fmov s0, w8
141+
; CHECK-SVE2p1-NEXT: fmov s1, w9
142+
; CHECK-SVE2p1-NEXT: mov v0.s[1], w10
143+
; CHECK-SVE2p1-NEXT: // kill: def $d0 killed $d0 killed $q0
144+
; CHECK-SVE2p1-NEXT: mov v1.s[1], w11
145+
; CHECK-SVE2p1-NEXT: // kill: def $d1 killed $d1 killed $q1
146+
; CHECK-SVE2p1-NEXT: b use
147+
%r = call <vscale x 8 x i1> @llvm.get.active.lane.mask.nxv8i1.i64(i64 %i, i64 %n)
148+
%v0 = call <2 x i1> @llvm.vector.extract.v2i1.nxv8i1.i64(<vscale x 8 x i1> %r, i64 0)
149+
%v1 = call <2 x i1> @llvm.vector.extract.v2i1.nxv8i1.i64(<vscale x 8 x i1> %r, i64 4)
150+
tail call void @use(<2 x i1> %v0, <2 x i1> %v1)
151+
ret void
152+
}
153+
114154
declare void @use(...)
115155

116156
attributes #0 = { nounwind }

0 commit comments

Comments
 (0)