Skip to content

Commit c6c60e1

Browse files
authored
[AArch64] Combine signext_inreg of setcc(... != splat(0)) (#157665)
Add the following fold AArch64 DAGCombine: Fold setcc_merge_zero( pred, insert_subvector(undef, signext_inreg(vNi1), 0), != splat(0)) -> setcc_merge_zero(pred, insert_subvector(undef, shl(vNi1), 0), != splat(0)) as the comparison (!= 0) depends only on bit 0 of the input, the left shift is sufficient.
1 parent 7936b6f commit c6c60e1

7 files changed

+167
-216
lines changed

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26104,6 +26104,17 @@ static SDValue performSetCCPunpkCombine(SDNode *N, SelectionDAG &DAG) {
2610426104
return SDValue();
2610526105
}
2610626106

26107+
static bool isSignExtInReg(const SDValue &V) {
26108+
if (V.getOpcode() != AArch64ISD::VASHR ||
26109+
V.getOperand(0).getOpcode() != AArch64ISD::VSHL)
26110+
return false;
26111+
26112+
unsigned BitWidth = V->getValueType(0).getScalarSizeInBits();
26113+
unsigned ShiftAmtR = V.getConstantOperandVal(1);
26114+
unsigned ShiftAmtL = V.getOperand(0).getConstantOperandVal(1);
26115+
return (ShiftAmtR == ShiftAmtL && ShiftAmtR == (BitWidth - 1));
26116+
}
26117+
2610726118
static SDValue
2610826119
performSetccMergeZeroCombine(SDNode *N, TargetLowering::DAGCombinerInfo &DCI) {
2610926120
assert(N->getOpcode() == AArch64ISD::SETCC_MERGE_ZERO &&
@@ -26144,6 +26155,27 @@ performSetccMergeZeroCombine(SDNode *N, TargetLowering::DAGCombinerInfo &DCI) {
2614426155
LHS->getOperand(0), Pred);
2614526156
}
2614626157

26158+
// setcc_merge_zero(
26159+
// pred, insert_subvector(undef, signext_inreg(vNi1), 0), != splat(0))
26160+
// => setcc_merge_zero(
26161+
// pred, insert_subvector(undef, shl(vNi1), 0), != splat(0))
26162+
if (Cond == ISD::SETNE && isZerosVector(RHS.getNode()) &&
26163+
LHS->getOpcode() == ISD::INSERT_SUBVECTOR && LHS.hasOneUse()) {
26164+
SDValue L0 = LHS->getOperand(0);
26165+
SDValue L1 = LHS->getOperand(1);
26166+
SDValue L2 = LHS->getOperand(2);
26167+
26168+
if (L0.getOpcode() == ISD::UNDEF && isNullConstant(L2) &&
26169+
isSignExtInReg(L1)) {
26170+
SDLoc DL(N);
26171+
SDValue Shl = L1.getOperand(0);
26172+
SDValue NewLHS = DAG.getNode(ISD::INSERT_SUBVECTOR, DL,
26173+
LHS.getValueType(), L0, Shl, L2);
26174+
return DAG.getNode(AArch64ISD::SETCC_MERGE_ZERO, DL, N->getValueType(0),
26175+
Pred, NewLHS, RHS, N->getOperand(3));
26176+
}
26177+
}
26178+
2614726179
return SDValue();
2614826180
}
2614926181

0 commit comments

Comments
 (0)