Skip to content

Commit b99f48c

Browse files
- Add isLane1KnownActive helper
- Extend canRemovePTestInstr for PTEST_PP_FIRST - Remove getVectorElementType() != MVT::i1 check for Mask
1 parent a3167b5 commit b99f48c

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20370,7 +20370,7 @@ static bool hasPairwiseAdd(unsigned Opcode, EVT VT, bool FullFP16) {
2037020370
}
2037120371

2037220372
static SDValue getPTest(SelectionDAG &DAG, EVT VT, SDValue Pg, SDValue Op,
20373-
AArch64CC::CondCode Cond, bool EmitCSel = true);
20373+
AArch64CC::CondCode Cond);
2037420374

2037520375
static bool isPredicateCCSettingOp(SDValue N) {
2037620376
if ((N.getOpcode() == ISD::SETCC) ||
@@ -20495,7 +20495,6 @@ static SDValue
2049520495
performExtractVectorEltCombine(SDNode *N, TargetLowering::DAGCombinerInfo &DCI,
2049620496
const AArch64Subtarget *Subtarget) {
2049720497
assert(N->getOpcode() == ISD::EXTRACT_VECTOR_ELT);
20498-
2049920498
if (SDValue Res = performFirstTrueTestVectorCombine(N, DCI, Subtarget))
2050020499
return Res;
2050120500
if (SDValue Res = performLastTrueTestVectorCombine(N, DCI, Subtarget))
@@ -22536,7 +22535,7 @@ static SDValue tryConvertSVEWideCompare(SDNode *N, ISD::CondCode CC,
2253622535
}
2253722536

2253822537
static SDValue getPTest(SelectionDAG &DAG, EVT VT, SDValue Pg, SDValue Op,
22539-
AArch64CC::CondCode Cond, bool EmitCSel) {
22538+
AArch64CC::CondCode Cond) {
2254022539
const TargetLowering &TLI = DAG.getTargetLoweringInfo();
2254122540

2254222541
SDLoc DL(Op);
@@ -22569,8 +22568,6 @@ static SDValue getPTest(SelectionDAG &DAG, EVT VT, SDValue Pg, SDValue Op,
2256922568

2257022569
// Set condition code (CC) flags.
2257122570
SDValue Test = DAG.getNode(PTest, DL, MVT::i32, Pg, Op);
22572-
if (!EmitCSel)
22573-
return Test;
2257422571

2257522572
// Convert CC to integer based on requested condition.
2257622573
// NOTE: Cond is inverted to promote CSEL's removal when it feeds a compare.
@@ -27237,6 +27234,21 @@ static bool isLanes1toNKnownZero(SDValue Op) {
2723727234
}
2723827235
}
2723927236

27237+
// Return true if the vector operation can guarantee that the first lane of its
27238+
// result is active.
27239+
static bool isLane1KnownActive(SDValue Op) {
27240+
switch (Op.getOpcode()) {
27241+
default:
27242+
return false;
27243+
case AArch64ISD::REINTERPRET_CAST:
27244+
return isLane1KnownActive(Op->getOperand(0));
27245+
case ISD::SPLAT_VECTOR:
27246+
return isOneConstant(Op.getOperand(0));
27247+
case AArch64ISD::PTRUE:
27248+
return Op.getConstantOperandVal(0) == AArch64SVEPredPattern::all;
27249+
};
27250+
}
27251+
2724027252
static SDValue removeRedundantInsertVectorElt(SDNode *N) {
2724127253
assert(N->getOpcode() == ISD::INSERT_VECTOR_ELT && "Unexpected node!");
2724227254
SDValue InsertVec = N->getOperand(0);
@@ -27532,22 +27544,17 @@ static SDValue performPTestFirstCombine(SDNode *N,
2753227544
auto Mask = N->getOperand(0);
2753327545
auto Pred = N->getOperand(1);
2753427546

27535-
if (Mask->getOpcode() == AArch64ISD::REINTERPRET_CAST)
27536-
Mask = Mask->getOperand(0);
27537-
2753827547
if (Pred->getOpcode() == AArch64ISD::REINTERPRET_CAST)
2753927548
Pred = Pred->getOperand(0);
2754027549

27541-
if (Pred->getValueType(0).getVectorElementType() != MVT::i1 ||
27542-
!isAllActivePredicate(DAG, Mask))
27550+
if (!isLane1KnownActive(Mask))
2754327551
return SDValue();
2754427552

2754527553
if (Pred->getOpcode() == ISD::CONCAT_VECTORS) {
2754627554
Pred = Pred->getOperand(0);
27547-
SDValue Mask = DAG.getSplatVector(Pred->getValueType(0), DL,
27548-
DAG.getAllOnesConstant(DL, MVT::i64));
27549-
return getPTest(DAG, N->getValueType(0), Mask, Pred,
27550-
AArch64CC::FIRST_ACTIVE, /* EmitCSel */ false);
27555+
Pred = DAG.getNode(AArch64ISD::REINTERPRET_CAST, DL, MVT::nxv16i1, Pred);
27556+
return DAG.getNode(AArch64ISD::PTEST_FIRST, DL, N->getValueType(0), Mask,
27557+
Pred);
2755127558
}
2755227559

2755327560
return SDValue();

llvm/lib/Target/AArch64/AArch64InstrInfo.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,6 +1503,10 @@ AArch64InstrInfo::canRemovePTestInstr(MachineInstr *PTest, MachineInstr *Mask,
15031503
getElementSizeForOpcode(PredOpcode))
15041504
return PredOpcode;
15051505

1506+
if (PTest->getOpcode() == AArch64::PTEST_PP_FIRST &&
1507+
isPTrueOpcode(MaskOpcode) && Mask->getOperand(1).getImm() == 31)
1508+
return PredOpcode;
1509+
15061510
return {};
15071511
}
15081512

0 commit comments

Comments
 (0)