-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[AArch64] Combine PTEST_FIRST(PTRUE, CONCAT(A, B)) -> PTEST_FIRST(PTRUE, A) #161384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
a3167b5
b99f48c
c5402af
095b1c3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27234,6 +27234,21 @@ static bool isLanes1toNKnownZero(SDValue Op) { | |
| } | ||
| } | ||
|
|
||
| // Return true if the vector operation can guarantee that the first lane of its | ||
| // result is active. | ||
| static bool isLane0KnownActive(SDValue Op) { | ||
| switch (Op.getOpcode()) { | ||
| default: | ||
| return false; | ||
| case AArch64ISD::REINTERPRET_CAST: | ||
| return isLane0KnownActive(Op->getOperand(0)); | ||
| case ISD::SPLAT_VECTOR: | ||
| return isOneConstant(Op.getOperand(0)); | ||
| case AArch64ISD::PTRUE: | ||
| return Op.getConstantOperandVal(0) == AArch64SVEPredPattern::all; | ||
| }; | ||
| } | ||
|
|
||
| static SDValue removeRedundantInsertVectorElt(SDNode *N) { | ||
| assert(N->getOpcode() == ISD::INSERT_VECTOR_ELT && "Unexpected node!"); | ||
| SDValue InsertVec = N->getOperand(0); | ||
|
|
@@ -27519,6 +27534,32 @@ static SDValue performMULLCombine(SDNode *N, | |
| return SDValue(); | ||
| } | ||
|
|
||
| static SDValue performPTestFirstCombine(SDNode *N, | ||
| TargetLowering::DAGCombinerInfo &DCI, | ||
| SelectionDAG &DAG) { | ||
| if (DCI.isBeforeLegalize()) | ||
| return SDValue(); | ||
|
|
||
| SDLoc DL(N); | ||
| auto Mask = N->getOperand(0); | ||
| auto Pred = N->getOperand(1); | ||
|
|
||
| if (Pred->getOpcode() == AArch64ISD::REINTERPRET_CAST) | ||
| Pred = Pred->getOperand(0); | ||
|
|
||
| if (!isLane0KnownActive(Mask)) | ||
| return SDValue(); | ||
|
Comment on lines
27547
to
27548
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps move this before looking through Pred's reinterpret_cast because this is what makes that code logically safe. |
||
|
|
||
| if (Pred->getOpcode() == ISD::CONCAT_VECTORS) { | ||
| Pred = Pred->getOperand(0); | ||
| Pred = DAG.getNode(AArch64ISD::REINTERPRET_CAST, DL, MVT::nxv16i1, Pred); | ||
| return DAG.getNode(AArch64ISD::PTEST_FIRST, DL, N->getValueType(0), Mask, | ||
| Pred); | ||
| } | ||
|
|
||
| return SDValue(); | ||
| } | ||
|
|
||
| static SDValue | ||
| performScalarToVectorCombine(SDNode *N, TargetLowering::DAGCombinerInfo &DCI, | ||
| SelectionDAG &DAG) { | ||
|
|
@@ -27875,6 +27916,8 @@ SDValue AArch64TargetLowering::PerformDAGCombine(SDNode *N, | |
| case AArch64ISD::UMULL: | ||
| case AArch64ISD::PMULL: | ||
| return performMULLCombine(N, DCI, DAG); | ||
| case AArch64ISD::PTEST_FIRST: | ||
| return performPTestFirstCombine(N, DCI, DAG); | ||
| case ISD::INTRINSIC_VOID: | ||
| case ISD::INTRINSIC_W_CHAIN: | ||
| switch (N->getConstantOperandVal(1)) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1503,6 +1503,10 @@ AArch64InstrInfo::canRemovePTestInstr(MachineInstr *PTest, MachineInstr *Mask, | |
| getElementSizeForOpcode(PredOpcode)) | ||
| return PredOpcode; | ||
|
|
||
| if (PTest->getOpcode() == AArch64::PTEST_PP_FIRST && | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps add a comment to match the other cases? |
||
| isPTrueOpcode(MaskOpcode) && Mask->getOperand(1).getImm() == 31) | ||
| return PredOpcode; | ||
|
|
||
| return {}; | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need the element type check because
AArch64ISD::REINTERPRET_CASTis only allowed to change the element count.