Skip to content

Commit 8469079

Browse files
committed
This doesn't work.
1 parent 26e0736 commit 8469079

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "AMDGPUMachineFunction.h"
1919
#include "AMDGPUMemoryUtils.h"
2020
#include "SIMachineFunctionInfo.h"
21+
#include "SIRegisterInfo.h"
2122
#include "llvm/CodeGen/Analysis.h"
2223
#include "llvm/CodeGen/GlobalISel/GISelValueTracking.h"
2324
#include "llvm/CodeGen/MachineFrameInfo.h"
@@ -5291,15 +5292,20 @@ SDValue AMDGPUTargetLowering::expandABS(SDNode *N, SelectionDAG &CurDAG,
52915292
assert(N->getOpcode() == ISD::ABS &&
52925293
"Tried to select abs with non-abs opcode.");
52935294

5294-
if (N->getValueSizeInBits(0) != 16 || IsNegative)
5295+
if (N->getValueSizeInBits(0) != 16 || getRegClassFor(N->getSimpleValueType(0)) != &AMDGPU::SReg_32RegClass)
52955296
return TargetLowering::expandABS(N, CurDAG, IsNegative);
52965297

52975298
SDValue Src = N->getOperand(0);
52985299
SDLoc DL(Src);
52995300

53005301
SDValue SExtSrc = CurDAG.getSExtOrTrunc(Src, DL, MVT::i32);
53015302
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);
53035309
}
53045310

53055311
SDValue AMDGPUTargetLowering::PerformDAGCombine(SDNode *N,
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
; RUN: llc -mtriple=amdgcn-- -mcpu=gfx900 < %s | FileCheck %s
2+
3+
define amdgpu_ps i16 @abs_i16(i16 inreg %arg) {
4+
; CHECK-LABEL: abs_i16:
5+
; CHECK: %bb.0:
6+
; CHECK-NEXT: s_sext_i32_i16 s0, s0
7+
; CHECK-NEXT: s_abs_i32 s0, s0
8+
9+
%res = call i16 @llvm.abs.i16(i16 %arg, i1 false)
10+
ret i16 %res
11+
}
12+
13+
define amdgpu_ps i16 @abs_i16_neg(i16 inreg %arg) {
14+
; CHECK-LABEL: abs_i16_neg:
15+
; CHECK: ; %bb.0:
16+
; CHECK-NEXT: s_sext_i32_i16 s0, s0
17+
; CHECK-NEXT: s_abs_i32 s0, s0
18+
; CHECK-NEXT: s_sub_i32 s0, 0, s0
19+
%res1 = call i16 @llvm.abs.i16(i16 %arg, i1 false)
20+
%res2 = sub i16 0, %res1
21+
ret i16 %res2
22+
}

0 commit comments

Comments
 (0)