Mainline bug in RTL fwprop.

Andrew MacLeod amacleod@redhat.com
Tue Mar 6 14:40:00 GMT 2007


I was working on a a patch for PR 21596, and it seems to have triggered
a bug in fwprop on x86 in mainline.

The testcase is simple:

register int *reg __asm__("%edi");
int test () { return *--reg <= 0; }


I've attached the patch for TER which changes the tree produced in
mainline from:

      reg.0 = reg;
      reg.27 = reg.0 - 4B;
      reg = reg.27;
      return *reg.27 <= 0;

to

      reg.27 = reg - 4B;
      reg = reg.27;
      return *reg.27 <= 0;

which eliminates one extraneous copy.


Going into fwprop1, the rtl looks like:

    (insn 7 5 8 2 (parallel [
		(set (reg:SI 58 [ reg.27 ])
		    (plus:SI (reg/v:SI 5 di [ reg ])
			(const_int -4 [0xfffffffc])))
		(clobber (reg:CC 17 flags))
	    ]) 148 {*addsi_1} (nil)
	(nil))

    (insn 8 7 9 2 (set (reg/v:SI 5 di [ reg ])
	    (reg:SI 58 [ reg.27 ])) 34 {*movsi_1} (nil)
	(nil))

    (insn 9 8 10 2 (set (reg:CCNO 17 flags)
	    (compare:CCNO (mem:SI (reg:SI 58 [ reg.27 ]) [3 S4 A32])
		(const_int 0 [0x0]))) 0 {*cmpsi_ccno_1} (nil)
	(nil))


and fwprop decides to propagate:

   (compare:CCNO (mem:SI (reg:SI 58 [ reg.27 ]) [3 S4 A32])
	  (const_int 0 [0x0]))
   with (compare:CCNO (mem:SI (plus:SI (reg/v:SI 5 di [ reg ])
		  (const_int -4 [0xfffffffc])) [3 S4 A32])
	  (const_int 0 [0x0]))

resulting in:

    (insn 7 5 8 2 (parallel [
		(set (reg:SI 58 [ reg.27 ])
		    (plus:SI (reg/v:SI 5 di [ reg ])
			(const_int -4 [0xfffffffc])))
		(clobber (reg:CC 17 flags))
	    ]) 148 {*addsi_1} (nil)
	(nil))

    (insn 8 7 9 2 (set (reg/v:SI 5 di [ reg ])
	    (reg:SI 58 [ reg.27 ])) 34 {*movsi_1} (nil)
	(nil))

    (insn 9 8 10 2 (set (reg:CCNO 17 flags)
	    (compare:CCNO (mem:SI (plus:SI (reg/v:SI 5 di [ reg ])
			(const_int -4 [0xfffffffc])) [3 S4 A32])
		(const_int 0 [0x0]))) 0 {*cmpsi_ccno_1} (nil)
	(nil))


note that it has propagated 'di - 4' past insn 8 which sets di to di
-4. 

The compare in insn 9 is now comparing an additional -4 offset to di,
which is wrong.

It would be really sweet if we propagated the 'di - 4' into insn 8, then
recognized that di is now the value of SI 58, and propagated di into the
compare.  insn 7 would be dead and we'd get the code the PR is looking
for :-)
 
Andrew

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 21596.diff
Type: text/x-patch
Size: 1958 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc/attachments/20070306/437f911b/attachment.bin>


More information about the Gcc mailing list