|
18 | 18 | #include "AMDGPUMachineFunction.h" |
19 | 19 | #include "AMDGPUMemoryUtils.h" |
20 | 20 | #include "SIMachineFunctionInfo.h" |
| 21 | +#include "SIRegisterInfo.h" |
21 | 22 | #include "llvm/CodeGen/Analysis.h" |
22 | 23 | #include "llvm/CodeGen/GlobalISel/GISelValueTracking.h" |
23 | 24 | #include "llvm/CodeGen/MachineFrameInfo.h" |
@@ -5292,15 +5293,20 @@ SDValue AMDGPUTargetLowering::expandABS(SDNode *N, SelectionDAG &CurDAG, |
5292 | 5293 | assert(N->getOpcode() == ISD::ABS && |
5293 | 5294 | "Tried to select abs with non-abs opcode."); |
5294 | 5295 |
|
5295 | | - if (N->getValueSizeInBits(0) != 16 || IsNegative) |
| 5296 | + if (N->getValueSizeInBits(0) != 16 || getRegClassFor(N->getSimpleValueType(0)) != &AMDGPU::SReg_32RegClass) |
5296 | 5297 | return TargetLowering::expandABS(N, CurDAG, IsNegative); |
5297 | 5298 |
|
5298 | 5299 | SDValue Src = N->getOperand(0); |
5299 | 5300 | SDLoc DL(Src); |
5300 | 5301 |
|
5301 | 5302 | SDValue SExtSrc = CurDAG.getSExtOrTrunc(Src, DL, MVT::i32); |
5302 | 5303 | SDValue ExtAbs = CurDAG.getNode(ISD::ABS, DL, MVT::i32, SExtSrc); |
5303 | | - return CurDAG.getNode(ISD::TRUNCATE, DL, MVT::i16, ExtAbs); |
| 5304 | + SDValue TruncResult = CurDAG.getNode(ISD::TRUNCATE, DL, MVT::i16, ExtAbs); |
| 5305 | + |
| 5306 | + if (!IsNegative) |
| 5307 | + return TruncResult; |
| 5308 | + return CurDAG.getNode(ISD::SUB, DL, MVT::i16, |
| 5309 | + CurDAG.getConstant(0, DL, MVT::i16), TruncResult); |
5304 | 5310 | } |
5305 | 5311 |
|
5306 | 5312 | SDValue AMDGPUTargetLowering::PerformDAGCombine(SDNode *N, |
|
0 commit comments