Skip to content

Commit 55de46f

Browse files
author
QingShan Zhang
committed
[PowerPC] Support constrained fp operation for setcc
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
1 parent 3359ea6 commit 55de46f

File tree

5 files changed

+2742
-9
lines changed

5 files changed

+2742
-9
lines changed

llvm/include/llvm/Target/TargetSelectionDAG.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,8 @@ def strict_sint_to_fp : SDNode<"ISD::STRICT_SINT_TO_FP",
553553
SDTIntToFPOp, [SDNPHasChain]>;
554554
def strict_uint_to_fp : SDNode<"ISD::STRICT_UINT_TO_FP",
555555
SDTIntToFPOp, [SDNPHasChain]>;
556+
def strict_fsetcc : SDNode<"ISD::STRICT_FSETCC", SDTSetCC, [SDNPHasChain]>;
557+
def strict_fsetccs : SDNode<"ISD::STRICT_FSETCCS", SDTSetCC, [SDNPHasChain]>;
556558

557559
def setcc : SDNode<"ISD::SETCC" , SDTSetCC>;
558560
def select : SDNode<"ISD::SELECT" , SDTSelect>;
@@ -1420,6 +1422,12 @@ def any_sint_to_fp : PatFrags<(ops node:$src),
14201422
def any_uint_to_fp : PatFrags<(ops node:$src),
14211423
[(strict_uint_to_fp node:$src),
14221424
(uint_to_fp node:$src)]>;
1425+
def any_fsetcc : PatFrags<(ops node:$lhs, node:$rhs, node:$pred),
1426+
[(strict_fsetcc node:$lhs, node:$rhs, node:$pred),
1427+
(setcc node:$lhs, node:$rhs, node:$pred)]>;
1428+
def any_fsetccs : PatFrags<(ops node:$lhs, node:$rhs, node:$pred),
1429+
[(strict_fsetccs node:$lhs, node:$rhs, node:$pred),
1430+
(setcc node:$lhs, node:$rhs, node:$pred)]>;
14231431

14241432
multiclass binary_atomic_op_ord<SDNode atomic_op> {
14251433
def NAME#_monotonic : PatFrag<(ops node:$ptr, node:$val),

llvm/lib/Target/PowerPC/P9InstrResources.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def : InstRW<[P9_ALU_3C, IP_EXEC_1C, DISP_3SLOTS_1C],
9494
(instregex "CMPRB(8)?$"),
9595
(instregex "TD(I)?$"),
9696
(instregex "TW(I)?$"),
97-
(instregex "FCMPU(S|D)$"),
97+
(instregex "FCMP(O|U)(S|D)$"),
9898
(instregex "XSTSTDC(S|D)P$"),
9999
FTDIV,
100100
FTSQRT,

llvm/lib/Target/PowerPC/PPCISelLowering.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,16 @@ PPCTargetLowering::PPCTargetLowering(const PPCTargetMachine &TM,
419419
if (!Subtarget.useCRBits())
420420
setOperationAction(ISD::SETCC, MVT::i32, Custom);
421421

422+
if (Subtarget.hasFPU()) {
423+
setOperationAction(ISD::STRICT_FSETCC, MVT::f32, Legal);
424+
setOperationAction(ISD::STRICT_FSETCC, MVT::f64, Legal);
425+
setOperationAction(ISD::STRICT_FSETCC, MVT::f128, Legal);
426+
427+
setOperationAction(ISD::STRICT_FSETCCS, MVT::f32, Legal);
428+
setOperationAction(ISD::STRICT_FSETCCS, MVT::f64, Legal);
429+
setOperationAction(ISD::STRICT_FSETCCS, MVT::f128, Legal);
430+
}
431+
422432
// PowerPC does not have BRCOND which requires SetCC
423433
if (!Subtarget.useCRBits())
424434
setOperationAction(ISD::BRCOND, MVT::Other, Expand);

llvm/lib/Target/PowerPC/PPCInstrInfo.td

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2570,14 +2570,17 @@ let isCompare = 1, hasSideEffects = 0 in {
25702570
}
25712571
}
25722572
let PPC970_Unit = 3, Predicates = [HasFPU] in { // FPU Operations.
2573-
//def FCMPO : XForm_17<63, 32, (outs CRRC:$crD), (ins FPRC:$fA, FPRC:$fB),
2574-
// "fcmpo $crD, $fA, $fB", IIC_FPCompare>;
25752573
let isCompare = 1, hasSideEffects = 0 in {
25762574
def FCMPUS : XForm_17<63, 0, (outs crrc:$crD), (ins f4rc:$fA, f4rc:$fB),
25772575
"fcmpu $crD, $fA, $fB", IIC_FPCompare>;
2578-
let Interpretation64Bit = 1, isCodeGenOnly = 1 in
2579-
def FCMPUD : XForm_17<63, 0, (outs crrc:$crD), (ins f8rc:$fA, f8rc:$fB),
2580-
"fcmpu $crD, $fA, $fB", IIC_FPCompare>;
2576+
def FCMPOS : XForm_17<63, 32, (outs crrc:$crD), (ins f4rc:$fA, f4rc:$fB),
2577+
"fcmpo $crD, $fA, $fB", IIC_FPCompare>;
2578+
let Interpretation64Bit = 1, isCodeGenOnly = 1 in {
2579+
def FCMPUD : XForm_17<63, 0, (outs crrc:$crD), (ins f8rc:$fA, f8rc:$fB),
2580+
"fcmpu $crD, $fA, $fB", IIC_FPCompare>;
2581+
def FCMPOD : XForm_17<63, 32, (outs crrc:$crD), (ins f8rc:$fA, f8rc:$fB),
2582+
"fcmpo $crD, $fA, $fB", IIC_FPCompare>;
2583+
}
25812584
}
25822585

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

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

39403944
// SETCC for f64.
3941-
defm : FSetCCPat<setcc, f64, FCMPUD>;
3945+
defm : FSetCCPat<any_fsetcc, f64, FCMPUD>;
39423946

39433947
// SETCC for f128.
3944-
defm : FSetCCPat<setcc, f128, XSCMPUQP>;
3948+
defm : FSetCCPat<any_fsetcc, f128, XSCMPUQP>;
3949+
3950+
// FCMPO: If either of the operands is a Signaling NaN, then VXSNAN is set and,
3951+
// if neither operand is a Signaling NaN but at least one operand is a Quiet NaN,
3952+
// then VXVC is set.
3953+
// SETCCS for f32.
3954+
defm : FSetCCPat<strict_fsetccs, f32, FCMPOS>;
3955+
3956+
// SETCCS for f64.
3957+
defm : FSetCCPat<strict_fsetccs, f64, FCMPOD>;
3958+
3959+
// SETCCS for f128.
3960+
defm : FSetCCPat<strict_fsetccs, f128, XSCMPOQP>;
39453961
}
39463962

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

0 commit comments

Comments
 (0)