Bug 45325 - [4.9 Regression] target attribute doesn't work with -march=i586
Summary: [4.9 Regression] target attribute doesn't work with -march=i586
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.6.0
: P2 normal
Target Milestone: 5.0
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid, ice-on-invalid-code
: 45753 46025 (view as bug list)
Depends on: 37565
Blocks: 45475
  Show dependency treegraph
 
Reported: 2010-08-18 20:23 UTC by H.J. Lu
Modified: 2016-08-03 08:18 UTC (History)
9 users (show)

See Also:
Host:
Target: i?86-*-*
Build:
Known to work: 4.4.4, 4.5.2, 5.0
Known to fail: 4.6.0, 4.9.4
Last reconfirmed: 2010-09-23 06:10:37


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2010-08-18 20:23:56 UTC
[hjl@gnu-36 gcc]$ cat ../../../../src-trunk/gcc/testsuite/gcc.target/i386/pr38240.c
/* { dg-do compile } */

typedef float V
  __attribute__ ((__vector_size__ (16), __may_alias__));

V __attribute__((target("sse"))) f(const V *ptr) { return *ptr; }

V g(const V *ptr) { return *ptr; }
[hjl@gnu-36 gcc]$ ../../xgcc -B../../ ../../../../src-trunk/gcc/testsuite/gcc.target/i386/pr38240.c -S -march=i586 -m32
../../../../src-trunk/gcc/testsuite/gcc.target/i386/pr38240.c: In function ‘g’:
../../../../src-trunk/gcc/testsuite/gcc.target/i386/pr38240.c:8:21: internal compiler error: in convert_move, at expr.c:326
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
[hjl@gnu-36 gcc]$
Comment 1 Richard Biener 2010-08-18 20:31:29 UTC
Well - obviously global typedefs keep their BLKmode.  The target attribute
can't work this way - it's broken by design.
Comment 2 Steven Bosscher 2010-08-18 20:58:20 UTC
WONTFIX for an ICE seems a bit odd to me.
Just needs a diagnostic to reject nonsense target attributes, or a sorry. But not an ICE.
Comment 3 Richard Biener 2010-08-18 21:18:40 UTC
Well, I think we should back out support for that option.  The set of
"nonsensical" options doesn't include "sse" - but all options are included
in the set of broken options.  At least I expect that you can create a
testcase with such ICEs for every one.
Comment 4 H.J. Lu 2010-08-19 19:38:50 UTC
It is caused by revision 162918:

http://gcc.gnu.org/ml/gcc-cvs/2010-08/msg00129.html
Comment 5 Richard Henderson 2010-08-19 19:48:35 UTC
(In reply to comment #3)
> Well, I think we should back out support for that option.  The set of
> "nonsensical" options doesn't include "sse" - but all options are included
> in the set of broken options.  At least I expect that you can create a
> testcase with such ICEs for every one.

Not every one, just those that expand the set of valid backend modes.
Thus "sse3" will not cause additional ice's, assuming "sse2" is in
effect globally.

That's not to say this feature isn't fraught with peril.  I think it
should be improved though, not removed.
Comment 6 Dave Korn 2010-09-12 23:45:45 UTC
This is also present on i686-pc-cygwin:

> FAIL: gcc.target/i386/pr38240.c (internal compiler error)

ICE happens here:

(gdb) bt
#0  0x006065e0 in convert_move (to=0x7fcc26c0, from=0x7fcc26d0, unsignedp=0)
    at /gnu/gcc/gcc-unpatched/gcc/expr.c:2944
#1  0x00609d2f in store_expr (exp=0x7fde2c10, target=0x7fcc26c0,
    call_param_p=0, nontemporal=0 '\0')
    at /gnu/gcc/gcc-unpatched/gcc/expr.c:2944
#2  0x0060f638 in expand_assignment (to=0x7fe20050, from=0x7fde2c10,
    nontemporal=0 '\0') at /gnu/gcc/gcc-unpatched/gcc/expr.c:2944

(...yes, the line number info is wrong, don't know why but it's unrelated.)

  The patch in r162918 tightens up the condition on calling emit_block_move:

--- trunk/gcc/expr.c	2010/08/05 15:39:54	162917
+++ trunk/gcc/expr.c	2010/08/05 16:37:38	162918
@@ -4752,11 +4752,14 @@
 	{
 	  int unsignedp = TYPE_UNSIGNED (TREE_TYPE (exp));
 	  if (GET_MODE (target) == BLKmode
-		   || GET_MODE (temp) == BLKmode)
+	      && GET_MODE (temp) == BLKmode)
 	    emit_block_move (target, temp, expr_size (exp),
 			     (call_param_p
 			      ? BLOCK_OP_CALL_PARM
 			      : BLOCK_OP_NORMAL));
+	  else if (GET_MODE (target) == BLKmode)
+	    store_bit_field (target, INTVAL (expr_size (exp)) * BITS_PER_UNIT,
+			     0, GET_MODE (temp), temp);
 	  else
 	    convert_move (target, temp, unsignedp);
 	}
so that when temp is BLKmode and target is not, as in this case:

(gdb) call debug_rtx (to) # aka target
(mem/c/i:V4SF (reg/f:SI 58 [ D.1753 ]) [0 <retval>+0 S16 A128])
(gdb) call debug_rtx (from) # aka temp
(mem/c/i:BLK (plus:SI (reg/f:SI 54 virtual-stack-vars)
        (const_int -16 [0xfffffff0])) [0 D.1747+0 S16 A128])

... it falls through into the final else clause, and calls convert_move.  However convert_move is unable to handle any BLKmode data at all: it has these asserts near the beginning,

  gcc_assert (to_mode != BLKmode);
  gcc_assert (from_mode != BLKmode);

.. and the second one fires.
Comment 7 H.J. Lu 2010-09-23 00:20:48 UTC
*** Bug 45753 has been marked as a duplicate of this bug. ***
Comment 8 Richard Biener 2010-09-23 09:16:37 UTC
Yes, my patch should be a no-op on this failure, it just avoids calling
convert_move if it would ICE anyway.
Comment 9 Manuel López-Ibáñez 2010-09-23 15:53:50 UTC
(In reply to comment #1)
> Well - obviously global typedefs keep their BLKmode.  The target attribute
> can't work this way - it's broken by design.

If it is broken by design, why not remove it before people start depending on it and GCC has to add layer after layer of workarounds?
Comment 10 Richard Biener 2010-09-30 11:32:34 UTC
Target bug.  ix86_valid_target_attribute_p should reject "sse" if that
changes the mode of any type.  Thus, declaring the testcase as-is invalid.

The same issue is at least latent with 4.5, making this P2.
Comment 11 Rainer Orth 2010-10-14 18:31:31 UTC
*** Bug 46025 has been marked as a duplicate of this bug. ***
Comment 12 Dave Korn 2010-10-17 14:24:06 UTC
This also breaks lto-bootstrap on i686-pc-cygwin:

/gnu/gcc/gcc/libcpp/lex.c: In function ‘search_line_sse2’:
/gnu/gcc/gcc/libcpp/lex.c:370:15: internal compiler error: in convert_move, at expr.c:326

In the call to convert_move, we have:

to = (reg/v:V16QI 62 [ repl_nl ])
from = (mem/u/c:BLK (reg/f:SI 97) [0 MEM[(const v16qi *)&repl_chars]+0 S16 A128])
Comment 13 ro@CeBiTec.Uni-Bielefeld.DE 2011-01-28 15:15:37 UTC
Is this going to be fixed for 4.6.0 or should we XFAIL the test?  This
PR has been open for 5 months now.

	Rainer
Comment 14 Richard Biener 2011-01-28 15:19:23 UTC
The test is invalid on i[345]86-*-* without also enabling -msse.  A fix is to
add

/* { dg-options "-msse" { target i[345]86-*-* } } */

probably also for x86_64 with -m32.  Or simply unconditionally as it is a
x86 specific test anyway.

A fix for the bug would instead issue a diagnostic.
Comment 15 Dave Korn 2011-01-28 15:28:33 UTC
(In reply to comment #14)
> The test is invalid on i[345]86-*-* without also enabling -msse.

  Does the same apply to libcpp/lex.c?  i.e. Is that code invalid unless compiled with -msse2?  LTO bootstrap with arch=i686,tune=generic was still broken last time I checked.
Comment 16 rguenther@suse.de 2011-01-28 15:32:50 UTC
On Fri, 28 Jan 2011, davek at gcc dot gnu.org wrote:

> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45325
> 
> --- Comment #15 from Dave Korn <davek at gcc dot gnu.org> 2011-01-28 15:28:33 UTC ---
> (In reply to comment #14)
> > The test is invalid on i[345]86-*-* without also enabling -msse.
> 
>   Does the same apply to libcpp/lex.c?  i.e. Is that code invalid unless
> compiled with -msse2?  LTO bootstrap with arch=i686,tune=generic was still
> broken last time I checked.

Yes.  The code should be #ifdefed out when -msse is not enabled.

Richard.
Comment 17 Rainer Orth 2011-01-31 14:27:45 UTC
That works.  Patch submitted:

http://gcc.gnu.org/ml/gcc-patches/2011-01/msg02297.html
Comment 18 Rainer Orth 2011-01-31 14:56:35 UTC
Author: ro
Date: Mon Jan 31 14:56:31 2011
New Revision: 169440

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=169440
Log:
	PR target/45325
	* gcc.target/i386/pr38240.c: Add dg-options "-msse".

Modified:
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gcc.target/i386/pr38240.c
Comment 19 Diego Novillo 2011-02-02 18:11:44 UTC
Author: dnovillo
Date: Wed Feb  2 18:11:36 2011
New Revision: 169720

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=169720
Log:
	PR target/45325
	* gcc.target/i386/pr38240.c: Add dg-options "-msse".

Modified:
    branches/google/integration/gcc/testsuite/ChangeLog
    branches/google/integration/gcc/testsuite/gcc.target/i386/pr38240.c
Comment 20 Jakub Jelinek 2011-03-25 19:53:17 UTC
GCC 4.6.0 is being released, adjusting target milestone.
Comment 21 Jakub Jelinek 2011-06-27 12:33:15 UTC
GCC 4.6.1 is being released.
Comment 22 Jakub Jelinek 2011-10-26 17:14:07 UTC
GCC 4.6.2 is being released.
Comment 23 Jakub Jelinek 2012-03-01 14:39:27 UTC
GCC 4.6.3 is being released.
Comment 24 Jakub Jelinek 2013-04-12 15:17:10 UTC
GCC 4.6.4 has been released and the branch has been closed.
Comment 25 Richard Biener 2014-06-12 13:47:46 UTC
The 4.7 branch is being closed, moving target milestone to 4.8.4.
Comment 26 Jakub Jelinek 2014-12-19 13:30:50 UTC
GCC 4.8.4 has been released.
Comment 27 Jakub Jelinek 2015-02-24 10:46:29 UTC
The ICE is gone with r220609 aka PR61925 fix.
Comment 28 Richard Biener 2015-06-23 08:19:39 UTC
The gcc-4_8-branch is being closed, re-targeting regressions to 4.9.3.
Comment 29 Jakub Jelinek 2015-06-26 19:55:46 UTC
GCC 4.9.3 has been released.
Comment 30 Richard Biener 2016-08-03 08:18:21 UTC
Fixed in GCC 5+.