Bug 34916 - [4.3/4.4 Regression] gcc.c-torture/execute/pr27364.c fails with -O1, -O2 and -Os
Summary: [4.3/4.4 Regression] gcc.c-torture/execute/pr27364.c fails with -O1, -O2 and -Os
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.3.0
: P5 normal
Target Milestone: 4.3.1
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2008-01-21 23:55 UTC by Paulo Marques
Modified: 2008-04-12 15:38 UTC (History)
4 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: avr-*-*
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2008-04-04 22:34:34


Attachments
Combine pass RTL dump file (1.44 KB, text/plain)
2008-01-22 00:23 UTC, Andy Hutchinson
Details
dce pass RTL dump file (bfore combine) (2.26 KB, text/plain)
2008-01-22 00:26 UTC, Andy Hutchinson
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Paulo Marques 2008-01-21 23:55:54 UTC
This test case fails with latest gcc 4.3.0. The test assumes 32 bit integers, but even after changing the constants to long, it produces incorrect results.

With -O2 we get this:

int f(unsigned number_of_digits_to_use)
{
 if (number_of_digits_to_use > 1294)
206:        65 e0               ldi        r22, 0x05        ; 5
208:        8f 30               cpi        r24, 0x0F        ; 15
20a:        96 07               cpc        r25, r22
20c:        c0 f4               brcc        .+48             ; 0x23e <f+0x38>
   return 0;
 return ((number_of_digits_to_use * 3321928L) / 1000000L + 1) /16;
20e:        bc 01               movw        r22, r24
210:        80 e0               ldi        r24, 0x00        ; 0
212:        90 e0               ldi        r25, 0x00        ; 0
214:        0e 94 6c 06         call        0xcd8        ; 0xcd8 <__mulsi3>
[...]

It "forgets" to load r18:r19:r20:r21 with 3321928 before calling __mulsi3.
Comment 1 Andy Hutchinson 2008-01-22 00:23:02 UTC
Created attachment 14991 [details]
Combine pass RTL dump file
Comment 2 Andy Hutchinson 2008-01-22 00:26:19 UTC
Created attachment 14992 [details]
dce pass RTL dump file (bfore combine)

Posted two RTL dump file of smaller testcase:


long f2(long number_of_digits_to_use)
{

  return ( number_of_digits_to_use * 11L ) ;
}

This faile GCC head 4.3.0 of 13/12/2007

Combine decide load of constant is not needed. Seem to happen after combine tries combining load with multiply (ie multiply by constant).
Comment 3 Andy Hutchinson 2008-01-22 00:52:44 UTC
Assembler of short testcase. Constant load (11L) missing

  16               	.Ltext0:
  17               	.global	f2
  19               	f2:
  20               	.LFB2:
  21               	.LM1:
  22               	.LVL0:
  23               	/* prologue: function */
  24               	/* frame size = 0 */
  25               	.LM2:
  26 0000 0E94 0000 		call __mulsi3
  27               	.LVL1:
  28               	/* epilogue start */
  29               	.LM3:
  30 0004 0895      		ret
  31               	.LFE2:
  57               	.Letext0:
DEFINED SYMBOLS
Comment 4 Andy Hutchinson 2008-01-22 23:41:53 UTC
The WRONG CODE is still present on 4.3.0 20080121  HEAD. 
This is a regresssion from 4.2 (A big one too!)

4.2.2 20071221 (Winavr) OK
4.3.0 20071213 FAILS
4.3.0 HEAD 20080121  FAILS

vr-gcc -c -mmcu=atmega128  -g -w  -Q -O2 -DSTACK_SIZE=400 -da  -DNO_TRAMPOLINES -fno-show-column  -DSIGNAL_SUPPRESS -lm -Wa,-adhlns=xpr27364.lst -lm  -std=gnu99 xpr27364.c -o xpr27364.o
Comment 5 Paulo Marques 2008-01-23 03:31:31 UTC
I just found out another data point: this happens when you pass -mmcu=atmega128, but not if you pass -mmcu=attiny13 (for instance).
Comment 6 Manuel López-Ibáñez 2008-01-23 18:37:51 UTC
Regressions should have a target milestone
Comment 7 Joseph S. Myers 2008-03-15 00:42:26 UTC
Update milestone after 4.3.0 release.
Comment 8 Andy Hutchinson 2008-03-15 23:40:16 UTC
This appear to be same bug where  combine is erroneously assuming all DF register references are to different instructions. So it tries combining instructions with themselves and stuff gets lost.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35519

The above testcase still fails with gcc version 4.4.0 20080305.

However, with patch from PR35519 it produces correct code:

  23               	/* prologue: function */
  24               	/* frame size = 0 */
  25               	.LM2:
  26 0000 2BE0      		ldi r18,lo8(11)
  27 0002 30E0      		ldi r19,hi8(11)
  28 0004 40E0      		ldi r20,hlo8(11)
  29 0006 50E0      		ldi r21,hhi8(11)
  30 0008 0E94 0000 		call __mulsi3
  31               	.LVL1:
  32               	/* epilogue start */
  33               	.LM3:
  34 000c 0895      		ret



Comment 9 Andy Hutchinson 2008-04-04 23:46:32 UTC
Subject: Bug 34916

Author: hutchinsonandy
Date: Fri Apr  4 23:45:46 2008
New Revision: 133920

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=133920
Log:
PR rtl-optimization/34916
PR middle-end/35519
* combine.c (create_log_links): Do not create duplicate LOG_LINKS
between instruction pairs

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/combine.c

Comment 10 Eric Weddington 2008-04-08 15:16:21 UTC
Andy, since this was a 4.3 regression is there any way we can back port this and commit it on the 4.3 branch?
Comment 11 Andy Hutchinson 2008-04-08 17:23:40 UTC
Subject: Re:  [4.3/4.4 Regression] gcc.c-torture/execute/pr27364.c
 fails with -O1, -O2 and -Os

I believe the rules allow for this after a suitable grace period.

Remind me towards end of week and I will post for approval.

Andy



-----Original Message-----
From: eric dot weddington at atmel dot com <gcc-bugzilla@gcc.gnu.org>
To: hutchinsonandy@aim.com
Sent: Tue, 8 Apr 2008 11:16 am
Subject: [Bug target/34916] [4.3/4.4 Regression] 
gcc.c-torture/execute/pr27364.c fails with -O1, -O2 and -Os




------- Comment #10 from eric dot weddington at atmel dot com  
2008-04-08 15:16
-------
Andy, since this was a 4.3 regression is there any way we can back port 
this
and commit it on the 4.3 branch?


--


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34916

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.

Comment 12 Andy Hutchinson 2008-04-09 22:51:28 UTC
Subject: Bug 34916

Author: hutchinsonandy
Date: Wed Apr  9 22:50:42 2008
New Revision: 134152

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=134152
Log:
2008-04-09 Andy Hutchinson <hutchinsonandy@aim.com>

	PR rtl-optimization/34916
	PR middle-end/35519
	* combine.c (create_log_links): Do not create duplicate LOG_LINKS
	between instruction pairs

Modified:
    branches/gcc-4_3-branch/gcc/ChangeLog
    branches/gcc-4_3-branch/gcc/combine.c

Comment 13 Andy Hutchinson 2008-04-12 15:38:08 UTC
Fixed 4.3 and 4.4