This is an archive of the discontinued LLVM Phabricator instance.

[mips] Prevent shrink-wrap for BuildPairF64, ExtractElementF64 when they use $sp
ClosedPublic

Authored by vstefanovic on Aug 20 2018, 11:49 AM.

Details

Summary

For a certain combination of options, BuildPairF64_{64}, ExtractElementF64{_64}
may be expanded into instructions using stack.
Add implicit operand $sp for such cases so that ShrinkWrapping doesn't move
prologue setup below them.

Fixes MultiSource/Benchmarks/MallocBench/cfrac for
'--target=mips-img-linux-gnu -mcpu=mips32r6 -mfpxx -mnan=2008'
and
'--target=mips-img-linux-gnu -mcpu=mips32r6 -mfp64 -mnan=2008 -mno-odd-spreg'.

Diff Detail

Repository
rL LLVM

Event Timeline

vstefanovic created this revision.Aug 20 2018, 11:49 AM
thegameg added a subscriber: thegameg.

This looks ok, but I am not sure the FrameSetup flag was made to be used in this way.

Would it make more sense to add SP as an implicit use to the instruction instead? I believe this is how things are usually modelled now, but I might be wrong.

test/CodeGen/Mips/shrink-wrap-buildpairf64-extractelementf64.ll
1 ↗(On Diff #161524)

Can you please add a MIR test with -start-before shrink-wrap -stop-after prologepilog instead of an IR test?

This looks wrong to me. And it would be good if you could explain with more detail or an example. So far I see: An instruction uses a register but we didn't add a register operand for that. Why would we fix this by adding an exception into shrink wrapping instead of making sure there is an actual operand?

Adding implicit operand $sp to the instructions instead of FrameSetup flag.

Thanks for the comments, adding $sp as implicit operand is a lot better, no need to modify ShrinkWrapping then.

An example - BuildPair64 loads 64 bits into a FPR from two GPRs.

$d0 = BuildPairF64 $zero, $zero

This is later usually expanded to mtc1 + mthc1:

$f0 = MTC1 $zero
$d0 = MTHC1_D32 $d0, $zero

but when mthc1 isn't available (e.g. for '-mfpxx -mcpu=mips32'), $d0 is loaded via stack:

SW $zero, $sp, 16
SW $zero, $sp, 20
$d0 = LDC1 $sp, 16

(I'll update commit message if this is ok.)

test/CodeGen/Mips/shrink-wrap-buildpairf64-extractelementf64.ll
1 ↗(On Diff #161524)

I also need to check whether $sp is added to implicit operands in the isel pass.
There could be a separate test for that, but I found it more convenient to cover everything with one input.

thegameg added inline comments.Aug 21 2018, 11:04 AM
test/CodeGen/Mips/shrink-wrap-buildpairf64-extractelementf64.ll
1 ↗(On Diff #161524)

Yes, I think just -stop-after=isel should do it.

Split the test.

vstefanovic retitled this revision from [ShrinkWrap] Don't put pseudo-instrs which use $sp before prologue setup to [mips] Prevent shrink-wrap for BuildPairF64, ExtractElementF64 when they use $sp.Aug 22 2018, 3:09 PM
vstefanovic edited the summary of this revision. (Show Details)
thegameg accepted this revision.Aug 28 2018, 3:55 AM

Looks better now. Thanks for adding the MIR test.

LGTM although I have no knowledge about the MIPS backend, so you might want to wait for someone else.

This revision is now accepted and ready to land.Aug 28 2018, 3:55 AM
This revision was automatically updated to reflect the committed changes.