Skip to content

Commit fd0aeaa

Browse files
koachanbrad0
authored andcommitted
[SPARC] Don't emit deprecated FP branches when targeting v9
Don't emit deprecated v8-style FP compares & branches when targeting v9 processors. For now, always use %fcc0, because currently the allocator requires allocatable registers to also be spillable, which isn't the case with v9 FCC registers. The work to enable allocation over the entire FCC register file will be done in a future patch. Fixes bug #17834 Reviewed By: arsenm Differential Revision: https://reviews.llvm.org/D135515
1 parent 586d5f9 commit fd0aeaa

File tree

5 files changed

+72
-23
lines changed

5 files changed

+72
-23
lines changed

llvm/lib/Target/Sparc/SparcISelLowering.cpp

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1927,12 +1927,16 @@ const char *SparcTargetLowering::getTargetNodeName(unsigned Opcode) const {
19271927
case SPISD::FIRST_NUMBER: break;
19281928
case SPISD::CMPICC: return "SPISD::CMPICC";
19291929
case SPISD::CMPFCC: return "SPISD::CMPFCC";
1930+
case SPISD::CMPFCC_V9:
1931+
return "SPISD::CMPFCC_V9";
19301932
case SPISD::BRICC: return "SPISD::BRICC";
19311933
case SPISD::BPICC:
19321934
return "SPISD::BPICC";
19331935
case SPISD::BPXCC:
19341936
return "SPISD::BPXCC";
19351937
case SPISD::BRFCC: return "SPISD::BRFCC";
1938+
case SPISD::BRFCC_V9:
1939+
return "SPISD::BRFCC_V9";
19361940
case SPISD::SELECT_ICC: return "SPISD::SELECT_ICC";
19371941
case SPISD::SELECT_XCC: return "SPISD::SELECT_XCC";
19381942
case SPISD::SELECT_FCC: return "SPISD::SELECT_FCC";
@@ -1992,15 +1996,14 @@ void SparcTargetLowering::computeKnownBitsForTargetNode
19921996
// set LHS/RHS and SPCC to the LHS/RHS of the setcc and SPCC to the condition.
19931997
static void LookThroughSetCC(SDValue &LHS, SDValue &RHS,
19941998
ISD::CondCode CC, unsigned &SPCC) {
1995-
if (isNullConstant(RHS) &&
1996-
CC == ISD::SETNE &&
1999+
if (isNullConstant(RHS) && CC == ISD::SETNE &&
19972000
(((LHS.getOpcode() == SPISD::SELECT_ICC ||
19982001
LHS.getOpcode() == SPISD::SELECT_XCC) &&
19992002
LHS.getOperand(3).getOpcode() == SPISD::CMPICC) ||
20002003
(LHS.getOpcode() == SPISD::SELECT_FCC &&
2001-
LHS.getOperand(3).getOpcode() == SPISD::CMPFCC)) &&
2002-
isOneConstant(LHS.getOperand(0)) &&
2003-
isNullConstant(LHS.getOperand(1))) {
2004+
(LHS.getOperand(3).getOpcode() == SPISD::CMPFCC ||
2005+
LHS.getOperand(3).getOpcode() == SPISD::CMPFCC_V9))) &&
2006+
isOneConstant(LHS.getOperand(0)) && isNullConstant(LHS.getOperand(1))) {
20042007
SDValue CMPCC = LHS.getOperand(3);
20052008
SPCC = cast<ConstantSDNode>(LHS.getOperand(2))->getZExtValue();
20062009
LHS = CMPCC.getOperand(0);
@@ -2567,18 +2570,19 @@ static SDValue LowerBR_CC(SDValue Op, SelectionDAG &DAG,
25672570
CompareFlag = TLI.LowerF128Compare(LHS, RHS, SPCC, dl, DAG);
25682571
Opc = isV9 ? SPISD::BPICC : SPISD::BRICC;
25692572
} else {
2570-
CompareFlag = DAG.getNode(SPISD::CMPFCC, dl, MVT::Glue, LHS, RHS);
2573+
unsigned CmpOpc = isV9 ? SPISD::CMPFCC_V9 : SPISD::CMPFCC;
2574+
CompareFlag = DAG.getNode(CmpOpc, dl, MVT::Glue, LHS, RHS);
25712575
if (SPCC == ~0U) SPCC = FPCondCCodeToFCC(CC);
2572-
Opc = SPISD::BRFCC;
2576+
Opc = isV9 ? SPISD::BRFCC_V9 : SPISD::BRFCC;
25732577
}
25742578
}
25752579
return DAG.getNode(Opc, dl, MVT::Other, Chain, Dest,
25762580
DAG.getConstant(SPCC, dl, MVT::i32), CompareFlag);
25772581
}
25782582

25792583
static SDValue LowerSELECT_CC(SDValue Op, SelectionDAG &DAG,
2580-
const SparcTargetLowering &TLI,
2581-
bool hasHardQuad) {
2584+
const SparcTargetLowering &TLI, bool hasHardQuad,
2585+
bool isV9) {
25822586
SDValue LHS = Op.getOperand(0);
25832587
SDValue RHS = Op.getOperand(1);
25842588
ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(4))->get();
@@ -2603,7 +2607,8 @@ static SDValue LowerSELECT_CC(SDValue Op, SelectionDAG &DAG,
26032607
CompareFlag = TLI.LowerF128Compare(LHS, RHS, SPCC, dl, DAG);
26042608
Opc = SPISD::SELECT_ICC;
26052609
} else {
2606-
CompareFlag = DAG.getNode(SPISD::CMPFCC, dl, MVT::Glue, LHS, RHS);
2610+
unsigned CmpOpc = isV9 ? SPISD::CMPFCC_V9 : SPISD::CMPFCC;
2611+
CompareFlag = DAG.getNode(CmpOpc, dl, MVT::Glue, LHS, RHS);
26072612
Opc = SPISD::SELECT_FCC;
26082613
if (SPCC == ~0U) SPCC = FPCondCCodeToFCC(CC);
26092614
}
@@ -3150,8 +3155,8 @@ LowerOperation(SDValue Op, SelectionDAG &DAG) const {
31503155
hasHardQuad);
31513156
case ISD::BR_CC:
31523157
return LowerBR_CC(Op, DAG, *this, hasHardQuad, isV9);
3153-
case ISD::SELECT_CC: return LowerSELECT_CC(Op, DAG, *this,
3154-
hasHardQuad);
3158+
case ISD::SELECT_CC:
3159+
return LowerSELECT_CC(Op, DAG, *this, hasHardQuad, isV9);
31553160
case ISD::VASTART: return LowerVASTART(Op, DAG, *this);
31563161
case ISD::VAARG: return LowerVAARG(Op, DAG);
31573162
case ISD::DYNAMIC_STACKALLOC: return LowerDYNAMIC_STACKALLOC(Op, DAG,
@@ -3240,6 +3245,8 @@ SparcTargetLowering::EmitInstrWithCustomInserter(MachineInstr &MI,
32403245
case SP::SELECT_CC_FP_FCC:
32413246
case SP::SELECT_CC_DFP_FCC:
32423247
case SP::SELECT_CC_QFP_FCC:
3248+
if (Subtarget->isV9())
3249+
return expandSelectCC(MI, BB, SP::FBCOND_V9);
32433250
return expandSelectCC(MI, BB, SP::FBCOND);
32443251
}
32453252
}

llvm/lib/Target/Sparc/SparcISelLowering.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ namespace llvm {
2323
namespace SPISD {
2424
enum NodeType : unsigned {
2525
FIRST_NUMBER = ISD::BUILTIN_OP_END,
26-
CMPICC, // Compare two GPR operands, set icc+xcc.
27-
CMPFCC, // Compare two FP operands, set fcc.
28-
BRICC, // Branch to dest on icc condition
29-
BPICC, // Branch to dest on icc condition, with prediction (64-bit only).
30-
BPXCC, // Branch to dest on xcc condition, with prediction (64-bit only).
31-
BRFCC, // Branch to dest on fcc condition
26+
CMPICC, // Compare two GPR operands, set icc+xcc.
27+
CMPFCC, // Compare two FP operands, set fcc.
28+
CMPFCC_V9, // Compare two FP operands, set fcc (v9 variant).
29+
BRICC, // Branch to dest on icc condition
30+
BPICC, // Branch to dest on icc condition, with prediction (64-bit only).
31+
BPXCC, // Branch to dest on xcc condition, with prediction (64-bit only).
32+
BRFCC, // Branch to dest on fcc condition
33+
BRFCC_V9, // Branch to dest on fcc condition (v9 variant).
3234
SELECT_ICC, // Select between two values using the current ICC flags.
3335
SELECT_XCC, // Select between two values using the current XCC flags.
3436
SELECT_FCC, // Select between two values using the current FCC flags.

llvm/lib/Target/Sparc/SparcInstrInfo.td

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,12 @@ SDTypeProfile<1, 2, [SDTCisPtrTy<0>, SDTCisPtrTy<1>]>;
241241

242242
def SPcmpicc : SDNode<"SPISD::CMPICC", SDTSPcmpicc, [SDNPOutGlue]>;
243243
def SPcmpfcc : SDNode<"SPISD::CMPFCC", SDTSPcmpfcc, [SDNPOutGlue]>;
244+
def SPcmpfccv9 : SDNode<"SPISD::CMPFCC_V9", SDTSPcmpfcc, [SDNPOutGlue]>;
244245
def SPbricc : SDNode<"SPISD::BRICC", SDTSPbrcc, [SDNPHasChain, SDNPInGlue]>;
245246
def SPbpicc : SDNode<"SPISD::BPICC", SDTSPbrcc, [SDNPHasChain, SDNPInGlue]>;
246247
def SPbpxcc : SDNode<"SPISD::BPXCC", SDTSPbrcc, [SDNPHasChain, SDNPInGlue]>;
247248
def SPbrfcc : SDNode<"SPISD::BRFCC", SDTSPbrcc, [SDNPHasChain, SDNPInGlue]>;
249+
def SPbrfccv9 : SDNode<"SPISD::BRFCC_V9", SDTSPbrcc, [SDNPHasChain, SDNPInGlue]>;
248250

249251
def SPhi : SDNode<"SPISD::Hi", SDTIntUnaryOp>;
250252
def SPlo : SDNode<"SPISD::Lo", SDTIntUnaryOp>;
@@ -962,6 +964,19 @@ let Uses = [FCC0] in {
962964
"fb$cond,a $imm22", []>;
963965
}
964966

967+
// Variants of FBCOND that uses V9 opcode
968+
let Predicates = [HasV9], Uses = [FCC0], cc = 0,
969+
isBranch = 1, isTerminator = 1, hasDelaySlot = 1 in {
970+
def FBCOND_V9 : F2_3<0b101, 0, 1, (outs),
971+
(ins bprtarget:$imm19, CCOp:$cond),
972+
"fb$cond %fcc0, $imm19",
973+
[(SPbrfccv9 bb:$imm19, imm:$cond)], IIC_fpu_normal_instr>;
974+
def FBCONDA_V9 : F2_3<0b101, 1, 1, (outs),
975+
(ins bprtarget:$imm19, CCOp:$cond),
976+
"fb$cond,a %fcc0, $imm19",
977+
[(SPbrfccv9 bb:$imm19, imm:$cond)], IIC_fpu_normal_instr>;
978+
}
979+
965980
let Predicates = [HasV9] in
966981
defm BPF : FPredBranch;
967982

@@ -1408,6 +1423,31 @@ let Defs = [FCC0], rd = 0, isCodeGenOnly = 1 in {
14081423
Requires<[HasHardQuad]>;
14091424
}
14101425

1426+
// A.13 Floating-Point Compare (SPARC v9)
1427+
// Note that these always write to %fcc0 instead of having its destination
1428+
// allocated automatically.
1429+
// This avoids complications with the scheduler sometimes wanting to spill
1430+
// the contents of an FCC, since SPARC v9 doesn't have facilities to spill
1431+
// an individual FCC.
1432+
1433+
let Predicates = [HasV9], Defs = [FCC0], rd = 0, isCodeGenOnly = 1 in {
1434+
def FCMPS_V9 : F3_3c<2, 0b110101, 0b001010001,
1435+
(outs), (ins FPRegs:$rs1, FPRegs:$rs2),
1436+
"fcmps %fcc0, $rs1, $rs2",
1437+
[(SPcmpfccv9 f32:$rs1, f32:$rs2)],
1438+
IIC_fpu_fast_instr>;
1439+
def FCMPD_V9 : F3_3c<2, 0b110101, 0b001010010,
1440+
(outs), (ins DFPRegs:$rs1, DFPRegs:$rs2),
1441+
"fcmpd %fcc0, $rs1, $rs2",
1442+
[(SPcmpfccv9 f64:$rs1, f64:$rs2)],
1443+
IIC_fpu_fast_instr>;
1444+
def FCMPQ_V9 : F3_3c<2, 0b110101, 0b001010011,
1445+
(outs), (ins QFPRegs:$rs1, QFPRegs:$rs2),
1446+
"fcmpq %fcc0, $rs1, $rs2",
1447+
[(SPcmpfccv9 f128:$rs1, f128:$rs2)]>,
1448+
Requires<[HasHardQuad]>;
1449+
}
1450+
14111451
//===----------------------------------------------------------------------===//
14121452
// Instructions for Thread Local Storage(TLS).
14131453
//===----------------------------------------------------------------------===//

llvm/test/CodeGen/SPARC/2011-01-11-CC.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,10 @@ entry:
118118
; V8: {{fbule|fbg}} .LBB
119119

120120
; V9-LABEL: test_float_cc
121-
; V9: fcmpd
122-
; V9: {{fbl|fbuge}} .LBB
123-
; V9: fcmpd
124-
; V9: {{fbule|fbg}} .LBB
121+
; V9: fcmpd %fcc0
122+
; V9: {{fbl|fbuge}} %fcc0, .LBB
123+
; V9: fcmpd %fcc0
124+
; V9: {{fbule|fbg}} %fcc0, .LBB
125125

126126
%0 = fcmp uge double %a, 0.000000e+00
127127
br i1 %0, label %loop, label %loop.2

llvm/test/CodeGen/SPARC/64cond.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ entry:
6868

6969
; CHECK: selecti64_fcc
7070
; CHECK: mov %i3, %i0
71-
; CHECK: fcmps %f1, %f3
71+
; CHECK: fcmps %fcc0, %f1, %f3
7272
; CHECK: movul %fcc0, %i2, %i0
7373
; CHECK: restore
7474
define i64 @selecti64_fcc(float %x, float %y, i64 %a, i64 %b) {

0 commit comments

Comments
 (0)