On sh-elf, the function foo in 20010422-1.c unsigned int foo(unsigned int x) { if (x < 5) x = 4; else x = 8; return x; }
is compiled to foo: mov.l r14,@-r15 mov r15,r14 mov #4,r1 cmp/hi r1,r1 bf/s .L6 mov #4,r0 mov #8,r0 .L6: mov r14,r15 mov.l @r15+,r14 rts nop with -O1. Thus the first parameter register r4 is ignored. For mips-elf, foo is assembled to foo: .frame $sp,0,$31 # vars= 0, regs= 0/0, args= 0, gp= 0 .mask 0x00000000,0 .fmask 0x00000000,0 .set noreorder .set nomacro sltu $2,$2,5 beq $2,$0,$L2 nop ... with -O1 where $4 should be register for x. It started after the patch r119711 | amacleod | 2006-12-11 06:25:40 +0900 (Mon, 11 Dec 2006) | 103 lines and the first tree dump which differs before and after this patch is .099t.optimized: [r119710 .099t.optimized] ;; Function foo (foo) Analyzing Edge Insertions. foo (x) { unsigned int x.24; <bb 2>: if (x <= 4) goto <L5>; else goto <L4>; <L5>:; x.24 = 4; goto <bb 4> (<L2>); <L4>:; x.24 = 8; <L2>:; return x.24; } [r119711 .099t.optimized] ;; Function foo (foo) Analyzing Edge Insertions. foo (x) { unsigned int x.24; <bb 2>: if (x.24 <= 4) goto <L5>; else goto <L4>; <L5>:; x = 4; goto <bb 4> (<L2>); <L4>:; x = 8; <L2>:; return x; } -- Summary: [4.3 Regression] gcc.c-torture/execute/20010422-1.c is miscompiled on sh-elf and mips-elf Product: gcc Version: 4.3.0 Status: UNCONFIRMED Keywords: wrong-code Severity: normal Priority: P3 Component: tree-optimization AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: kkojima at gcc dot gnu dot org GCC build triplet: i686-pc-linux-gnu GCC host triplet: i686-pc-linux-gnu GCC target triplet: sh-elf, mips-elf http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30159