Skip to content

Commit af5faf8

Browse files
rotaterighttstellar
authored andcommitted
[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. (cherry picked from commit 8e34dd9)
1 parent 7fc9f12 commit af5faf8

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
@@ -21182,12 +21182,14 @@ static SDValue splitVectorStore(StoreSDNode *Store, SelectionDAG &DAG) {
2118221182
"Expecting 256/512-bit op");
2118321183

2118421184
// Splitting volatile memory ops is not allowed unless the operation was not
21185-
// legal to begin with. We are assuming the input op is legal (this transform
21186-
// is only used for targets with AVX).
21185+
// legal to begin with. Assume the input store is legal (this transform is
21186+
// only used for targets with AVX). Note: It is possible that we have an
21187+
// illegal type like v2i128, and so we could allow splitting a volatile store
21188+
// in that case if that is important.
2118721189
if (Store->isVolatile())
2118821190
return SDValue();
2118921191

21190-
MVT StoreVT = StoredVal.getSimpleValueType();
21192+
EVT StoreVT = StoredVal.getValueType();
2119121193
unsigned NumElems = StoreVT.getVectorNumElements();
2119221194
unsigned HalfSize = StoredVal.getValueSizeInBits() / 2;
2119321195
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)