Bug 11965 - [3.3/3.4 Regression] invalid assembler code for a shift << 32 operation
Summary: [3.3/3.4 Regression] invalid assembler code for a shift << 32 operation
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 3.3
: P2 normal
Target Milestone: 3.3.2
Assignee: Eric Botcazou
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2003-08-18 12:41 UTC by jk
Modified: 2004-01-17 04:22 UTC (History)
2 users (show)

See Also:
Host: sparc-sun-solaris2.8
Target: sparc-sun-solaris2.8
Build: sparc-sun-solaris2.8
Known to work:
Known to fail:
Last reconfirmed:


Attachments
sparc.md patch (557 bytes, patch)
2003-08-19 19:01 UTC, Martin Husemann
Details | Diff
revised patch (738 bytes, patch)
2003-09-05 11:12 UTC, Martin Husemann
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description jk 2003-08-18 12:41:33 UTC
GCC 3.3 on Solaris SPARC produces invalid assembler code, for shift operator
shifting 32 bits.

GCC 3.3 is compiled to use the system's assembler, /usr/ccs/bin/as


To reproduce the issue (admitted, this code has undefined behaviour):

% cat shift.c

#if __GNUC__
#define ATTR_ALWAYS_INLINE __attribute__ ((__always_inline__))
#else
#define ATTR_ALWAYS_INLINE
#endif


static ATTR_ALWAYS_INLINE unsigned
put_bits(int n, unsigned int value)
{
        return value << n;
}

main()
{
        unsigned val = 1;
        int i;

        for (i = 0; i < 4; i++)
                val = put_bits(32, val);

        printf("val=%x\n", val);
}

% gcc -O3 -mcpu=ultrasparc -o shift shift.c
/usr/ccs/bin/as: "/tmp/cc0VFu29.s", line 20: error: shift count negative or too
big: 32


Looking at the generated assembler source...

% gcc -O3 -mcpu=ultrasparc -S shift.c

... there's a shift instruction with a constant shift count of 32, where the
immediate shift count is restricted to the range 0 .. 31 on SPARC:

       sll     %o1, 32, %o1


The same code used to compile with gcc 3.2 and erlier, and it does compile with
gcc 3.3 at optimization level -O2 or when option -mcpu=ultrasparc is not used.
Comment 1 Falk Hueffner 2003-08-18 17:35:27 UTC
I can reproduce this on Sparc Linux with gcc 3.3.1 20030728 (Debian prerelease).
Comment 2 Martin Husemann 2003-08-19 19:01:56 UTC
Created attachment 4622 [details]
sparc.md patch

Funny, I just found + fixed this bug over the last weekend on NetBSD when
compiling XFree on sparc64.

The patch fixes it and does not cause any regressions in the testsuite. I only
tested generating 64 bit sparc code on a 64 bit sparc host, but the patch tries
to  handle the 32bit case correctly too (similar to the mips backend).
Comment 3 Martin Husemann 2003-08-19 20:04:03 UTC
Forgot to mention: I used gcc version 3.3.1.
I initially left out the 32bit changes (since that cases currently seem to not
be triggered), but Ian L. Taylor told me you can not rely on that and pointed to
the mips backends way of handling it.
Comment 4 Andrew Pinski 2003-08-23 14:24:20 UTC
This is a regression from 3.2.3 and there is even a patch.


Martin can you send the patch to gcc-patches saying this fixes this PR?
Comment 5 Martin Husemann 2003-09-05 11:12:35 UTC
Created attachment 4708 [details]
revised patch

This is a simplified version that also addresses the same issue in other shift
instruction patterns.
Comment 6 Eric Botcazou 2003-09-09 14:51:08 UTC
I'll bootstrap/regtest it for SPARC and SPARC64 on the 3.3 branch and install it.
Comment 7 GCC Commits 2003-09-10 12:59:41 UTC
Subject: Bug 11965

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	ebotcazou@gcc.gnu.org	2003-09-10 12:59:36

Modified files:
	gcc            : ChangeLog 
	gcc/config/sparc: sparc.c sparc.md 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.dg: ultrasp10.c 

Log message:
	PR target/11965
	* config/sparc/sparc.c (sparc_v8plus_shift): Protect against
	constants greater than 63.
	* config/sparc/sparc.md (ashlsi3, ashrsi3, lshrsi3): Protect
	against constants greater than 31.
	(*ashldi3_sp64, *ashrdi3_sp64, *lshrdi3_sp64): Protect against
	constants greater than 63.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.1022&r2=2.1023
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/sparc/sparc.c.diff?cvsroot=gcc&r1=1.258&r2=1.259
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/sparc/sparc.md.diff?cvsroot=gcc&r1=1.190&r2=1.191
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.3047&r2=1.3048
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/ultrasp10.c.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 8 GCC Commits 2003-09-10 13:04:02 UTC
Subject: Bug 11965

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_3-branch
Changes by:	ebotcazou@gcc.gnu.org	2003-09-10 13:04:00

Modified files:
	gcc            : ChangeLog 
	gcc/config/sparc: sparc.c sparc.md 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.dg: ultrasp10.c 

Log message:
	PR target/11965
	* config/sparc/sparc.c (sparc_v8plus_shift): Protect against
	constants greater than 63.
	* config/sparc/sparc.md (ashlsi3, ashrsi3, lshrsi3): Protect
	against constants greater than 31.
	(*ashldi3_sp64, *ashrdi3_sp64, *lshrdi3_sp64): Protect against
	constants greater than 63.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.16114.2.734&r2=1.16114.2.735
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/sparc/sparc.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.233.4.5&r2=1.233.4.6
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/sparc/sparc.md.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.181.4.6&r2=1.181.4.7
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.2261.2.276&r2=1.2261.2.277
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/ultrasp10.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=NONE&r2=1.1.2.1

Comment 9 Eric Botcazou 2003-09-10 13:05:45 UTC
Done.