Skip to content

Commit

Permalink
[PowerPC] Support constrained fp operation for setcc
Browse files Browse the repository at this point in the history
The constrained fp operation fcmp was added by https://reviews.llvm.org/D69281.
This patch is trying to add the support for PowerPC backend.

Reviewed By: uweigand

Differential Revision: https://reviews.llvm.org/D81727
  • Loading branch information
QingShan Zhang committed Aug 7, 2020
1 parent 3359ea6 commit 55de46f
Show file tree
Hide file tree
Showing 5 changed files with 2,742 additions and 9 deletions.
8 changes: 8 additions & 0 deletions llvm/include/llvm/Target/TargetSelectionDAG.td
Expand Up @@ -553,6 +553,8 @@ def strict_sint_to_fp : SDNode<"ISD::STRICT_SINT_TO_FP",
SDTIntToFPOp, [SDNPHasChain]>;
def strict_uint_to_fp : SDNode<"ISD::STRICT_UINT_TO_FP",
SDTIntToFPOp, [SDNPHasChain]>;
def strict_fsetcc : SDNode<"ISD::STRICT_FSETCC", SDTSetCC, [SDNPHasChain]>;
def strict_fsetccs : SDNode<"ISD::STRICT_FSETCCS", SDTSetCC, [SDNPHasChain]>;

def setcc : SDNode<"ISD::SETCC" , SDTSetCC>;
def select : SDNode<"ISD::SELECT" , SDTSelect>;
Expand Down Expand Up @@ -1420,6 +1422,12 @@ def any_sint_to_fp : PatFrags<(ops node:$src),
def any_uint_to_fp : PatFrags<(ops node:$src),
[(strict_uint_to_fp node:$src),
(uint_to_fp node:$src)]>;
def any_fsetcc : PatFrags<(ops node:$lhs, node:$rhs, node:$pred),
[(strict_fsetcc node:$lhs, node:$rhs, node:$pred),
(setcc node:$lhs, node:$rhs, node:$pred)]>;
def any_fsetccs : PatFrags<(ops node:$lhs, node:$rhs, node:$pred),
[(strict_fsetccs node:$lhs, node:$rhs, node:$pred),
(setcc node:$lhs, node:$rhs, node:$pred)]>;

multiclass binary_atomic_op_ord<SDNode atomic_op> {
def NAME#_monotonic : PatFrag<(ops node:$ptr, node:$val),
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/PowerPC/P9InstrResources.td
Expand Up @@ -94,7 +94,7 @@ def : InstRW<[P9_ALU_3C, IP_EXEC_1C, DISP_3SLOTS_1C],
(instregex "CMPRB(8)?$"),
(instregex "TD(I)?$"),
(instregex "TW(I)?$"),
(instregex "FCMPU(S|D)$"),
(instregex "FCMP(O|U)(S|D)$"),
(instregex "XSTSTDC(S|D)P$"),
FTDIV,
FTSQRT,
Expand Down
10 changes: 10 additions & 0 deletions llvm/lib/Target/PowerPC/PPCISelLowering.cpp
Expand Up @@ -419,6 +419,16 @@ PPCTargetLowering::PPCTargetLowering(const PPCTargetMachine &TM,
if (!Subtarget.useCRBits())
setOperationAction(ISD::SETCC, MVT::i32, Custom);

if (Subtarget.hasFPU()) {
setOperationAction(ISD::STRICT_FSETCC, MVT::f32, Legal);
setOperationAction(ISD::STRICT_FSETCC, MVT::f64, Legal);
setOperationAction(ISD::STRICT_FSETCC, MVT::f128, Legal);

setOperationAction(ISD::STRICT_FSETCCS, MVT::f32, Legal);
setOperationAction(ISD::STRICT_FSETCCS, MVT::f64, Legal);
setOperationAction(ISD::STRICT_FSETCCS, MVT::f128, Legal);
}

// PowerPC does not have BRCOND which requires SetCC
if (!Subtarget.useCRBits())
setOperationAction(ISD::BRCOND, MVT::Other, Expand);
Expand Down
32 changes: 24 additions & 8 deletions llvm/lib/Target/PowerPC/PPCInstrInfo.td
Expand Up @@ -2570,14 +2570,17 @@ let isCompare = 1, hasSideEffects = 0 in {
}
}
let PPC970_Unit = 3, Predicates = [HasFPU] in { // FPU Operations.
//def FCMPO : XForm_17<63, 32, (outs CRRC:$crD), (ins FPRC:$fA, FPRC:$fB),
// "fcmpo $crD, $fA, $fB", IIC_FPCompare>;
let isCompare = 1, hasSideEffects = 0 in {
def FCMPUS : XForm_17<63, 0, (outs crrc:$crD), (ins f4rc:$fA, f4rc:$fB),
"fcmpu $crD, $fA, $fB", IIC_FPCompare>;
let Interpretation64Bit = 1, isCodeGenOnly = 1 in
def FCMPUD : XForm_17<63, 0, (outs crrc:$crD), (ins f8rc:$fA, f8rc:$fB),
"fcmpu $crD, $fA, $fB", IIC_FPCompare>;
def FCMPOS : XForm_17<63, 32, (outs crrc:$crD), (ins f4rc:$fA, f4rc:$fB),
"fcmpo $crD, $fA, $fB", IIC_FPCompare>;
let Interpretation64Bit = 1, isCodeGenOnly = 1 in {
def FCMPUD : XForm_17<63, 0, (outs crrc:$crD), (ins f8rc:$fA, f8rc:$fB),
"fcmpu $crD, $fA, $fB", IIC_FPCompare>;
def FCMPOD : XForm_17<63, 32, (outs crrc:$crD), (ins f8rc:$fA, f8rc:$fB),
"fcmpo $crD, $fA, $fB", IIC_FPCompare>;
}
}

def FTDIV: XForm_17<63, 128, (outs crrc:$crD), (ins f8rc:$fA, f8rc:$fB),
Expand Down Expand Up @@ -3934,14 +3937,27 @@ multiclass FSetCCPat<SDNode SetCC, ValueType Ty, PatLeaf FCmp> {
}

let Predicates = [HasFPU] in {
// FCMPU: If either of the operands is a Signaling NaN, then VXSNAN is set.
// SETCC for f32.
defm : FSetCCPat<setcc, f32, FCMPUS>;
defm : FSetCCPat<any_fsetcc, f32, FCMPUS>;

// SETCC for f64.
defm : FSetCCPat<setcc, f64, FCMPUD>;
defm : FSetCCPat<any_fsetcc, f64, FCMPUD>;

// SETCC for f128.
defm : FSetCCPat<setcc, f128, XSCMPUQP>;
defm : FSetCCPat<any_fsetcc, f128, XSCMPUQP>;

// FCMPO: If either of the operands is a Signaling NaN, then VXSNAN is set and,
// if neither operand is a Signaling NaN but at least one operand is a Quiet NaN,
// then VXVC is set.
// SETCCS for f32.
defm : FSetCCPat<strict_fsetccs, f32, FCMPOS>;

// SETCCS for f64.
defm : FSetCCPat<strict_fsetccs, f64, FCMPOD>;

// SETCCS for f128.
defm : FSetCCPat<strict_fsetccs, f128, XSCMPOQP>;
}

// This must be in this file because it relies on patterns defined in this file
Expand Down

0 comments on commit 55de46f

Please sign in to comment.