[gnu.gcc.bug] extra labels not optimized away

Raeburn@ATHENA.MIT.EDU (Ken Raeburn) (03/01/90)

(1.37,vax)

Source file:

    extern int i;
    int foo (void) {
	switch (i) {
	case 2:
	    i = 12;
	    return 9;
	case 1:
	    i = 3;
	    return 9;
	case 3:
	    i = 3;
	    return 9;
	default:
	    i = 3;
	    return 9;
	}
    }

Assembly code produced with "-O -fcombine-regs -fstrength-reduce
-fforce-mem" (our default -O configuration for vax):

	#NO_APP
	gcc_compiled.:
	.text
		.align 1
	.globl _foo
	_foo:
		.word 0x0
		movl _i,r0
		cmpl r0,$2
		jeql L2
		jleq L5
		cmpl r0,$3	# unnecessary distinction
		jeql L4
		jbr L5
	L2:
		movl $12,_i
		movl $9,r0
		ret
	L4:			# no code between labels
	L5:
		movl $3,_i
		movl $9,r0
		ret

In the case where `I' is 3 (but not 1), extra comparison code is
generated, and two branches -- one conditional, one unconditional --
transfer to the same instruction regardless of the comparison result.

This doesn't happen in all cases; in fact, in most cases (like `1'
above), the extra labels and code are removed.  However, there are
some pieces of code (with lots of labels, not switch statements) not
entirely unlike this in gcc's own insn-recog routines (vax version),
for example, so it may improve the compiler itself to fix this.