[PATCH] D120891: [AArch64] Perform first active true vector combine
Allen zhong via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 7 07:17:43 PST 2022
Allen updated this revision to Diff 413463.
Allen marked an inline comment as done.
Allen added a comment.
Address comments
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D120891/new/
https://reviews.llvm.org/D120891
Files:
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
llvm/test/CodeGen/AArch64/sve-cmp-folds.ll
Index: llvm/test/CodeGen/AArch64/sve-cmp-folds.ll
===================================================================
--- llvm/test/CodeGen/AArch64/sve-cmp-folds.ll
+++ llvm/test/CodeGen/AArch64/sve-cmp-folds.ll
@@ -52,3 +52,17 @@
%not = xor <vscale x 4 x i1> %icmp, %ones
ret <vscale x 4 x i1> %not
}
+
+define i1 @foo(<vscale x 4 x float> %a, <vscale x 4 x float> %b) {
+; CHECK-LABEL: foo:
+; CHECK: // %bb.0:
+; CHECK-NEXT: ptrue p0.s
+; CHECK-NEXT: fcmeq p1.s, p0/z, z0.s, z1.s
+; CHECK-NEXT: ptest p0, p1.b
+; CHECK-NEXT: cset w0, mi
+; CHECK-NEXT: ret
+ %vcond = fcmp oeq <vscale x 4 x float> %a, %b
+ %bit = extractelement <vscale x 4 x i1> %vcond, i64 0
+ ret i1 %bit
+}
+
Index: llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
===================================================================
--- llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -14364,7 +14364,44 @@
}
}
-static SDValue performExtractVectorEltCombine(SDNode *N, SelectionDAG &DAG) {
+static SDValue getPTest(SelectionDAG &DAG, EVT VT, SDValue Pg, SDValue Op,
+ AArch64CC::CondCode Cond);
+
+// Materialize : i1 = extract_vector_elt t37, Constant:i64<0>
+// ... into: "ptrue p, all" + PTEST
+static SDValue
+performFirstTrueTestVectorCombine(SDNode *N,
+ TargetLowering::DAGCombinerInfo &DCI,
+ const AArch64Subtarget *Subtarget) {
+ if (!Subtarget->hasSVE() || !DCI.isBeforeLegalize())
+ return SDValue();
+
+ SDValue SetCC = N->getOperand(0);
+ EVT VT = SetCC.getValueType();
+
+ if (!VT.isScalableVector() || VT.getVectorElementType() != MVT::i1)
+ return SDValue();
+
+ // Restricted the DAG combine to only cases where we're extracting from a
+ // flag-setting operation
+ auto *Idx = dyn_cast<ConstantSDNode>(N->getOperand(1));
+ if (!Idx || !Idx->isZero() || SetCC.getOpcode() != ISD::SETCC)
+ return SDValue();
+
+ // Extracts of lane 0 for SVE can be expressed as PTEST(Op, FIRST) ? 1 : 0
+ SelectionDAG &DAG = DCI.DAG;
+ SDValue Pg = getPTrue(DAG, SDLoc(N), VT, AArch64SVEPredPattern::all);
+ return getPTest(DAG, N->getValueType(0), Pg, SetCC, AArch64CC::FIRST_ACTIVE);
+}
+
+static SDValue performExtractVectorEltCombine(SDNode *N,
+ TargetLowering::DAGCombinerInfo &DCI,
+ const AArch64Subtarget *Subtarget) {
+ assert(N->getOpcode() == ISD::EXTRACT_VECTOR_ELT);
+ if (SDValue Res = performFirstTrueTestVectorCombine (N, DCI, Subtarget))
+ return Res;
+
+ SelectionDAG &DAG = DCI.DAG;
SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
ConstantSDNode *ConstantN1 = dyn_cast<ConstantSDNode>(N1);
@@ -18356,7 +18393,7 @@
case ISD::INSERT_VECTOR_ELT:
return performInsertVectorEltCombine(N, DCI);
case ISD::EXTRACT_VECTOR_ELT:
- return performExtractVectorEltCombine(N, DAG);
+ return performExtractVectorEltCombine(N, DCI, Subtarget);
case ISD::VECREDUCE_ADD:
return performVecReduceAddCombine(N, DCI.DAG, Subtarget);
case AArch64ISD::UADDV:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120891.413463.patch
Type: text/x-patch
Size: 3168 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220307/5d6a7d1e/attachment.bin>
More information about the llvm-commits
mailing list