Hi,
I have a task to complete and I’m getting stuck. I can’t find anything comparable in the documentation. The shortest explanation I can give is as follows: I need to use double-precision floating point values for floating-point multiplies. I’ll not go into why: That would take the discussion away from the essential problem. E.g.
Replace:
fmuls %f20,%f21,%f8
with the sequence:
fstod %f20,%f0
fstod %f21,%f2
fmuld %f0,%f2,%f8
This is for a Sparc derived back-end and I’m already at the MachineInstr phase. The essential code I have now is as follows, but it doesn’t work. I’ve had much larger pieces of code, but I believe my mistake lies somewhere in here. I’m not sure if I’m heading down the right path with this. Please, any help would be appreciated – or any reference to an example, even better.
[code is iterating through the MachineBasicBlock – this code is pretty straightforward and you can probably guess what’s in it]
if (Opcode == SP::FMULS)
{
MachineOperand& MO = MI.getOperand(0);
DebugLoc DL = MBBI->getDebugLoc();
BuildMI(MBB, MBBI, DL, TII.get(SP::FSTOD), MO.getReg());
[ Then we’d do the second fstod and the fmuld, but I’ve not included this because the basic problem of generating the MachineInstr has happened already for this first MachineInstr]
MI.eraseFromParent();
}
Chris Dewhurst,
University of Limerick, Ireland
On Sep 7, 2015, at 6:40 PM, Chris.Dewhurst via llvm-dev <llvm...@lists.llvm.org> wrote:Hi,I have a task to complete and I’m getting stuck. I can’t find anything comparable in the documentation. The shortest explanation I can give is as follows: I need to use double-precision floating point values for floating-point multiplies. I’ll not go into why: That would take the discussion away from the essential problem. E.g.Replace:fmuls %f20,%f21,%f8with the sequence:fstod %f20,%f0fstod %f21,%f2fmuld %f0,%f2,%f8This is for a Sparc derived back-end and I’m already at the MachineInstr phase. The essential code I have now is as follows, but it doesn’t work. I’ve had much larger pieces of code, but I believe my mistake lies somewhere in here. I’m not sure if I’m heading down the right path with this. Please, any help would be appreciated – or any reference to an example, even better.[code is iterating through the MachineBasicBlock – this code is pretty straightforward and you can probably guess what’s in it]if (Opcode == SP::FMULS){MachineOperand& MO = MI.getOperand(0);DebugLoc DL = MBBI->getDebugLoc();BuildMI(MBB, MBBI, DL, TII.get(SP::FSTOD), MO.getReg());
[ Then we’d do the second fstod and the fmuld, but I’ve not included this because the basic problem of generating the MachineInstr has happened already for this first MachineInstr]
MI.eraseFromParent();}Chris Dewhurst,University of Limerick, Ireland
_______________________________________________
LLVM Developers mailing list
llvm...@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
On Sep 7, 2015, at 8:19 PM, Chris.Dewhurst <Chris.D...@lero.ie> wrote:Hi,
Just for completeness, the essential problem is that the hardware implementation of the Sparc-derived processor's FMULS operation is faulty and this needs to be fixed by substituting a FMULD to simulate the operation instead (FMULD does not exhibit the problem). The hardware fix will take a long time to be released.
More specifically, in terms of the running the code, the problem appear on the next iteration of the MBB, giving me this error, which could perhaps be because I've broken the list in MBB, perhaps???
Are you sure you need to actually do this as a post-processing pass after code generation? Why not setOperationAction(ISD::FMUL, MVT::i32, Promote); SparcISelLowering.cpp? I believe that'd avoid having it get generated in the first place (although I've not tested it).
Also: which erratum are you trying to work around? UT699's "FMULS precision loss after FDIVD/FSQRTD"? If so, I'd think that the workaround option of adding a "std %fNN, [%sp-8]" after fdivd/fsqrtd instructions may be better?
I'm nearly there and, notwithstanding that it might be better to use setOperationAction (as indicated, James), this is representative of a class of problem that I'm trying to resolve in a few places, so I'll keep onto the original question, rather than re-framing it for a different problem.
The initial problem I posted for was with the iterator, which I needed to move onwards before removing the initial instruction. That is now OK and I have this working.
I belive my problem is now with registers. The code below runs well, but when it comes to outputting instructions it fails again. I believe this is a problem with using a virtual rather than a physical register, but I'm really not sure how or where to resolve this. Any help appreciated.
The bug in the instruction printer is:
static const char* llvm::SparcInstPrinter::getRegisterName(unsigned int): Assertion `RegNo && RegNo < 153 && "Invalid register number!"' failed.
RegNo = 0x8000000, which indicates a virtual register if I understand correctly.
The code I'm using to generate the new MI is below. This works fine, except that it produces instructions that later fail as indicated above:
bool MyPass::runOnMachineFunction(MachineFunction& MF)
{
Subtarget = &MF.getSubtarget<SparcSubtarget>();
const TargetInstrInfo& TII = *Subtarget->getInstrInfo();
const TargetRegisterInfo* TRI = Subtarget->getRegisterInfo();
const TargetRegisterClass* DoubleRC = TRI->getRegClass(SP::DFPRegsRegClassID);
bool Modified = false;
for (auto MFI = MF.begin(), E = MF.end(); MFI != E; ++MFI)
{
MachineBasicBlock &MBB = *MFI;
for (auto MBBI = MBB.begin(), E = MBB.end(); MBBI != E; ++ MBBI)
{
MachineInstr &MI = *MBBI;
//MI.print(errs());
unsigned Opcode = MI.getOpcode();
if (Opcode == SP::FMULS)
{
MachineRegisterInfo& MRI = MF.getRegInfo();
unsigned int f0 = MRI.createVirtualRegister(DoubleRC);
MachineBasicBlock::iterator NMBBI = std::next(MBBI);
MachineOperand& MOx = MI.getOperand(0);
DebugLoc DL = MBBI->getDebugLoc();
BuildMI(MBB, MBBI, DL, TII.get(SP::FSTOD), f0).addReg(MOx.getReg());
// And so on for the other new instructions.
MI.eraseFromParent();
MBBI = NMBBI;
Modified = true;
}
}
}
return Modified;
}
________________________________________
From: James Y Knight [jykn...@google.com]
Sent: 08 September 2015 06:00
To: Chris.Dewhurst; Chris.Dewhurst via llvm-dev
Subject: Re: [llvm-dev] Inserting MachineInstr's
On Sep 7, 2015, at 9:40 PM, Chris.Dewhurst via llvm-dev <llvm...@lists.llvm.org> wrote: