Skip to content

Commit 6cfc5fd

Browse files
author
git apple-llvm automerger
committed
Merge commit '2887f1463930' from llvm.org/main into apple/main
2 parents bcfc4a6 + 2887f14 commit 6cfc5fd

File tree

8 files changed

+69
-63
lines changed

8 files changed

+69
-63
lines changed

llvm/include/llvm/CodeGen/ISDOpcodes.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,13 @@ enum NodeType {
615615
MULHU,
616616
MULHS,
617617

618+
// ABDS/ABDU - Absolute difference - Return the absolute difference between
619+
// two numbers interpreted as signed/unsigned.
620+
// i.e trunc(abs(sext(Op0) - sext(Op1))) becomes abds(Op0, Op1)
621+
// or trunc(abs(zext(Op0) - zext(Op1))) becomes abdu(Op0, Op1)
622+
ABDS,
623+
ABDU,
624+
618625
/// [US]{MIN/MAX} - Binary minimum or maximum of signed or unsigned
619626
/// integers.
620627
SMIN,

llvm/include/llvm/Target/TargetSelectionDAG.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,8 @@ def mul : SDNode<"ISD::MUL" , SDTIntBinOp,
369369
[SDNPCommutative, SDNPAssociative]>;
370370
def mulhs : SDNode<"ISD::MULHS" , SDTIntBinOp, [SDNPCommutative]>;
371371
def mulhu : SDNode<"ISD::MULHU" , SDTIntBinOp, [SDNPCommutative]>;
372+
def abds : SDNode<"ISD::ABDS" , SDTIntBinOp, [SDNPCommutative]>;
373+
def abdu : SDNode<"ISD::ABDU" , SDTIntBinOp, [SDNPCommutative]>;
372374
def smullohi : SDNode<"ISD::SMUL_LOHI" , SDTIntBinHiLoOp, [SDNPCommutative]>;
373375
def umullohi : SDNode<"ISD::UMUL_LOHI" , SDTIntBinHiLoOp, [SDNPCommutative]>;
374376
def sdiv : SDNode<"ISD::SDIV" , SDTIntBinOp>;

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9071,6 +9071,40 @@ SDValue DAGCombiner::visitFunnelShift(SDNode *N) {
90719071
return SDValue();
90729072
}
90739073

9074+
// Given a ABS node, detect the following pattern:
9075+
// (ABS (SUB (EXTEND a), (EXTEND b))).
9076+
// Generates UABD/SABD instruction.
9077+
static SDValue combineABSToABD(SDNode *N, SelectionDAG &DAG,
9078+
const TargetLowering &TLI) {
9079+
SDValue AbsOp1 = N->getOperand(0);
9080+
SDValue Op0, Op1;
9081+
9082+
if (AbsOp1.getOpcode() != ISD::SUB)
9083+
return SDValue();
9084+
9085+
Op0 = AbsOp1.getOperand(0);
9086+
Op1 = AbsOp1.getOperand(1);
9087+
9088+
unsigned Opc0 = Op0.getOpcode();
9089+
// Check if the operands of the sub are (zero|sign)-extended.
9090+
if (Opc0 != Op1.getOpcode() ||
9091+
(Opc0 != ISD::ZERO_EXTEND && Opc0 != ISD::SIGN_EXTEND))
9092+
return SDValue();
9093+
9094+
EVT VT1 = Op0.getOperand(0).getValueType();
9095+
EVT VT2 = Op1.getOperand(0).getValueType();
9096+
// Check if the operands are of same type and valid size.
9097+
unsigned ABDOpcode = (Opc0 == ISD::SIGN_EXTEND) ? ISD::ABDS : ISD::ABDU;
9098+
if (VT1 != VT2 || !TLI.isOperationLegalOrCustom(ABDOpcode, VT1))
9099+
return SDValue();
9100+
9101+
Op0 = Op0.getOperand(0);
9102+
Op1 = Op1.getOperand(0);
9103+
SDValue ABD =
9104+
DAG.getNode(ABDOpcode, SDLoc(N), Op0->getValueType(0), Op0, Op1);
9105+
return DAG.getNode(ISD::ZERO_EXTEND, SDLoc(N), N->getValueType(0), ABD);
9106+
}
9107+
90749108
SDValue DAGCombiner::visitABS(SDNode *N) {
90759109
SDValue N0 = N->getOperand(0);
90769110
EVT VT = N->getValueType(0);
@@ -9084,6 +9118,10 @@ SDValue DAGCombiner::visitABS(SDNode *N) {
90849118
// fold (abs x) -> x iff not-negative
90859119
if (DAG.SignBitIsZero(N0))
90869120
return N0;
9121+
9122+
if (SDValue ABD = combineABSToABD(N, DAG, TLI))
9123+
return ABD;
9124+
90879125
return SDValue();
90889126
}
90899127

llvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ std::string SDNode::getOperationName(const SelectionDAG *G) const {
232232
case ISD::MUL: return "mul";
233233
case ISD::MULHU: return "mulhu";
234234
case ISD::MULHS: return "mulhs";
235+
case ISD::ABDS: return "abds";
236+
case ISD::ABDU: return "abdu";
235237
case ISD::SDIV: return "sdiv";
236238
case ISD::UDIV: return "udiv";
237239
case ISD::SREM: return "srem";

llvm/lib/CodeGen/TargetLoweringBase.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,10 @@ void TargetLoweringBase::initActions() {
813813
setOperationAction(ISD::SUBC, VT, Expand);
814814
setOperationAction(ISD::SUBE, VT, Expand);
815815

816+
// Absolute difference
817+
setOperationAction(ISD::ABDS, VT, Expand);
818+
setOperationAction(ISD::ABDU, VT, Expand);
819+
816820
// These default to Expand so they will be expanded to CTLZ/CTTZ by default.
817821
setOperationAction(ISD::CTLZ_ZERO_UNDEF, VT, Expand);
818822
setOperationAction(ISD::CTTZ_ZERO_UNDEF, VT, Expand);

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 14 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,6 +1056,12 @@ AArch64TargetLowering::AArch64TargetLowering(const TargetMachine &TM,
10561056
setOperationAction(ISD::USUBSAT, VT, Legal);
10571057
}
10581058

1059+
for (MVT VT : {MVT::v8i8, MVT::v4i16, MVT::v2i32, MVT::v16i8, MVT::v8i16,
1060+
MVT::v4i32}) {
1061+
setOperationAction(ISD::ABDS, VT, Legal);
1062+
setOperationAction(ISD::ABDU, VT, Legal);
1063+
}
1064+
10591065
// Vector reductions
10601066
for (MVT VT : { MVT::v4f16, MVT::v2f32,
10611067
MVT::v8f16, MVT::v4f32, MVT::v2f64 }) {
@@ -2124,8 +2130,6 @@ const char *AArch64TargetLowering::getTargetNodeName(unsigned Opcode) const {
21242130
MAKE_CASE(AArch64ISD::CTPOP_MERGE_PASSTHRU)
21252131
MAKE_CASE(AArch64ISD::DUP_MERGE_PASSTHRU)
21262132
MAKE_CASE(AArch64ISD::INDEX_VECTOR)
2127-
MAKE_CASE(AArch64ISD::UABD)
2128-
MAKE_CASE(AArch64ISD::SABD)
21292133
MAKE_CASE(AArch64ISD::UADDLP)
21302134
MAKE_CASE(AArch64ISD::CALL_RVMARKER)
21312135
}
@@ -4090,8 +4094,8 @@ SDValue AArch64TargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op,
40904094
}
40914095
case Intrinsic::aarch64_neon_sabd:
40924096
case Intrinsic::aarch64_neon_uabd: {
4093-
unsigned Opcode = IntNo == Intrinsic::aarch64_neon_uabd ? AArch64ISD::UABD
4094-
: AArch64ISD::SABD;
4097+
unsigned Opcode = IntNo == Intrinsic::aarch64_neon_uabd ? ISD::ABDU
4098+
: ISD::ABDS;
40954099
return DAG.getNode(Opcode, dl, Op.getValueType(), Op.getOperand(1),
40964100
Op.getOperand(2));
40974101
}
@@ -12297,8 +12301,8 @@ static SDValue performVecReduceAddCombineWithUADDLP(SDNode *N,
1229712301
SDValue UABDHigh8Op1 =
1229812302
DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, MVT::v8i8, EXT1->getOperand(0),
1229912303
DAG.getConstant(8, DL, MVT::i64));
12300-
SDValue UABDHigh8 = DAG.getNode(IsZExt ? AArch64ISD::UABD : AArch64ISD::SABD,
12301-
DL, MVT::v8i8, UABDHigh8Op0, UABDHigh8Op1);
12304+
SDValue UABDHigh8 = DAG.getNode(IsZExt ? ISD::ABDU : ISD::ABDS, DL, MVT::v8i8,
12305+
UABDHigh8Op0, UABDHigh8Op1);
1230212306
SDValue UABDL = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::v8i16, UABDHigh8);
1230312307

1230412308
// Second, create the node pattern of UABAL.
@@ -12308,8 +12312,8 @@ static SDValue performVecReduceAddCombineWithUADDLP(SDNode *N,
1230812312
SDValue UABDLo8Op1 =
1230912313
DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, MVT::v8i8, EXT1->getOperand(0),
1231012314
DAG.getConstant(0, DL, MVT::i64));
12311-
SDValue UABDLo8 = DAG.getNode(IsZExt ? AArch64ISD::UABD : AArch64ISD::SABD,
12312-
DL, MVT::v8i8, UABDLo8Op0, UABDLo8Op1);
12315+
SDValue UABDLo8 = DAG.getNode(IsZExt ? ISD::ABDU : ISD::ABDS, DL, MVT::v8i8,
12316+
UABDLo8Op0, UABDLo8Op1);
1231312317
SDValue ZExtUABD = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::v8i16, UABDLo8);
1231412318
SDValue UABAL = DAG.getNode(ISD::ADD, DL, MVT::v8i16, UABDL, ZExtUABD);
1231512319

@@ -12368,48 +12372,6 @@ static SDValue performVecReduceAddCombine(SDNode *N, SelectionDAG &DAG,
1236812372
return DAG.getNode(ISD::VECREDUCE_ADD, DL, N->getValueType(0), Dot);
1236912373
}
1237012374

12371-
// Given a ABS node, detect the following pattern:
12372-
// (ABS (SUB (EXTEND a), (EXTEND b))).
12373-
// Generates UABD/SABD instruction.
12374-
static SDValue performABSCombine(SDNode *N, SelectionDAG &DAG,
12375-
TargetLowering::DAGCombinerInfo &DCI,
12376-
const AArch64Subtarget *Subtarget) {
12377-
SDValue AbsOp1 = N->getOperand(0);
12378-
SDValue Op0, Op1;
12379-
12380-
if (AbsOp1.getOpcode() != ISD::SUB)
12381-
return SDValue();
12382-
12383-
Op0 = AbsOp1.getOperand(0);
12384-
Op1 = AbsOp1.getOperand(1);
12385-
12386-
unsigned Opc0 = Op0.getOpcode();
12387-
// Check if the operands of the sub are (zero|sign)-extended.
12388-
if (Opc0 != Op1.getOpcode() ||
12389-
(Opc0 != ISD::ZERO_EXTEND && Opc0 != ISD::SIGN_EXTEND))
12390-
return SDValue();
12391-
12392-
EVT VectorT1 = Op0.getOperand(0).getValueType();
12393-
EVT VectorT2 = Op1.getOperand(0).getValueType();
12394-
// Check if vectors are of same type and valid size.
12395-
uint64_t Size = VectorT1.getFixedSizeInBits();
12396-
if (VectorT1 != VectorT2 || (Size != 64 && Size != 128))
12397-
return SDValue();
12398-
12399-
// Check if vector element types are valid.
12400-
EVT VT1 = VectorT1.getVectorElementType();
12401-
if (VT1 != MVT::i8 && VT1 != MVT::i16 && VT1 != MVT::i32)
12402-
return SDValue();
12403-
12404-
Op0 = Op0.getOperand(0);
12405-
Op1 = Op1.getOperand(0);
12406-
unsigned ABDOpcode =
12407-
(Opc0 == ISD::SIGN_EXTEND) ? AArch64ISD::SABD : AArch64ISD::UABD;
12408-
SDValue ABD =
12409-
DAG.getNode(ABDOpcode, SDLoc(N), Op0->getValueType(0), Op0, Op1);
12410-
return DAG.getNode(ISD::ZERO_EXTEND, SDLoc(N), N->getValueType(0), ABD);
12411-
}
12412-
1241312375
static SDValue performXorCombine(SDNode *N, SelectionDAG &DAG,
1241412376
TargetLowering::DAGCombinerInfo &DCI,
1241512377
const AArch64Subtarget *Subtarget) {
@@ -14575,8 +14537,8 @@ static SDValue performExtendCombine(SDNode *N,
1457514537
// helps the backend to decide that an sabdl2 would be useful, saving a real
1457614538
// extract_high operation.
1457714539
if (!DCI.isBeforeLegalizeOps() && N->getOpcode() == ISD::ZERO_EXTEND &&
14578-
(N->getOperand(0).getOpcode() == AArch64ISD::UABD ||
14579-
N->getOperand(0).getOpcode() == AArch64ISD::SABD)) {
14540+
(N->getOperand(0).getOpcode() == ISD::ABDU ||
14541+
N->getOperand(0).getOpcode() == ISD::ABDS)) {
1458014542
SDNode *ABDNode = N->getOperand(0).getNode();
1458114543
SDValue NewABD =
1458214544
tryCombineLongOpWithDup(Intrinsic::not_intrinsic, ABDNode, DCI, DAG);
@@ -16542,8 +16504,6 @@ SDValue AArch64TargetLowering::PerformDAGCombine(SDNode *N,
1654216504
default:
1654316505
LLVM_DEBUG(dbgs() << "Custom combining: skipping\n");
1654416506
break;
16545-
case ISD::ABS:
16546-
return performABSCombine(N, DAG, DCI, Subtarget);
1654716507
case ISD::ADD:
1654816508
case ISD::SUB:
1654916509
return performAddSubCombine(N, DCI, DAG);

llvm/lib/Target/AArch64/AArch64ISelLowering.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,6 @@ enum NodeType : unsigned {
242242
SRHADD,
243243
URHADD,
244244

245-
// Absolute difference
246-
UABD,
247-
SABD,
248-
249245
// Unsigned Add Long Pairwise
250246
UADDLP,
251247

llvm/lib/Target/AArch64/AArch64InstrInfo.td

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -579,14 +579,11 @@ def AArch64urhadd : SDNode<"AArch64ISD::URHADD", SDT_AArch64binvec>;
579579
def AArch64shadd : SDNode<"AArch64ISD::SHADD", SDT_AArch64binvec>;
580580
def AArch64uhadd : SDNode<"AArch64ISD::UHADD", SDT_AArch64binvec>;
581581

582-
def AArch64uabd_n : SDNode<"AArch64ISD::UABD", SDT_AArch64binvec>;
583-
def AArch64sabd_n : SDNode<"AArch64ISD::SABD", SDT_AArch64binvec>;
584-
585582
def AArch64uabd : PatFrags<(ops node:$lhs, node:$rhs),
586-
[(AArch64uabd_n node:$lhs, node:$rhs),
583+
[(abdu node:$lhs, node:$rhs),
587584
(int_aarch64_neon_uabd node:$lhs, node:$rhs)]>;
588585
def AArch64sabd : PatFrags<(ops node:$lhs, node:$rhs),
589-
[(AArch64sabd_n node:$lhs, node:$rhs),
586+
[(abds node:$lhs, node:$rhs),
590587
(int_aarch64_neon_sabd node:$lhs, node:$rhs)]>;
591588

592589
def AArch64uaddlp_n : SDNode<"AArch64ISD::UADDLP", SDT_AArch64uaddlp>;

0 commit comments

Comments
 (0)