This is an archive of the discontinued LLVM Phabricator instance.

[X86][X87] Ensure x87 instructions are tagged as altering the FPSW reg
ClosedPublic

Authored by RKSimon on Aug 7 2017, 10:10 AM.

Details

Summary

As noted in PR34080, a lot of x87 instructions alter the FPSW status register (or leave it in an undefined state) but aren't tagged as such in the tablegen.

This patch tags the control word, stack, wait and math instructions as altering FPSW, which matches what the AMD APMs suggests happens.

If anyone has some suggestions on tests for this, I'm open to ideas.....

Diff Detail

Repository
rL LLVM

Event Timeline

RKSimon created this revision.Aug 7 2017, 10:10 AM
craig.topper edited edge metadata.Aug 7 2017, 10:33 AM

Weirdly, Intel's documentation says that FNOP puts the FPU flags in an undefined state. AMD says they are unmodified. I'll see if I can find someone internally to determine if that's a mistake in Intel's documentation.

DavidKreitzer edited edge metadata.Aug 10 2017, 7:57 AM

The change looks correct to me modulo Craig's comment, though I suspect he's right that there is a bug in the Intel documentation for FNOP.

Regarding testing, would it be possible to write MI tests that run through the MIScheduler in misched-bottomup mode? The idea would be to construct an MI sequence similar to this:

...
fcom
fxam ; or some other FPSW-defining instruction you want to test
fstsw ax
...

I am not intimately familiar with the instruction scheduler, but if misched-bottomup behaves as its name implies, I would expect the fxam to be incorrectly hoisted above the fcom without your fix.

Weirdly, Intel's documentation says that FNOP puts the FPU flags in an undefined state. AMD says they are unmodified. I'll see if I can find someone internally to determine if that's a mistake in Intel's documentation.

@craig.topper Did you get an answer to this? The patch shouldn't introduce any new bugs to FNOP.

craig.topper accepted this revision.Sep 5 2017, 9:41 AM

I wasn't able to get an answer at FNOP. But it doesn't affect this patch.

The patch LGTM.

This revision is now accepted and ready to land.Sep 5 2017, 9:41 AM
This revision was automatically updated to reflect the committed changes.

I wasn't able to get an answer at FNOP. But it doesn't affect this patch.

The patch LGTM.

Thanks, I've committed the patch, but still haven't been able to create any suitable tests. x87 isn't easy to test as it is so its not a new problem, but I'll keep looking at options.