Skip to content

Commit 380d817

Browse files
authored
Merge pull request #9701 from swiftlang/jroelofs/6.1-cherrypicks
[🍒 swift/release/6.1] [llvm][AArch64] Fix a crash in performPostLD1Combine
2 parents 40f7f30 + 0dbf825 commit 380d817

File tree

2 files changed

+42
-6
lines changed

2 files changed

+42
-6
lines changed

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22450,10 +22450,15 @@ static SDValue performPostLD1Combine(SDNode *N,
2245022450
if (!VT.is128BitVector() && !VT.is64BitVector())
2245122451
return SDValue();
2245222452

22453-
unsigned LoadIdx = IsLaneOp ? 1 : 0;
22454-
SDNode *LD = N->getOperand(LoadIdx).getNode();
2245522453
// If it is not LOAD, can not do such combine.
22456-
if (LD->getOpcode() != ISD::LOAD)
22454+
unsigned LoadIdx = IsLaneOp ? 1 : 0;
22455+
LoadSDNode *LD = dyn_cast<LoadSDNode>(N->getOperand(LoadIdx).getNode());
22456+
if (!LD)
22457+
return SDValue();
22458+
22459+
// If the Generic combiner already helped form a pre- or post-indexed load,
22460+
// skip forming one here.
22461+
if (LD->isIndexed())
2245722462
return SDValue();
2245822463

2245922464
// The vector lane must be a constant in the LD1LANE opcode.

llvm/test/CodeGen/AArch64/arm64-indexed-vector-ldst-2.ll

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
; RUN: llc < %s
22

3-
; This used to assert with "Overran sorted position" in AssignTopologicalOrder
4-
; due to a cycle created in performPostLD1Combine.
5-
63
target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
74
target triple = "arm64-apple-ios7.0.0"
85

6+
; This used to assert with "Overran sorted position" in AssignTopologicalOrder
7+
; due to a cycle created in performPostLD1Combine.
8+
99
; Function Attrs: nounwind ssp
1010
define void @f(ptr %P1) #0 {
1111
entry:
@@ -50,6 +50,37 @@ define <4 x i32> @f3(ptr %p, <4 x i1> %m, <4 x i32> %v1, <4 x i32> %v2) {
5050
ret <4 x i32> %vret
5151
}
5252

53+
; This test used to crash in performPostLD1Combine when the combine attempted to
54+
; replace a load that already had index writeback, resulting in an incorrect
55+
; CombineTo, which would have changed the number of SDValue results of the
56+
; instruction.
57+
define i32 @rdar138004275(ptr %arg, i1 %arg1) {
58+
bb:
59+
br label %bb3
60+
61+
bb2: ; preds = %bb3
62+
store volatile <8 x half> %shufflevector10, ptr null, align 16
63+
ret i32 0
64+
65+
bb3: ; preds = %bb3, %bb
66+
%phi = phi ptr [ null, %bb ], [ %getelementptr11, %bb3 ]
67+
%load = load <2 x half>, ptr %phi, align 4
68+
%shufflevector = shufflevector <2 x half> %load, <2 x half> zeroinitializer, <8 x i32> <i32 0, i32 1, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
69+
%getelementptr = getelementptr i8, ptr %phi, i64 4
70+
%load4 = load half, ptr %getelementptr, align 2
71+
%insertelement = insertelement <2 x half> zeroinitializer, half %load4, i64 0
72+
%shufflevector5 = shufflevector <2 x half> %insertelement, <2 x half> zeroinitializer, <8 x i32> <i32 0, i32 0, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
73+
%shufflevector6 = shufflevector <8 x half> %shufflevector, <8 x half> %shufflevector5, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 8, i32 9, i32 6, i32 7>
74+
store <8 x half> %shufflevector6, ptr %arg, align 16
75+
%getelementptr7 = getelementptr i8, ptr %phi, i64 6
76+
%load8 = load <2 x half>, ptr %getelementptr7, align 4
77+
%shufflevector9 = shufflevector <2 x half> %load8, <2 x half> zeroinitializer, <8 x i32> <i32 0, i32 1, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
78+
%shufflevector10 = shufflevector <8 x half> %shufflevector9, <8 x half> zeroinitializer, <8 x i32> <i32 0, i32 1, i32 10, i32 11, i32 poison, i32 poison, i32 14, i32 15>
79+
%getelementptr11 = getelementptr i8, ptr %phi, i64 6
80+
br i1 %arg1, label %bb2, label %bb3
81+
}
82+
83+
5384
; Function Attrs: nounwind readnone
5485
declare i64 @llvm.objectsize.i64.p0(ptr, i1) #1
5586

0 commit comments

Comments
 (0)