Skip to content

Commit 8e34dd9

Browse files
committed
[x86] avoid crashing when splitting AVX stores with non-simple type (PR43916)
The store splitting transform was assuming a simple type (MVT), but that's not necessarily the case as shown in the test.
1 parent 3e54404 commit 8e34dd9

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21776,12 +21776,14 @@ static SDValue splitVectorStore(StoreSDNode *Store, SelectionDAG &DAG) {
2177621776
"Expecting 256/512-bit op");
2177721777

2177821778
// Splitting volatile memory ops is not allowed unless the operation was not
21779-
// legal to begin with. We are assuming the input op is legal (this transform
21780-
// is only used for targets with AVX).
21779+
// legal to begin with. Assume the input store is legal (this transform is
21780+
// only used for targets with AVX). Note: It is possible that we have an
21781+
// illegal type like v2i128, and so we could allow splitting a volatile store
21782+
// in that case if that is important.
2178121783
if (!Store->isSimple())
2178221784
return SDValue();
2178321785

21784-
MVT StoreVT = StoredVal.getSimpleValueType();
21786+
EVT StoreVT = StoredVal.getValueType();
2178521787
unsigned NumElems = StoreVT.getVectorNumElements();
2178621788
unsigned HalfSize = StoredVal.getValueSizeInBits() / 2;
2178721789
unsigned HalfAlign = (128 == HalfSize ? 16 : 32);

llvm/test/CodeGen/X86/avx-load-store.ll

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,3 +333,26 @@ define void @add4i64a16(<4 x i64>* %ret, <4 x i64>* %bp) nounwind {
333333
ret void
334334
}
335335

336+
; This used to crash.
337+
; v2i128 may not be a "simple" (MVT) type, but we can split that.
338+
; This example gets split further in legalization.
339+
340+
define void @PR43916(<2 x i128> %y, <2 x i128>* %z) {
341+
; CHECK-LABEL: PR43916:
342+
; CHECK: # %bb.0:
343+
; CHECK-NEXT: movq %rcx, 24(%r8)
344+
; CHECK-NEXT: movq %rdx, 16(%r8)
345+
; CHECK-NEXT: movq %rsi, 8(%r8)
346+
; CHECK-NEXT: movq %rdi, (%r8)
347+
; CHECK-NEXT: retq
348+
;
349+
; CHECK_O0-LABEL: PR43916:
350+
; CHECK_O0: # %bb.0:
351+
; CHECK_O0-NEXT: movq %rdi, (%r8)
352+
; CHECK_O0-NEXT: movq %rsi, 8(%r8)
353+
; CHECK_O0-NEXT: movq %rdx, 16(%r8)
354+
; CHECK_O0-NEXT: movq %rcx, 24(%r8)
355+
; CHECK_O0-NEXT: retq
356+
store <2 x i128> %y, <2 x i128>* %z, align 16
357+
ret void
358+
}

0 commit comments

Comments
 (0)