Skip to content

Commit 792eb13

Browse files
committed
[AArch64] Combine signext_inreg of setcc(... != splat(0))
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 96d5567 commit 792eb13

File tree

7 files changed

+167
-216
lines changed

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
@@ -26097,6 +26097,17 @@ static SDValue performSetCCPunpkCombine(SDNode *N, SelectionDAG &DAG) {
2609726097
return SDValue();
2609826098
}
2609926099

26100+
static bool isSignExtInReg(const SDValue &V) {
26101+
if (V.getOpcode() != AArch64ISD::VASHR ||
26102+
V.getOperand(0).getOpcode() != AArch64ISD::VSHL)
26103+
return false;
26104+
26105+
unsigned BitWidth = V->getValueType(0).getScalarSizeInBits();
26106+
unsigned ShiftAmtR = V.getConstantOperandVal(1);
26107+
unsigned ShiftAmtL = V.getOperand(0).getConstantOperandVal(1);
26108+
return (ShiftAmtR == ShiftAmtL && ShiftAmtR == (BitWidth - 1));
26109+
}
26110+
2610026111
static SDValue
2610126112
performSetccMergeZeroCombine(SDNode *N, TargetLowering::DAGCombinerInfo &DCI) {
2610226113
assert(N->getOpcode() == AArch64ISD::SETCC_MERGE_ZERO &&
@@ -26137,6 +26148,27 @@ performSetccMergeZeroCombine(SDNode *N, TargetLowering::DAGCombinerInfo &DCI) {
2613726148
LHS->getOperand(0), Pred);
2613826149
}
2613926150

26151+
// setcc_merge_zero(
26152+
// pred, insert_subvector(undef, signext_inreg(vNi1), 0), != splat(0))
26153+
// => setcc_merge_zero(
26154+
// pred, insert_subvector(undef, shl(vNi1), 0), != splat(0))
26155+
if (Cond == ISD::SETNE && isZerosVector(RHS.getNode()) &&
26156+
LHS->getOpcode() == ISD::INSERT_SUBVECTOR && LHS.hasOneUse()) {
26157+
SDValue L0 = LHS->getOperand(0);
26158+
SDValue L1 = LHS->getOperand(1);
26159+
SDValue L2 = LHS->getOperand(2);
26160+
26161+
if (L0.getOpcode() == ISD::UNDEF && isNullConstant(L2) &&
26162+
isSignExtInReg(L1)) {
26163+
SDLoc DL(N);
26164+
SDValue Shl = L1.getOperand(0);
26165+
SDValue NewLHS = DAG.getNode(ISD::INSERT_SUBVECTOR, DL,
26166+
LHS.getValueType(), L0, Shl, L2);
26167+
return DAG.getNode(AArch64ISD::SETCC_MERGE_ZERO, DL, N->getValueType(0),
26168+
Pred, NewLHS, RHS, N->getOperand(3));
26169+
}
26170+
}
26171+
2614026172
return SDValue();
2614126173
}
2614226174

0 commit comments

Comments
 (0)