@@ -181,7 +181,7 @@ SITargetLowering::SITargetLowering(const TargetMachine &TM,
181181
182182 // We don't want the default expansion of 16-bit ABS since we can
183183 // sign-extend and use the 32-bit ABS operation for 16-bit ABS with SGPRs
184- setOperationAction(ISD::ABS, MVT::i16, Custom);
184+ setOperationAction(ISD::ABS, { MVT::i8,MVT:: i16} , Custom);
185185 }
186186
187187 addRegisterClass(MVT::v32i32, &AMDGPU::VReg_1024RegClass);
@@ -979,7 +979,8 @@ SITargetLowering::SITargetLowering(const TargetMachine &TM,
979979 Custom);
980980 }
981981
982- setTargetDAGCombine({ISD::ADD,
982+ setTargetDAGCombine({ISD::ABS,
983+ ISD::ADD,
983984 ISD::PTRADD,
984985 ISD::UADDO_CARRY,
985986 ISD::SUB,
@@ -6779,7 +6780,7 @@ SDValue SITargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const {
67796780 case ISD::DEBUGTRAP:
67806781 return lowerDEBUGTRAP(Op, DAG);
67816782 case ISD::ABS:
6782- if (Op.getValueType() == MVT::i16)
6783+ if (Op.getValueType() == MVT::i16 || Op.getValueType() == MVT::i8 )
67836784 return lowerABSi16(Op, DAG);
67846785 LLVM_FALLTHROUGH;
67856786 case ISD::FABS:
@@ -7280,7 +7281,7 @@ static SDValue lowerLaneOp(const SITargetLowering &TLI, SDNode *N,
72807281void SITargetLowering::ReplaceNodeResults(SDNode *N,
72817282 SmallVectorImpl<SDValue> &Results,
72827283 SelectionDAG &DAG) const {
7283- switch (N->getOpcode()) {
7284+ switch (N->getOpcode()) {
72847285 case ISD::INSERT_VECTOR_ELT: {
72857286 if (SDValue Res = lowerINSERT_VECTOR_ELT(SDValue(N, 0), DAG))
72867287 Results.push_back(Res);
@@ -7458,6 +7459,15 @@ void SITargetLowering::ReplaceNodeResults(SDNode *N,
74587459 Results.push_back(lowerFSQRTF16(SDValue(N, 0), DAG));
74597460 break;
74607461 }
7462+ case ISD::ABS:
7463+ if (N->getValueType(0) == MVT::i16 || N->getValueType(0) == MVT::i8) {
7464+ SDValue result = lowerABSi16(SDValue(N, 0), DAG);
7465+ if(result!=SDValue()) {
7466+ Results.push_back(result);
7467+ return;
7468+ }
7469+ }
7470+ LLVM_FALLTHROUGH;
74617471 default:
74627472 AMDGPUTargetLowering::ReplaceNodeResults(N, Results, DAG);
74637473 break;
@@ -8151,7 +8161,7 @@ SDValue SITargetLowering::lowerDEBUGTRAP(SDValue Op, SelectionDAG &DAG) const {
81518161SDValue SITargetLowering::lowerABSi16(SDValue Op, SelectionDAG &DAG) const {
81528162 assert(Op.getOpcode() == ISD::ABS &&
81538163 "Tried to select abs with non-abs opcode.");
8154- assert(Op.getValueType() == MVT::i16 &&
8164+ assert(( Op.getValueType() == MVT::i16 || Op.getValueType() == MVT::i8) &&
81558165 "Tried to select abs i16 lowering with non-i16 type.");
81568166
81578167 // divergent means will not end up using SGPRs
@@ -8163,7 +8173,7 @@ SDValue SITargetLowering::lowerABSi16(SDValue Op, SelectionDAG &DAG) const {
81638173 SDLoc DL(Src);
81648174 SDValue SExtSrc = DAG.getSExtOrTrunc(Src, DL, MVT::i32);
81658175 SDValue ExtAbs = DAG.getNode(ISD::ABS, DL, MVT::i32, SExtSrc);
8166- return DAG.getNode(ISD::TRUNCATE, DL, MVT::i16 , ExtAbs);
8176+ return DAG.getNode(ISD::TRUNCATE, DL, Op.getValueType() , ExtAbs);
81678177}
81688178
81698179SDValue SITargetLowering::getSegmentAperture(unsigned AS, const SDLoc &DL,
@@ -16882,7 +16892,7 @@ SDValue SITargetLowering::PerformDAGCombine(SDNode *N,
1688216892 return SDValue();
1688316893
1688416894 switch (N->getOpcode()) {
16885- case ISD::ADD:
16895+ case ISD::ADD:
1688616896 return performAddCombine(N, DCI);
1688716897 case ISD::PTRADD:
1688816898 return performPtrAddCombine(N, DCI);
0 commit comments