[PATCH] D100107: [AArch64][SVE] Optimize index_vector with add
JunMa via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 8 07:15:25 PDT 2021
junparser updated this revision to Diff 336096.
junparser added a comment.
fix typo.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D100107/new/
https://reviews.llvm.org/D100107
Files:
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
llvm/test/CodeGen/AArch64/sve-stepvector.ll
Index: llvm/test/CodeGen/AArch64/sve-stepvector.ll
===================================================================
--- llvm/test/CodeGen/AArch64/sve-stepvector.ll
+++ llvm/test/CodeGen/AArch64/sve-stepvector.ll
@@ -49,9 +49,8 @@
; CHECK-LABEL: stepvector_nxv4i64:
; CHECK: // %bb.0: // %entry
; CHECK-NEXT: cntd x8
-; CHECK-NEXT: mov z1.d, x8
+; CHECK-NEXT: index z1.d, x8, #1
; CHECK-NEXT: index z0.d, #0, #1
-; CHECK-NEXT: add z1.d, z0.d, z1.d
; CHECK-NEXT: ret
entry:
%0 = call <vscale x 4 x i64> @llvm.experimental.stepvector.nxv4i64()
@@ -61,14 +60,13 @@
define <vscale x 16 x i32> @stepvector_nxv16i32() {
; CHECK-LABEL: stepvector_nxv16i32:
; CHECK: // %bb.0: // %entry
-; CHECK-NEXT: cntw x9
; CHECK-NEXT: cnth x8
+; CHECK-NEXT: cntw x9
+; CHECK-NEXT: mov z0.s, w8
+; CHECK-NEXT: index z1.s, w9, #1
+; CHECK-NEXT: index z2.s, w8, #1
+; CHECK-NEXT: add z3.s, z1.s, z0.s
; CHECK-NEXT: index z0.s, #0, #1
-; CHECK-NEXT: mov z1.s, w9
-; CHECK-NEXT: mov z3.s, w8
-; CHECK-NEXT: add z1.s, z0.s, z1.s
-; CHECK-NEXT: add z2.s, z0.s, z3.s
-; CHECK-NEXT: add z3.s, z1.s, z3.s
; CHECK-NEXT: ret
entry:
%0 = call <vscale x 16 x i32> @llvm.experimental.stepvector.nxv16i32()
Index: llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
===================================================================
--- llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -13433,6 +13433,32 @@
return DAG.getNode(N->getOpcode(), SDLoc(N), VT, LHS, RHS);
}
+// add(index_vector(zero, step), dup(X)) -> index_vector(X, step)
+static SDValue performAddIndexVectorCombine(SDNode *N, SelectionDAG &DAG) {
+ if (N->getOpcode() != ISD::ADD)
+ return SDValue();
+
+ SDValue IV = N->getOperand(0);
+ SDValue A = N->getOperand(1);
+ // Handle commutivity
+ if (IV.getOpcode() != AArch64ISD::INDEX_VECTOR)
+ std::swap(IV, A);
+ if (IV.getOpcode() != AArch64ISD::INDEX_VECTOR)
+ return SDValue();
+
+ EVT VT = N->getValueType(0);
+ assert(VT.isScalableVector() &&
+ "Only expect scalable vectors for STEP_VECTOR");
+
+ auto *BaseVal = dyn_cast<ConstantSDNode>(IV->getOperand(0));
+ if (BaseVal && BaseVal->isNullValue() &&
+ (A.getOpcode() == AArch64ISD::DUP || A.getOpcode() == ISD::SPLAT_VECTOR))
+ return DAG.getNode(AArch64ISD::INDEX_VECTOR, SDLoc(N), VT, A->getOperand(0),
+ IV->getOperand(1));
+
+ return SDValue();
+}
+
static SDValue performAddSubCombine(SDNode *N,
TargetLowering::DAGCombinerInfo &DCI,
SelectionDAG &DAG) {
@@ -13442,6 +13468,10 @@
if (SDValue Val = performAddDotCombine(N, DAG))
return Val;
+ // Try to combine add with index_vector
+ if (SDValue Val = performAddIndexVectorCombine(N, DAG))
+ return Val;
+
return performAddSubLongCombine(N, DCI, DAG);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100107.336096.patch
Type: text/x-patch
Size: 2953 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210408/ed68051a/attachment.bin>
More information about the llvm-commits
mailing list