[llvm] 2516376 - [AArch64] Enhance last active true vector combine
via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 5 18:54:37 PDT 2022
Author: zhongyunde
Date: 2022-04-06T09:54:28+08:00
New Revision: 251637690ab486bd13d8408453314aa933501dd0
URL: https://github.com/llvm/llvm-project/commit/251637690ab486bd13d8408453314aa933501dd0
DIFF: https://github.com/llvm/llvm-project/commit/251637690ab486bd13d8408453314aa933501dd0.diff
LOG: [AArch64] Enhance last active true vector combine
Last active extracting will output LASTB + WHILELS, and the WHILELS itself
is a flag-setting operation, so perform it preferly.
Reviewed By: paulwalker-arm, sdesmalen
Differential Revision: https://reviews.llvm.org/D122551
Added:
Modified:
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
llvm/test/CodeGen/AArch64/sve-extract-element.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
index f6e1c6140147e..68c8d73fbcb6f 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -14551,15 +14551,15 @@ performLastTrueTestVectorCombine(SDNode *N,
if (!Subtarget->hasSVE() || DCI.isBeforeLegalize())
return SDValue();
- SDValue SetCC = N->getOperand(0);
- EVT OpVT = SetCC.getValueType();
+ SDValue N0 = N->getOperand(0);
+ EVT OpVT = N0.getValueType();
if (!OpVT.isScalableVector() || OpVT.getVectorElementType() != MVT::i1)
return SDValue();
// Idx == (add (mul vscale, NumEls), -1)
SDValue Idx = N->getOperand(1);
- if (Idx.getOpcode() != ISD::ADD)
+ if (Idx.getOpcode() != ISD::ADD || !isAllOnesConstant(Idx.getOperand(1)))
return SDValue();
SDValue VS = Idx.getOperand(0);
@@ -14570,16 +14570,10 @@ performLastTrueTestVectorCombine(SDNode *N,
if (VS.getConstantOperandVal(0) != NumEls)
return SDValue();
- // Restricted the DAG combine to only cases where we're extracting from a
- // flag-setting operation
- auto *CI = dyn_cast<ConstantSDNode>(Idx.getOperand(1));
- if (!CI || !CI->isAllOnes() || SetCC.getOpcode() != ISD::SETCC)
- return SDValue();
-
// Extracts of lane EC-1 for SVE can be expressed as PTEST(Op, LAST) ? 1 : 0
SelectionDAG &DAG = DCI.DAG;
SDValue Pg = getPTrue(DAG, SDLoc(N), OpVT, AArch64SVEPredPattern::all);
- return getPTest(DAG, N->getValueType(0), Pg, SetCC, AArch64CC::LAST_ACTIVE);
+ return getPTest(DAG, N->getValueType(0), Pg, N0, AArch64CC::LAST_ACTIVE);
}
static SDValue
diff --git a/llvm/test/CodeGen/AArch64/sve-extract-element.ll b/llvm/test/CodeGen/AArch64/sve-extract-element.ll
index 393f894e4b659..6e3da13ae77ba 100644
--- a/llvm/test/CodeGen/AArch64/sve-extract-element.ll
+++ b/llvm/test/CodeGen/AArch64/sve-extract-element.ll
@@ -504,12 +504,9 @@ define i1 @test_lane9_8xi1(<vscale x 8 x i1> %a) #0 {
define i1 @test_last_8xi1(<vscale x 8 x i1> %a) #0 {
; CHECK-LABEL: test_last_8xi1:
; CHECK: // %bb.0:
-; CHECK-NEXT: cnth x8
-; CHECK-NEXT: mov z0.h, p0/z, #1 // =0x1
-; CHECK-NEXT: sub x8, x8, #1
-; CHECK-NEXT: whilels p0.h, xzr, x8
-; CHECK-NEXT: lastb w8, p0, z0.h
-; CHECK-NEXT: and w0, w8, #0x1
+; CHECK-NEXT: ptrue p1.h
+; CHECK-NEXT: ptest p1, p0.b
+; CHECK-NEXT: cset w0, lo
; CHECK-NEXT: ret
%vscale = call i64 @llvm.vscale.i64()
%shl = shl nuw nsw i64 %vscale, 3
More information about the llvm-commits
mailing list