11557 – [3.3 regression] constant folding (original) (raw)

Description Gwenole Beauchesne 2003-07-17 09:24:52 UTC

The following testcase fails at -O & -O2. This is a regression from 3.2.3 present on all 3.3 branches (2003/07/16) and at least AMD64 & IA-32. At this optimization level i == 0 is assumed and only a call to zero() is generated.

extern void abort (void);

int zero (void) { return 0; }

int one (void) { return 1; }

int main (void) { int i = 1; int r = (i ? one : zero)(); if (r != 1) abort(); return 0; }

Comment 1 Drea Pinski 2003-07-17 12:42:05 UTC

I can confirm this on 3.3.1 (20030707). On the mainline (20030717), it is already fixed. In fact the rtl is wrong at the begining (pr11557.c.00.rtl). (insn 12 10 16 (nil) (set (reg/v:SI 61) (const_int 1 [0x1])) -1 (nil) (nil))

(insn 16 12 20 (nil) (set (reg:SI 63) <----- the same reg as (symbol_ref:SI ("one"))) -1 (nil) (nil))

(insn 20 16 14 (nil) (set (reg:SI 63) <------ this one (symbol_ref:SI ("zero"))) -1 (nil) (nil))

<--- so 63 = zero

(insn 14 20 15 (nil) (set (reg:CCZ 17 flags) (compare:CCZ (reg/v:SI 61) (const_int 0 [0x0]))) -1 (nil) (nil))

(jump_insn 15 14 17 (nil) (set (pc) (if_then_else (eq (reg:CCZ 17 flags) (const_int 0 [0x0])) (label_ref 19) (pc))) -1 (nil) (nil))

(jump_insn 17 15 18 (nil) (set (pc) (label_ref 21)) -1 (nil) (nil))

(barrier 18 17 19)

(code_label 19 18 21 4 "" [0 uses])

(code_label 21 19 22 5 "" [0 uses])

(call_insn/u 22 21 23 (nil) (set (reg:SI 0 eax) (call (mem:QI (reg:SI 63) [0 S1 A8]) <---- call reg 63 which is zero always (const_int 0 [0x0]))) -1 (nil) (expr_list:REG_EH_REGION (const_int -1 [0xffffffff]) (nil)) (nil))

Comment 2 Drea Pinski 2003-07-17 12:44:00 UTC

I forgot to say I can confirm this worked in 3.2.3.

Comment 5 Mark Mitchell 2003-07-18 03🔞23 UTC

Fixed in GCC 3.3.1 and GCC 3.4.

Comment 6 Drea Pinski 2003-09-09 17:56:38 UTC

*** Bug 12227 has been marked as a duplicate of this bug. ***