Bug 15340 - [3.4 Regression] GCC internal error in preprocessed C code
Summary: [3.4 Regression] GCC internal error in preprocessed C code
Status: RESOLVED WONTFIX
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 3.4.0
: P3 normal
Target Milestone: 3.3.3
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2004-05-07 19:56 UTC by dawalker@uiuc.edu
Modified: 2006-02-28 09:17 UTC (History)
2 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work: 3.0.4 4.0.0
Known to fail: 3.2.2 3.2.3 3.4.0
Last reconfirmed: 2006-01-06 15:25:01


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description dawalker@uiuc.edu 2004-05-07 19:56:26 UTC
	GCC throws an internal compiler error on the following code when run with optimizations. Bug exists in 3.2, 3.3, and 3.4.

Environment:
System: Linux mrbean 2.6.1 #1 Wed Jan 21 16:45:49 CST 2004 i686 GNU/Linux
Architecture: i686
    libc: 2.3.2.ds1-12 (Debian)
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
Configured with: ./configure --enable-languages=c --enable-shared --with-system-zlib --enable-nls --without-included-gettext --enable-debug

How-To-Repeat:
Here's the command-line I ran with output:
davedude@mrbean:/usr/src/gcc-3.4.0/gcc$ ./xgcc -B. -v -O2 -fno-strict-aliasing ~/c/uiuc/cs348/mp6/bug.i
Reading specs from ./specs
Configured with: ./configure --enable-languages=c --enable-shared --with-system-zlib --enable-nls --without-included-gettext --enable-debug
Thread model: posix
gcc version 3.4.0
 ./cc1 -fpreprocessed /home/davedude/c/uiuc/cs348/mp6/bug.i -quiet -dumpbase bug.i -mtune=pentiumpro -auxbase bug -O2 -version -fno-strict-aliasing -o /tmp/ccOtjqJK.s
GNU C version 3.4.0 (i686-pc-linux-gnu)
        compiled by GNU C version 3.3.3 (Debian 20040401).
GGC heuristics: --param ggc-min-expand=47 --param ggc-min-heapsize=32090
bug.c: In function `main':
bug.c:20: error: insn does not satisfy its constraints:
(insn:HI 41 40 53 2 (set (reg/v:SI 3 bx [orig:74 y ] [74])
        (sign_extend:SI (mem/s/j:QI (mult:SI (plus:SI (reg/f:SI 6 bp)
                        (const_int -13 [0xfffffff3]))
                    (const_int 2 [0x2])) [0 dir S1 A8]))) 86 {extendqisi2} (nil)
    (nil))
bug.c:20: internal compiler error: in reload_cse_simplify_operands, at postreload.c:378
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.

Here's bug.i:

# 1 "bug.c"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "bug.c"
int globl;

void dummy(char arg)
{
    globl = arg;
}

int main(int argc, char *argv[])
{
    char dir[1];
    int y = 0, best;

    while (y > *argv[0])
    {
        best = (int)dir;
        y = dir[best];
        dummy(*argv[1|best]);
    }
    return 0;
}
Comment 1 dawalker@uiuc.edu 2004-05-07 19:56:26 UTC
Fix:
	Bug only appears with optimizations on. Also, this is as small as I could make
	the bug. Most changes to the above code will remove the problem. Although the
	code is obviously artificial, the problem did crop up in real code originally.
Comment 2 Andrew Pinski 2004-05-08 03:41:15 UTC
Confirmed.
Comment 3 Giovanni Bajo 2004-06-06 03:57:28 UTC
Retargeting to 3.4.1, being a regression on that release branch.
Comment 4 roger 2004-06-22 12:47:20 UTC
This looks to be a bug in reload, or a problem with the x86 backend's constraint
matching.

In .19.life, we have

(insn 38 33 39 2 (set (reg:QI 84)
        (mem/s:QI (plus:SI (reg/f:SI 93)
                (reg/f:SI 93)) [0 dir S1 A8])) 46 {*movqi_1} (nil)
    (nil))

(insn 39 38 42 2 (set (reg/v:SI 63 [ y ])
        (sign_extend:SI (reg:QI 84))) 86 {extendqisi2} (insn_list 38 (nil))
    (expr_list:REG_DEAD (reg:QI 84)
        (nil)))

These get smushed in combine, but I believe are stiil valid in .20.combine

(insn 39 38 42 2 (set (reg/v:SI 63 [ y ])
        (sign_extend:SI (mem/s:QI (mult:SI (reg/f:SI 93)
                    (const_int 2 [0x2])) [0 dir S1 A8]))) 86 {extendqisi2} (nil)
    (nil))

But everything goes to hell in reload, as we consider substituting pseduo 93
for "(plus (reg/f:SI bp) (const_int -13))", producing this monster in .26.greg

Reloads for insn # 39
Reload 0: reload_in (QI) = (mem/s:QI (mult:SI (plus:SI (reg/f:SI 6 bp)
  (const_int -13 [0xfffffff3])) (const_int 2 [0x2])) [0 dir S1 A8])
        Q_REGS, RELOAD_FOR_INPUT (opnum = 1), optional
        reload_in_reg: (mem/s:QI (mult:SI (plus:SI (reg/f:SI 6 bp)
  (const_int -13 [0xfffffff3])) (const_int 2 [0x2])) [0 dir S1 A8])


(insn:HI 39 38 42 2 (set (reg/v:SI 3 bx [orig:63 y ] [63])
        (sign_extend:SI (mem/s:QI (mult:SI (plus:SI (reg/f:SI 6 bp)
                        (const_int -13 [0xfffffff3]))
                    (const_int 2 [0x2])) [0 dir S1 A8]))) 86 {extendqisi2} (nil)
    (nil))
Comment 5 Andrew Pinski 2004-06-24 21:17:55 UTC
Patch here: <http://gcc.gnu.org/ml/gcc-patches/2004-06/msg01980.html>.
Comment 6 Steven Bosscher 2004-08-12 08:14:38 UTC
rth commented on the patch and the discussion died out.  Suggestions? 
 
Comment 7 Mark Mitchell 2004-08-29 18:12:11 UTC
Postponed until GCC 3.4.3.
Comment 8 Mark Mitchell 2004-08-29 18:14:47 UTC
Postponed until GCC 3.4.3.
Comment 9 Richard Henderson 2004-09-13 09:25:53 UTC
No ICE on mainline as of 2004-09-12.
Comment 10 Andrew Pinski 2004-09-27 04:12:16 UTC
Patch keyword removed as the patch was rejected by RTH.
Comment 11 Mark Mitchell 2004-11-01 00:46:39 UTC
Postponed until GCC 3.4.4.
Comment 12 Gabriel Dos Reis 2006-02-28 09:17:17 UTC
Works in 4.0 and up.  Won't fix for 3.4.6