|
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" |
@@ -5291,15 +5292,20 @@ SDValue AMDGPUTargetLowering::expandABS(SDNode *N, SelectionDAG &CurDAG, |
5291 | 5292 | assert(N->getOpcode() == ISD::ABS && |
5292 | 5293 | "Tried to select abs with non-abs opcode."); |
5293 | 5294 |
|
5294 | | - if (N->getValueSizeInBits(0) != 16 || IsNegative) |
| 5295 | + if (N->getValueSizeInBits(0) != 16 || getRegClassFor(N->getSimpleValueType(0)) != &AMDGPU::SReg_32RegClass) |
5295 | 5296 | return TargetLowering::expandABS(N, CurDAG, IsNegative); |
5296 | 5297 |
|
5297 | 5298 | SDValue Src = N->getOperand(0); |
5298 | 5299 | SDLoc DL(Src); |
5299 | 5300 |
|
5300 | 5301 | SDValue SExtSrc = CurDAG.getSExtOrTrunc(Src, DL, MVT::i32); |
5301 | 5302 | SDValue ExtAbs = CurDAG.getNode(ISD::ABS, DL, MVT::i32, SExtSrc); |
5302 | | - return CurDAG.getNode(ISD::TRUNCATE, DL, MVT::i16, ExtAbs); |
| 5303 | + SDValue TruncResult = CurDAG.getNode(ISD::TRUNCATE, DL, MVT::i16, ExtAbs); |
| 5304 | + |
| 5305 | + if (!IsNegative) |
| 5306 | + return TruncResult; |
| 5307 | + return CurDAG.getNode(ISD::SUB, DL, MVT::i16, |
| 5308 | + CurDAG.getConstant(0, DL, MVT::i16), TruncResult); |
5303 | 5309 | } |
5304 | 5310 |
|
5305 | 5311 | SDValue AMDGPUTargetLowering::PerformDAGCombine(SDNode *N, |
|
0 commit comments