Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions llvm/include/llvm/CodeGen/TargetLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -5576,8 +5576,8 @@ class LLVM_ABI TargetLowering : public TargetLoweringBase {
/// \param N Node to expand
/// \param IsNegative indicate negated abs
/// \returns The expansion result or SDValue() if it fails.
SDValue expandABS(SDNode *N, SelectionDAG &DAG,
bool IsNegative = false) const;
virtual SDValue expandABS(SDNode *N, SelectionDAG &DAG,
bool IsNegative = false) const;

/// Expand ABDS/ABDU nodes. Expands vector/scalar ABDS/ABDU nodes.
/// \param N Node to expand
Expand Down
21 changes: 21 additions & 0 deletions llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5287,6 +5287,27 @@ SDValue AMDGPUTargetLowering::performRcpCombine(SDNode *N,
return DCI.DAG.getConstantFP(One / Val, SDLoc(N), N->getValueType(0));
}

SDValue AMDGPUTargetLowering::expandABS(SDNode *N, SelectionDAG &DAG,
bool IsNegative) const {
if (N->isDivergent() ||
(N->getValueType(0) != MVT::i8 && N->getValueType(0) != MVT::i16))
return TargetLowering::expandABS(N, DAG, IsNegative);

//(abs i8/i16 (i8/i16 op1)) -> (trunc i8/i16 (abs i32 (sext i32 (i8/i16
// op1))))
SDValue Src = N->getOperand(0);
SDLoc DL(Src);
SDValue SExtSrc = DAG.getSExtOrTrunc(Src, DL, MVT::i32);
SDValue ExtAbs = DAG.getNode(ISD::ABS, DL, MVT::i32, SExtSrc);
SDValue TruncResult =
DAG.getNode(ISD::TRUNCATE, DL, N->getValueType(0), ExtAbs);

if (!IsNegative)
return TruncResult;

return DAG.getNegative(TruncResult, DL, N->getValueType(0));
}

SDValue AMDGPUTargetLowering::PerformDAGCombine(SDNode *N,
DAGCombinerInfo &DCI) const {
SelectionDAG &DAG = DCI.DAG;
Expand Down
3 changes: 3 additions & 0 deletions llvm/lib/Target/AMDGPU/AMDGPUISelLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ class AMDGPUTargetLowering : public TargetLowering {
/// original size will not change the value.
static unsigned numBitsSigned(SDValue Op, SelectionDAG &DAG);

virtual SDValue expandABS(SDNode *N, SelectionDAG &DAG,
bool IsNegative = false) const override;

protected:
SDValue LowerEXTRACT_SUBVECTOR(SDValue Op, SelectionDAG &DAG) const;
SDValue LowerCONCAT_VECTORS(SDValue Op, SelectionDAG &DAG) const;
Expand Down
Loading