Page MenuHomePhabricator

[X86][Draft] Disable long double type for -mno-x87 option
Needs ReviewPublic

Authored by asavonic on Mar 18 2021, 1:45 PM.

Details

Summary

This patch attempts to fix a compiler crash that occurs when long double type
is used with -mno-x87 compiler option.

The option disables x87 target feature, which in turn disables x87 registers, so
CG cannot select them for x86_fp80 LLVM IR type. Long double is lowered as
x86_fp80 for some targets, so it leads to a crash.

The option seems to contradict the SystemV ABI, which requires long double to
be represented as a 80-bit floating point, and it also requires to use x87 registers.

Diff Detail

Event Timeline

asavonic created this revision.Mar 18 2021, 1:45 PM
asavonic requested review of this revision.Mar 18 2021, 1:45 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 18 2021, 1:45 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
asavonic added a comment.EditedMar 18 2021, 2:01 PM

I'm not sure that this is the right approach, but I wanted to get feedback on
how the issue should be fixed. Currently, the compiler crashes on almost any
code with long double and -mno-x87 (excluding cases where CG does not properly disable x87):

long double foo(long double x, long double y)
{
  long double z = x + y;
  if (z < 0.0)
    return z;
  else
    return 0.0;
}

The option was added in D19658 and D13979, but I'm not sure how it is supposed to work for SystemV ABI.
GCC emits an error if long double type is used with -mno-x87: "test.c:37:1: error: x87 register return with x87 disabled".

Added reviewers of the original patches. Please let me know if this patch makes sense, or we should do something else to avoid the crash.