Skip to content

Commit

Permalink
[Sparc] Delete FPMover Pass and remove Fp* Pseudo-instructions from S…
Browse files Browse the repository at this point in the history
…parc backend.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183613 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
vegovin committed Jun 8, 2013
1 parent 9eefea0 commit 1799921
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 162 deletions.
1 change: 0 additions & 1 deletion lib/Target/Sparc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ add_public_tablegen_target(SparcCommonTableGen)

add_llvm_target(SparcCodeGen
DelaySlotFiller.cpp
FPMover.cpp
SparcAsmPrinter.cpp
SparcInstrInfo.cpp
SparcISelDAGToDAG.cpp
Expand Down
141 changes: 0 additions & 141 deletions lib/Target/Sparc/FPMover.cpp

This file was deleted.

1 change: 0 additions & 1 deletion lib/Target/Sparc/Sparc.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ namespace llvm {

FunctionPass *createSparcISelDag(SparcTargetMachine &TM);
FunctionPass *createSparcDelaySlotFillerPass(TargetMachine &TM);
FunctionPass *createSparcFPMoverPass(TargetMachine &TM);

} // end namespace llvm;

Expand Down
40 changes: 39 additions & 1 deletion lib/Target/Sparc/SparcISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1315,6 +1315,12 @@ SparcTargetLowering::SparcTargetLowering(TargetMachine &TM)
// on SparcV8 and later.
setOperationAction(ISD::ATOMIC_FENCE, MVT::Other, Expand);

if (!Subtarget->isV9()) {
// SparcV8 does not have FNEGD and FABSD.
setOperationAction(ISD::FNEG, MVT::f64, Custom);
setOperationAction(ISD::FABS, MVT::f64, Custom);
}

setOperationAction(ISD::FSIN , MVT::f64, Expand);
setOperationAction(ISD::FCOS , MVT::f64, Expand);
setOperationAction(ISD::FSINCOS, MVT::f64, Expand);
Expand Down Expand Up @@ -1365,7 +1371,7 @@ SparcTargetLowering::SparcTargetLowering(TargetMachine &TM)

setStackPointerRegisterToSaveRestore(SP::O6);

if (TM.getSubtarget<SparcSubtarget>().isV9())
if (Subtarget->isV9())
setOperationAction(ISD::CTPOP, MVT::i32, Legal);

setMinFunctionAlignment(2);
Expand Down Expand Up @@ -1751,10 +1757,42 @@ static SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) {
return RetAddr;
}

static SDValue LowerF64Op(SDValue Op, SelectionDAG &DAG)
{
SDLoc dl(Op);

assert(Op.getValueType() == MVT::f64 && "LowerF64Op called on non-double!");
assert(Op.getOpcode() == ISD::FNEG || Op.getOpcode() == ISD::FABS);

// Lower fneg/fabs on f64 to fneg/fabs on f32.
// fneg f64 => fneg f32:sub_even, fmov f32:sub_odd.
// fabs f64 => fabs f32:sub_even, fmov f32:sub_odd.

SDValue SrcReg64 = Op.getOperand(0);
SDValue Hi32 = DAG.getTargetExtractSubreg(SP::sub_even, dl, MVT::f32,
SrcReg64);
SDValue Lo32 = DAG.getTargetExtractSubreg(SP::sub_odd, dl, MVT::f32,
SrcReg64);

Hi32 = DAG.getNode(Op.getOpcode(), dl, MVT::f32, Hi32);

SDValue DstReg64 = SDValue(DAG.getMachineNode(TargetOpcode::IMPLICIT_DEF,
dl, MVT::f64), 0);
DstReg64 = DAG.getTargetInsertSubreg(SP::sub_even, dl, MVT::f64,
DstReg64, Hi32);
DstReg64 = DAG.getTargetInsertSubreg(SP::sub_odd, dl, MVT::f64,
DstReg64, Lo32);
return DstReg64;
}

SDValue SparcTargetLowering::
LowerOperation(SDValue Op, SelectionDAG &DAG) const {
switch (Op.getOpcode()) {
default: llvm_unreachable("Should not custom lower this!");

case ISD::FNEG:
case ISD::FABS: return LowerF64Op(Op, DAG);

case ISD::RETURNADDR: return LowerRETURNADDR(Op, DAG);
case ISD::FRAMEADDR: return LowerFRAMEADDR(Op, DAG);
case ISD::GlobalTLSAddress:
Expand Down
26 changes: 22 additions & 4 deletions lib/Target/Sparc/SparcInstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,28 @@ void SparcInstrInfo::copyPhysReg(MachineBasicBlock &MBB,
else if (SP::FPRegsRegClass.contains(DestReg, SrcReg))
BuildMI(MBB, I, DL, get(SP::FMOVS), DestReg)
.addReg(SrcReg, getKillRegState(KillSrc));
else if (SP::DFPRegsRegClass.contains(DestReg, SrcReg))
BuildMI(MBB, I, DL, get(Subtarget.isV9() ? SP::FMOVD : SP::FpMOVD), DestReg)
.addReg(SrcReg, getKillRegState(KillSrc));
else
else if (SP::DFPRegsRegClass.contains(DestReg, SrcReg)) {
if (Subtarget.isV9()) {
BuildMI(MBB, I, DL, get(SP::FMOVD), DestReg)
.addReg(SrcReg, getKillRegState(KillSrc));
} else {
// Use two FMOVS instructions.
const TargetRegisterInfo *TRI = &getRegisterInfo();
MachineInstr *MovMI = 0;
unsigned subRegIdx[] = {SP::sub_even, SP::sub_odd};
for (unsigned i = 0; i != 2; ++i) {
unsigned Dst = TRI->getSubReg(DestReg, subRegIdx[i]);
unsigned Src = TRI->getSubReg(SrcReg, subRegIdx[i]);
assert(Dst && Src && "Bad sub-register");

MovMI = BuildMI(MBB, I, DL, get(SP::FMOVS), Dst).addReg(Src);
}
// Add implicit super-register defs and kills to the last MovMI.
MovMI->addRegisterDefined(DestReg, TRI);
if (KillSrc)
MovMI->addRegisterKilled(SrcReg, TRI);
}
} else
llvm_unreachable("Impossible reg-to-reg copy");
}

Expand Down
13 changes: 0 additions & 13 deletions lib/Target/Sparc/SparcInstrInfo.td
Original file line number Diff line number Diff line change
Expand Up @@ -245,19 +245,6 @@ let hasSideEffects = 1, mayStore = 1 in {
def UNIMP : F2_1<0b000, (outs), (ins i32imm:$val),
"unimp $val", []>;

// FpMOVD/FpNEGD/FpABSD - These are lowered to single-precision ops by the
// fpmover pass.
let Predicates = [HasNoV9] in { // Only emit these in V8 mode.
def FpMOVD : Pseudo<(outs DFPRegs:$dst), (ins DFPRegs:$src),
"!FpMOVD $src, $dst", []>;
def FpNEGD : Pseudo<(outs DFPRegs:$dst), (ins DFPRegs:$src),
"!FpNEGD $src, $dst",
[(set f64:$dst, (fneg f64:$src))]>;
def FpABSD : Pseudo<(outs DFPRegs:$dst), (ins DFPRegs:$src),
"!FpABSD $src, $dst",
[(set f64:$dst, (fabs f64:$src))]>;
}

// SELECT_CC_* - Used to implement the SELECT_CC DAG operation. Expanded after
// instruction selection into a branch sequence. This has to handle all
// permutations of selection between i32/f32/f64 on ICC and FCC.
Expand Down
1 change: 0 additions & 1 deletion lib/Target/Sparc/SparcTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ bool SparcPassConfig::addInstSelector() {
/// passes immediately before machine code is emitted. This should return
/// true if -print-machineinstrs should print out the code after the passes.
bool SparcPassConfig::addPreEmitPass(){
addPass(createSparcFPMoverPass(getSparcTargetMachine()));
addPass(createSparcDelaySlotFillerPass(getSparcTargetMachine()));
return true;
}
Expand Down
47 changes: 47 additions & 0 deletions test/CodeGen/SPARC/float.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
; RUN: llc -march=sparc < %s | FileCheck %s -check-prefix=V8
; RUN: llc -march=sparc -O0 < %s | FileCheck %s -check-prefix=V8-UNOPT
; RUN: llc -march=sparc -mattr=v9 < %s | FileCheck %s -check-prefix=V9


; V8: test_neg:
; V8: call get_double
; V8: fnegs %f0, %f0

; V8-UNOPT: test_neg:
; V8-UNOPT: fnegs
; V8-UNOPT: ! implicit-def
; V8-UNOPT: fmovs {{.+}}, %f0
; V8-UNOPT: fmovs {{.+}}, %f1

; V9: test_neg:
; V9: fnegd %f0, %f0

define double @test_neg() {
entry:
%0 = tail call double @get_double()
%1 = fsub double -0.000000e+00, %0
ret double %1
}

; V8: test_abs:
; V8: fabss %f0, %f0

; V8-UNOPT: test_abs:
; V8-UNOPT: fabss
; V8-UNOPT: ! implicit-def
; V8-UNOPT: fmovs {{.+}}, %f0
; V8-UNOPT: fmovs {{.+}}, %f1

; V9: test_abs:
; V9: fabsd %f0, %f0

define double @test_abs() {
entry:
%0 = tail call double @get_double()
%1 = tail call double @llvm.fabs.f64(double %0)
ret double %1
}

declare double @get_double()
declare double @llvm.fabs.f64(double) nounwind readonly

0 comments on commit 1799921

Please sign in to comment.