Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit 5ac981f

Browse files
committed
Merging r332103:
------------------------------------------------------------------------ r332103 | gberry | 2018-05-11 09:25:06 -0700 (Fri, 11 May 2018) | 24 lines [AArch64] Fix performPostLD1Combine to check for constant lane index. Summary: performPostLD1Combine in AArch64ISelLowering looks for vector insert_vector_elt of a loaded value which it can optimize into a single LD1LANE instruction. The code checking for the pattern was not checking if the lane index was a constant which could cause two problems: - an assert when lowering the LD1LANE ISD node since it assumes an constant operand - an assert in isel if the lane index value depends on the post-incremented base register Both of these issues are avoided by simply checking that the lane index is a constant. Fixes bug 35822. Reviewers: t.p.northover, javed.absar Subscribers: rengolin, kristof.beyls, mcrosier, llvm-commits Differential Revision: https://reviews.llvm.org/D46591 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_60@332158 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent f3bbc06 commit 5ac981f

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9637,6 +9637,15 @@ static SDValue performPostLD1Combine(SDNode *N,
96379637
if (LD->getOpcode() != ISD::LOAD)
96389638
return SDValue();
96399639

9640+
// The vector lane must be a constant in the LD1LANE opcode.
9641+
SDValue Lane;
9642+
if (IsLaneOp) {
9643+
Lane = N->getOperand(2);
9644+
auto *LaneC = dyn_cast<ConstantSDNode>(Lane);
9645+
if (!LaneC || LaneC->getZExtValue() >= VT.getVectorNumElements())
9646+
return SDValue();
9647+
}
9648+
96409649
LoadSDNode *LoadSDN = cast<LoadSDNode>(LD);
96419650
EVT MemVT = LoadSDN->getMemoryVT();
96429651
// Check if memory operand is the same type as the vector element.
@@ -9693,7 +9702,7 @@ static SDValue performPostLD1Combine(SDNode *N,
96939702
Ops.push_back(LD->getOperand(0)); // Chain
96949703
if (IsLaneOp) {
96959704
Ops.push_back(Vector); // The vector to be inserted
9696-
Ops.push_back(N->getOperand(2)); // The lane to be inserted in the vector
9705+
Ops.push_back(Lane); // The lane to be inserted in the vector
96979706
}
96989707
Ops.push_back(Addr);
96999708
Ops.push_back(Inc);

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,28 @@ return: ; preds = %if.then172, %cond.e
2828
ret void
2929
}
3030

31+
; Avoid an assert/bad codegen in LD1LANEPOST lowering by not forming
32+
; LD1LANEPOST ISD nodes with a non-constant lane index.
33+
define <4 x i32> @f2(i32 *%p, <4 x i1> %m, <4 x i32> %v1, <4 x i32> %v2, i32 %idx) {
34+
%L0 = load i32, i32* %p
35+
%p1 = getelementptr i32, i32* %p, i64 1
36+
%L1 = load i32, i32* %p1
37+
%v = select <4 x i1> %m, <4 x i32> %v1, <4 x i32> %v2
38+
%vret = insertelement <4 x i32> %v, i32 %L0, i32 %idx
39+
store i32 %L1, i32 *%p
40+
ret <4 x i32> %vret
41+
}
42+
43+
; Check that a cycle is avoided during isel between the LD1LANEPOST instruction and the load of %L1.
44+
define <4 x i32> @f3(i32 *%p, <4 x i1> %m, <4 x i32> %v1, <4 x i32> %v2) {
45+
%L0 = load i32, i32* %p
46+
%p1 = getelementptr i32, i32* %p, i64 1
47+
%L1 = load i32, i32* %p1
48+
%v = select <4 x i1> %m, <4 x i32> %v1, <4 x i32> %v2
49+
%vret = insertelement <4 x i32> %v, i32 %L0, i32 %L1
50+
ret <4 x i32> %vret
51+
}
52+
3153
; Function Attrs: nounwind readnone
3254
declare i64 @llvm.objectsize.i64.p0i8(i8*, i1) #1
3355

0 commit comments

Comments
 (0)