Bug 59277 - x86_64 code generation defects when SSE instructions are disabled
Summary: x86_64 code generation defects when SSE instructions are disabled
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.7.3
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2013-11-24 19:56 UTC by Aaron Myles Landwehr
Modified: 2013-11-25 17:11 UTC (History)
0 users

See Also:
Host:
Target: x86_64-*-*
Build:
Known to work:
Known to fail:
Last reconfirmed: 2013-11-25 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Aaron Myles Landwehr 2013-11-24 19:56:48 UTC
There are a couple of defects in GCC for x86_64 targets when -mno-sse is specified.

(1) SSE registers are still generated in various cases. For example, the following codes will throw an error during compilation because SSE registers are used:
   (1) double test() { return 0.0; }
   (2) void test (int n, ...) {
          va_list vl; va_start(vl, n);
          double foo = va_arg(vl, double);
          va_end(vl);
       }

(2) va_arg is broken for double types, independently of the bug listed above. When '-mno-sse' is specified, floating-point numbers are pushed to the stack by default instead of using the SSE registers; however, the current implementation for va_arg still looks in the register save area for FP numbers and as such it returns garbage values.

A fix for the latter should be pretty simple, along the lines of just defaulting to overflow area for double types similar to the following:
    #define va_arg_double(va) \
        (*(double*)((va->overflow_arg_area += 8, va->overflow_arg_area

It looked to me like the code to generate the ABI implementation of va_list for x86 targets is in gcc\config\i386\i386.c.

The only question I have is that I believe fixing these the defects breaks with the x86_64 ABI specification and wonder whether this would be an issue because of that.
Comment 1 Andrew Pinski 2013-11-24 23:11:40 UTC
1) I don't think this is a bug since the abi says to use SSE registers here. If you want a different abi where SSE is not used you need to create a new abi

2) yes GCC is inconatsaint here but not really a bug due to an abi different.
Comment 2 Aaron Myles Landwehr 2013-11-24 23:33:17 UTC
Right, a fix for this is really a question of whether the ABI holds king here.

It is worth mentioning that the current behavior of passing the FP arguments via the stack is in itself also against what the ABI dictates for x86_64.

LLVM also has the same issue and I passed this along to them with very much the same question of whether this should be handled at all or whether it should simply be left as a "you can try disabling sse in x86_64 if you want, it may work, it may not -- it really depends on what you are doing -- all bets are off"
Comment 3 Richard Biener 2013-11-25 09:14:32 UTC
We still have to follow the ABI.  Of course I'd say with -mno-sse you
should get a fatal_error () whenever you run into an ABI piece that requires
SSE registers (instead of silently using them).

We may have one or more (near) duplicates of this bug.
Comment 4 Aaron Myles Landwehr 2013-11-25 17:11:04 UTC
That is completely fair. Correct me if I'm wrong here, but that also means that any code that passes doubles as arguments should also get fatal_error() instead of dropping arguments to the stack as is currently done.