🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Ken Raeburn Wed, 28 Feb 1990 20:12
extra labels not optimized away
#2917
Author: Ken Raeburn
Date: Wed, 28 Feb 1990 20:12
58 lines
1639 bytes
(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.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads