Page MenuHomePhabricator

[X86] Don't set exception mask bits when modifying FPCW to change rounding mode for fp->int conversion
ClosedPublic

Authored by craig.topper on Feb 5 2019, 1:59 PM.

Details

Summary

When we need to do an fp->int conversion using x87 instructions, we need to temporarily change the rounding mode to 0b11 and perform a store. To do this we save the old value of the fpcw to the stack, then set the fpcw to 0xc7f, do the store, then restore fpcw. But the 0xc7f value forces the exception mask bits 1. While this is what they would be in the default FP environment, as we move to support changing the FP environments, we shouldn't make this assumption.

This patch changes the code to explicitly OR 0xc00 with the old value so that only the rounding mode is changed. Unfortunately, this requires an additional stack temporaries one to hold the old value and one to hold the new value. Without two stack temporaries we would need an additional GPR. We already need one to do the OR operation in. This is similar to what gcc and icc do for this operation. Though they are both better at reusing the stack temporaries when there are multiple truncates in a function(or at least in a basic block)

Diff Detail

Repository
rL LLVM

Event Timeline

craig.topper created this revision.Feb 5 2019, 1:59 PM
RKSimon accepted this revision.Feb 15 2019, 4:26 AM

LGTM with one minor

lib/Target/X86/X86ISelLowering.cpp
30071 ↗(On Diff #185395)

Explain what the bits represent

This revision is now accepted and ready to land.Feb 15 2019, 4:26 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 15 2019, 1:59 PM

BTW, this seems to have caused a regression -- see https://bugs.llvm.org/show_bug.cgi?id=40779