This is an archive of the discontinued LLVM Phabricator instance.

[X86] Add ST0 as an implicit def/use of x87 load/store instructions during FP stackifying.
ClosedPublic

Authored by craig.topper on Feb 2 2019, 7:19 PM.

Details

Summary

These instructions implicitly operate on ST0, but we don't currently add that information to the MachineInstr. We also don't add it the tablegen definitions either.

For the most part this doesn't cause any problems because the stackifying occurs after register allocation. All the instructions are marked as having side effects so the postRA scheduler won't reorder them amongst themselves.

But nothing stops inline assembly using X87 instructions from being reordered around other x87 instructions if that inline assembly wasn't marked volatile.

The two test cases I've identified so far in PR40539 involve loads and stores used to set up the inline assembly or capture the results of the inline assembly ending up in the wrong order.

This patch adds implicit ST0 uses/defs to the load/store instructions to prevent this from happening.

I plan to fix all of the FP instructions, but the binops are bit trickier to get right. So I've chosen fixing the known test cases as a good first step.

I think we also need to update the tablegen descriptions so MS inline assembly infers the right clobbers, but I haven't checked that yet.

Diff Detail

Repository
rL LLVM

Event Timeline

craig.topper created this revision.Feb 2 2019, 7:19 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 2 2019, 7:19 PM
RKSimon accepted this revision.Feb 4 2019, 3:56 AM

LGTM

This revision is now accepted and ready to land.Feb 4 2019, 3:56 AM
This revision was automatically updated to reflect the committed changes.