Skip to content

Commit 26e0736

Browse files
committed
Finally something that works
1 parent 104fcb1 commit 26e0736

File tree

6 files changed

+22
-7
lines changed

6 files changed

+22
-7
lines changed

llvm/include/llvm/CodeGen/TargetLowering.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5580,8 +5580,8 @@ class LLVM_ABI TargetLowering : public TargetLoweringBase {
55805580
/// \param N Node to expand
55815581
/// \param IsNegative indicate negated abs
55825582
/// \returns The expansion result or SDValue() if it fails.
5583-
SDValue expandABS(SDNode *N, SelectionDAG &DAG,
5584-
bool IsNegative = false) const;
5583+
virtual SDValue expandABS(SDNode *N, SelectionDAG &DAG,
5584+
bool IsNegative = false) const;
55855585

55865586
/// Expand ABDS/ABDU nodes. Expands vector/scalar ABDS/ABDU nodes.
55875587
/// \param N Node to expand

llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "SIMachineFunctionInfo.h"
2424
#include "llvm/Analysis/UniformityAnalysis.h"
2525
#include "llvm/CodeGen/FunctionLoweringInfo.h"
26+
#include "llvm/CodeGen/ISDOpcodes.h"
2627
#include "llvm/CodeGen/SelectionDAG.h"
2728
#include "llvm/CodeGen/SelectionDAGISel.h"
2829
#include "llvm/CodeGen/SelectionDAGNodes.h"

llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ class AMDGPUDAGToDAGISel : public SelectionDAGISel {
282282
void SelectADD_SUB_I64(SDNode *N);
283283
void SelectAddcSubb(SDNode *N);
284284
void SelectUADDO_USUBO(SDNode *N);
285+
bool SelectABS(SDNode *N);
285286
void SelectDIV_SCALE(SDNode *N);
286287
void SelectMAD_64_32(SDNode *N);
287288
void SelectMUL_LOHI(SDNode *N);

llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5286,6 +5286,22 @@ SDValue AMDGPUTargetLowering::performRcpCombine(SDNode *N,
52865286
return DCI.DAG.getConstantFP(One / Val, SDLoc(N), N->getValueType(0));
52875287
}
52885288

5289+
SDValue AMDGPUTargetLowering::expandABS(SDNode *N, SelectionDAG &CurDAG,
5290+
bool IsNegative) const {
5291+
assert(N->getOpcode() == ISD::ABS &&
5292+
"Tried to select abs with non-abs opcode.");
5293+
5294+
if (N->getValueSizeInBits(0) != 16 || IsNegative)
5295+
return TargetLowering::expandABS(N, CurDAG, IsNegative);
5296+
5297+
SDValue Src = N->getOperand(0);
5298+
SDLoc DL(Src);
5299+
5300+
SDValue SExtSrc = CurDAG.getSExtOrTrunc(Src, DL, MVT::i32);
5301+
SDValue ExtAbs = CurDAG.getNode(ISD::ABS, DL, MVT::i32, SExtSrc);
5302+
return CurDAG.getNode(ISD::TRUNCATE, DL, MVT::i16, ExtAbs);
5303+
}
5304+
52895305
SDValue AMDGPUTargetLowering::PerformDAGCombine(SDNode *N,
52905306
DAGCombinerInfo &DCI) const {
52915307
SelectionDAG &DAG = DCI.DAG;

llvm/lib/Target/AMDGPU/AMDGPUISelLowering.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ class AMDGPUTargetLowering : public TargetLowering {
135135
SDValue performFNegCombine(SDNode *N, DAGCombinerInfo &DCI) const;
136136
SDValue performFAbsCombine(SDNode *N, DAGCombinerInfo &DCI) const;
137137
SDValue performRcpCombine(SDNode *N, DAGCombinerInfo &DCI) const;
138+
virtual SDValue expandABS(SDNode *N, SelectionDAG &CurDAG,
139+
bool IsNegative) const override;
138140

139141
static EVT getEquivalentMemType(LLVMContext &Context, EVT VT);
140142

llvm/lib/Target/AMDGPU/SOPInstructions.td

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1895,11 +1895,6 @@ def : GCNPat <
18951895
(S_MOV_B32 imm:$imm)
18961896
>;
18971897

1898-
def : GCNPat <
1899-
(i32 (UniformUnaryFrag<anyext> (i16 (UniformBinFrag<smax> i16:$src, (i16 (UniformBinFrag<sub> 0, i16:$src)))))),
1900-
(S_ABS_I32 (i32 (S_SEXT_I32_I16 $src)))
1901-
>;
1902-
19031898
def : GCNPat <
19041899
(v2i32 (UniformBinFrag<and> v2i32:$x, v2i32:$y)),
19051900
(S_AND_B64 SReg_64:$x, SReg_64:$y)

0 commit comments

Comments
 (0)