Bug 67963 - -march=lakemont generates x87 instructions
Summary: -march=lakemont generates x87 instructions
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 6.0
: P3 normal
Target Milestone: 6.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-10-14 12:30 UTC by H.J. Lu
Modified: 2015-10-20 15:13 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Patch that introduces PTA_NO_80387 (563 bytes, patch)
2015-10-15 11:23 UTC, Uroš Bizjak
Details | Diff
V2 patch that introduces PTA_NO_80387 (797 bytes, patch)
2015-10-15 12:10 UTC, Uroš Bizjak
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2015-10-14 12:30:30 UTC
[hjl@gnu-6 gcc]$ cat x.c
float
foo (void)
{
  return 0;
}
[hjl@gnu-6 gcc]$ ./xgcc -B./ -march=lakemont -S x.c -m32
[hjl@gnu-6 gcc]$ cat x.s
	.file	"x.c"
	.text
	.globl	foo
	.type	foo, @function
foo:
.LFB0:
	.cfi_startproc
	pushl	%ebp
	.cfi_def_cfa_offset 8
	.cfi_offset 5, -8
	movl	%esp, %ebp
	.cfi_def_cfa_register 5
	fldz
	popl	%ebp
	.cfi_restore 5
	.cfi_def_cfa 4, 4
	ret
	.cfi_endproc
.LFE0:
	.size	foo, .-foo
	.ident	"GCC: (GNU) 6.0.0 20151006 (experimental)"
	.section	.note.GNU-stack,"",@progbits
[hjl@gnu-6 gcc]$ 

We should issue an error if -march=lakemont is used without -miacmu.
Comment 1 H.J. Lu 2015-10-14 12:46:43 UTC
(In reply to H.J. Lu from comment #0)
> We should issue an error if -march=lakemont is used without -miacmu.

We should issue an error if -march=lakemont is used without -mno-80387,
not without -miamcu.
Comment 2 H.J. Lu 2015-10-14 13:38:23 UTC
(In reply to H.J. Lu from comment #1)
> (In reply to H.J. Lu from comment #0)
> > We should issue an error if -march=lakemont is used without -miacmu.
> 
> We should issue an error if -march=lakemont is used without -mno-80387,
> not without -miamcu.

-march=lakemont should imply -mno-80387.
Comment 3 Julia Koval 2015-10-14 15:09:00 UTC
Patch posted at:

https://gcc.gnu.org/ml/gcc-patches/2015-10/msg01369.html

The same test with this patch:

objdump -d test.o

test.o:     file format elf32-i386


Disassembly of section .text:

00000000 <foo>:
   0:   55                      push   %ebp
   1:   89 e5                   mov    %esp,%ebp
   3:   a1 00 00 00 00          mov    0x0,%eax
   8:   5d                      pop    %ebp
   9:   c3                      ret
Comment 4 Uroš Bizjak 2015-10-15 09:56:40 UTC
I have a patch that moves -m80387 to ISA flags.
Comment 5 Uroš Bizjak 2015-10-15 11:22:16 UTC
(In reply to Uroš Bizjak from comment #4)
> I have a patch that moves -m80387 to ISA flags.

Not really. To be attached much simpler patch introduces PTA_NO_80387 and changes target flags instead.
Comment 6 Uroš Bizjak 2015-10-15 11:23:12 UTC
Created attachment 36516 [details]
Patch that introduces PTA_NO_80387
Comment 7 Uroš Bizjak 2015-10-15 12:10:13 UTC
Created attachment 36517 [details]
V2 patch that introduces PTA_NO_80387
Comment 8 H.J. Lu 2015-10-15 12:30:55 UTC
(In reply to Uroš Bizjak from comment #7)
> Created attachment 36517 [details]
> V2 patch that introduces PTA_NO_80387

We need some testcases to verify it works on command line as well
as with __attribute__((target("arch=...."))).
Comment 9 hjl@gcc.gnu.org 2015-10-20 15:13:09 UTC
Author: hjl
Date: Tue Oct 20 15:12:37 2015
New Revision: 229082

URL: https://gcc.gnu.org/viewcvs?rev=229082&root=gcc&view=rev
Log:
Properly handle -miamcu and -march=lakemont

-miamcu specifies how parameters are passed to functions and how value
is returned from a function.  Inside function,  we can use instructions
supported by -march=XXX.  -miamcu -march=haswell can generate x87, SSE
and AVX instructions as long as the IA MCU psABI is followed.  But since
Lakemont processor doesn't support x87 instructions, we shouldn't
generate x87 instructions with -march=lakemont.  This patch separates
code generation from -miamcu and makes -march=lakemont not to generate
x87 instructions.

gcc/

	PR target/67963
	PR target/67985
	* common/config/i386/i386-common.c (ix86_handle_option): Remove
	OPT_miamcu handling.
	* config/i386/i386.c (PTA_NO_80387): New macro.
	(processor_alias_table): Add PTA_NO_80387 to lakemont.
	(ix86_option_override_internal): Update MASK_80387 from
	PTA_NO_80387.  Don't warn x87/MMX/SSE/AVX for -miamcu.  Warn
	SSE math only if 80387 is supported.  Don't change
	MASK_FLOAT_RETURNS.
	(ix86_valid_target_attribute_tree): Enable FPMATH_387 only if
	80387 is supported.
	* config/i386/i386.h (TARGET_FLOAT_RETURNS_IN_80387): True only
	if TARGET_80387 is true and TARGET_IAMCU is false.
	(TARGET_FLOAT_RETURNS_IN_80387_P): True only if TARGET_80387_P
	is true and TARGET_IAMCU_P is false.

gcc/testsuite/

	PR target/67963
	PR target/67985
	* gcc.target/i386/pr67963-1.c: New test.
	* gcc.target/i386/pr67963-2.c: Likewise.
	* gcc.target/i386/pr67963-3.c: Likewise.
	* gcc.target/i386/pr67985-1.c: Likewise.
	* gcc.target/i386/pr67985-2.c: Likewise.
	* gcc.target/i386/pr67985-3.c: Likewise.

Added:
    trunk/gcc/testsuite/gcc.target/i386/pr67963-1.c
    trunk/gcc/testsuite/gcc.target/i386/pr67963-2.c
    trunk/gcc/testsuite/gcc.target/i386/pr67963-3.c
    trunk/gcc/testsuite/gcc.target/i386/pr67985-1.c
    trunk/gcc/testsuite/gcc.target/i386/pr67985-2.c
    trunk/gcc/testsuite/gcc.target/i386/pr67985-3.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/common/config/i386/i386-common.c
    trunk/gcc/config/i386/i386.c
    trunk/gcc/config/i386/i386.h
    trunk/gcc/testsuite/ChangeLog
Comment 10 H.J. Lu 2015-10-20 15:13:54 UTC
Fixed.