🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #2919

superfluous assignment not removed

#2919
From: Ken Raeburn
Date: Wed, 28 Feb 1990 21:40
43 lines
1501 bytes
(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.
Technical Details
Message-ID: <9002282140.AA12518@prometheus.MIT.EDU>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!bu.edu!snorkelwacker!tut.cis.ohio-state.edu!ATHENA.MIT.EDU!Raeburn

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!bu.edu!snorkelwacker!tut.cis.ohio-state.edu!ATHENA.MIT.EDU!Raeburn
From: Raeburn@ATHENA.MIT.EDU (Ken Raeburn)
Newsgroups: gnu.gcc.bug
Subject: superfluous assignment not removed
Message-ID: <9002282140.AA12518@prometheus.MIT.EDU>
Date: 28 Feb 90 21:40:10 GMT
Sender: daemon@tut.cis.ohio-state.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 43