Skip to content

Commit 5d98710

Browse files
authored
[SelectionDAG] Move VSelect sign pattern check from AArch64 to general SelectionDAG (#151840)
For some reason the check is already there, but it bails out. Doing the transform in SelDAG has no negative effect.
1 parent d20a3c0 commit 5d98710

3 files changed

Lines changed: 1010 additions & 32 deletions

File tree

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13957,8 +13957,13 @@ static SDValue combineVSelectWithAllOnesOrZeros(SDValue Cond, SDValue TVal,
1395713957
ISD::isConstantSplatVector(TVal.getNode(), TValAPInt) &&
1395813958
TValAPInt.isOne() &&
1395913959
ISD::isConstantSplatVectorAllOnes(Cond.getOperand(1).getNode()) &&
13960-
ISD::isConstantSplatVectorAllOnes(FVal.getNode())) {
13961-
return SDValue();
13960+
ISD::isConstantSplatVectorAllOnes(FVal.getNode()) &&
13961+
!TLI.shouldAvoidTransformToShift(VT, VT.getScalarSizeInBits() - 1)) {
13962+
SDValue LHS = Cond.getOperand(0);
13963+
SDValue ShiftC =
13964+
DAG.getShiftAmountConstant(VT.getScalarSizeInBits() - 1, VT, DL);
13965+
SDValue Shift = DAG.getNode(ISD::SRA, DL, VT, LHS, ShiftC);
13966+
return DAG.getNode(ISD::OR, DL, VT, Shift, TVal);
1396213967
}
1396313968

1396413969
// To use the condition operand as a bitwise mask, it must have elements that

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27977,37 +27977,7 @@ static SDValue performVSelectCombine(SDNode *N,
2797727977
}
2797827978
}
2797927979

27980-
// Check for sign pattern (VSELECT setgt, iN lhs, -1, 1, -1) and transform
27981-
// into (OR (ASR lhs, N-1), 1), which requires less instructions for the
27982-
// supported types.
2798327980
SDValue SetCC = N->getOperand(0);
27984-
if (SetCC.getOpcode() == ISD::SETCC &&
27985-
SetCC.getOperand(2) == DAG.getCondCode(ISD::SETGT)) {
27986-
SDValue CmpLHS = SetCC.getOperand(0);
27987-
EVT VT = CmpLHS.getValueType();
27988-
SDNode *CmpRHS = SetCC.getOperand(1).getNode();
27989-
SDNode *SplatLHS = N->getOperand(1).getNode();
27990-
SDNode *SplatRHS = N->getOperand(2).getNode();
27991-
APInt SplatLHSVal;
27992-
if (CmpLHS.getValueType() == N->getOperand(1).getValueType() &&
27993-
VT.isSimple() &&
27994-
is_contained(ArrayRef({MVT::v8i8, MVT::v16i8, MVT::v4i16, MVT::v8i16,
27995-
MVT::v2i32, MVT::v4i32, MVT::v2i64}),
27996-
VT.getSimpleVT().SimpleTy) &&
27997-
ISD::isConstantSplatVector(SplatLHS, SplatLHSVal) &&
27998-
SplatLHSVal.isOne() && ISD::isConstantSplatVectorAllOnes(CmpRHS) &&
27999-
ISD::isConstantSplatVectorAllOnes(SplatRHS)) {
28000-
unsigned NumElts = VT.getVectorNumElements();
28001-
SmallVector<SDValue, 8> Ops(
28002-
NumElts, DAG.getConstant(VT.getScalarSizeInBits() - 1, SDLoc(N),
28003-
VT.getScalarType()));
28004-
SDValue Val = DAG.getBuildVector(VT, SDLoc(N), Ops);
28005-
28006-
auto Shift = DAG.getNode(ISD::SRA, SDLoc(N), VT, CmpLHS, Val);
28007-
auto Or = DAG.getNode(ISD::OR, SDLoc(N), VT, Shift, N->getOperand(1));
28008-
return Or;
28009-
}
28010-
}
2801127981

2801227982
// Attempt to convert a (vXi1 bitcast(iX N0)) selection mask before it might
2801327983
// get split by legalization.

0 commit comments

Comments
 (0)