This pass, fixing an erratum in some LEON 2 processors ensures that the SDIV instruction is not issued, but replaced by SDIVcc instead, which does not exhibit the error. Unit test included.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
lib/Target/Sparc/LeonPasses.cpp | ||
---|---|---|
300–305 ↗ | (On Diff #71618) | SDIVcc modifies the integer condition codes, so if any later instruction depends on the current value of those you might get the wrong result. You probably need to do the switch at an earlier stage to prevent this from happening. |
Addresses Daniel Cederman's concerns about the integer condition codes potentially being corrupted by marking that the ICC (condition codes) are changed by the SDIV instruction when the erratum fix is switched on. This will prevent the compiler from inserting this instruction in between the condition codes being set and later, being used.
This could be fixed in the front-end of the compiler, but it was difficult to find a working solution in the back-end except for this change.
HasLeonSdivReplace doesn't actually work the way you want it to: division gets selected manually in SparcDAGToDAGISel::Select (https://github.com/llvm-mirror/llvm/blob/master/lib/Target/Sparc/SparcISelDAGToDAG.cpp#L362), not through a pattern, so the predicate has no effect.
Actually, you should be able to substitute in the correct opcode at that point, instead of fixing up the MachineInstr later.
Earlier you had a unit test for this patch, but it seems to have gone missing in the later updates. Could you add it again?
(Re-) added unit test. Added test to ensure this doesn't change behaviour for unaffected processors.