[gnu.gcc.bug] superfluous assignment not removed

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

(This is a really minor one....)

(1.37; vax; -O -fcombine-regs -fstrength-reduce -fforce-mem)

Source file:

	int foo (int ii) {
	    int i = ii;
	    if (i == 2) {
		i = 2;
	    }
	    return i;
	}

(Granted, the source file is silly; but I've seen similar code using
enumerated values or preprocessor macros with conceptually different
-- but numerically identical -- values.)

Assembly code:

	#NO_APP
	gcc_compiled.:
	.text
		.align 1
	.globl _foo
	_foo:
		.word 0x0
		movl 4(ap),r0
		cmpl r0,$2
		jneq L1
		movl $2,r0	# r0 is already 2
	L1:
		ret

According to the texinfo file, the REG_EQUAL notes are used only for
the insns that set registers, so I'm not sure how it would be tagged,
but the known value of i should be recognized inside the `then'
branch, and the assignment suppressed.

Similar results are obtained by making the comparison "!=" (in which
case it is the comparison and references to `i' and `ii' that are
superfluous, since 2 is always returned), but I expect that is
somewhat harder to optimize.