Bug 17791 - [4.0 Regression] doloop can produce wrong code causes Ada bootstrap failure
Summary: [4.0 Regression] doloop can produce wrong code causes Ada bootstrap failure
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 4.0.0
: P2 critical
Target Milestone: 4.0.0
Assignee: Zdenek Dvorak
URL:
Keywords: build, patch, wrong-code
Depends on: 17787
Blocks:
  Show dependency treegraph
 
Reported: 2004-10-02 02:55 UTC by Andrew Pinski
Modified: 2005-07-23 22:49 UTC (History)
2 users (show)

See Also:
Host:
Target: powerpc-*-*
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Pinski 2004-10-02 02:55:05 UTC
After fixing PR 17790, I noticed that Ada still does not bootstrap and looked into it and noticed that 
doloop is causing wrong code:
The RTL looks like:
(insn 334 333 429 27 /Volumes/UFS_Partition/pinskia/src/devel/new-fold/gcc/gcc/ada/csets.adb:
1151 (set (reg:SI 118 [ ivtmp.7 ])
        (const_int 255 [0xff])) 332 {*movsi_internal1} (nil)
    (nil))
...
(insn 359 358 360 28 /Volumes/UFS_Partition/pinskia/src/devel/new-fold/gcc/gcc/ada/csets.adb:
1151 (set (reg:SI 278)
        (plus:SI (reg:SI 118 [ ivtmp.7 ])
            (const_int -1 [0xffffffffffffffff]))) -1 (nil)
    (nil))

(insn 360 359 361 28 /Volumes/UFS_Partition/pinskia/src/devel/new-fold/gcc/gcc/ada/csets.adb:
1151 (set (reg:SI 118 [ ivtmp.7 ])
        (zero_extend:SI (subreg:QI (reg:SI 278) 3))) -1 (nil)
    (nil))

(note 361 360 362 28 ("/Volumes/UFS_Partition/pinskia/src/devel/new-fold/gcc/gcc/ada/
csets.adb") 1150)

(insn 362 361 363 28 /Volumes/UFS_Partition/pinskia/src/devel/new-fold/gcc/gcc/ada/csets.adb:
1150 (set (reg:CC 279)
        (compare:CC (reg:SI 118 [ ivtmp.7 ])
            (const_int 0 [0x0]))) -1 (nil)
    (nil))
Comment 1 Andrew Pinski 2004-10-02 02:59:45 UTC
I should say that the loop gets turned into a loop which starts at (unsigned)-1 and goes down to 0 
which is wrong.
Comment 2 Andrew Pinski 2004-10-02 03:00:16 UTC
s/17790/17787.
Comment 3 Andrew Pinski 2004-10-02 05:09:43 UTC
I was able to past the part which I was failing when I reported this bug on powerpc-apple-darwin with 
the patch for PR 17787 and with BOOT_CFLAGS="-O2 -g -fno-branch-count-reg" so I think doloop is 
the last bootstrap problem with Ada.
Comment 4 Andrew Pinski 2004-10-03 17:47:30 UTC
I hear that this also happens on powerpc-linux and using -fno-branch-count-reg fixes the problem 
there too.
Comment 5 Zdenek Dvorak 2004-10-03 21:44:46 UTC
Doloop tries to interpret number of iterations that is computed in QImode
in SImode, which causes problems since # of iterations is constant, does not
contain information about its mode and gets missinterpreted.

I am testing the patch.
Comment 6 Zdenek Dvorak 2004-10-04 06:56:57 UTC
Patch:

http://gcc.gnu.org/ml/gcc-patches/2004-10/msg00228.html
Comment 7 GCC Commits 2004-10-07 06:20:40 UTC
Subject: Bug 17791

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	rakdver@gcc.gnu.org	2004-10-07 06:20:35

Modified files:
	gcc            : ChangeLog loop-doloop.c loop-iv.c rtl.h 

Log message:
	PR rtl-optimization/17791
	* loop-doloop.c (doloop_modify): Take number of iterations as
	argument.
	(doloop_optimize): Extend or shorten the number of iterations
	when changing mode of counter register.
	* loop-iv.c (lowpart_subreg): Export.
	* rtl.h (lowpart_subreg): Declare.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.5778&r2=2.5779
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/loop-doloop.c.diff?cvsroot=gcc&r1=2.9&r2=2.10
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/loop-iv.c.diff?cvsroot=gcc&r1=2.20&r2=2.21
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/rtl.h.diff?cvsroot=gcc&r1=1.512&r2=1.513

Comment 8 Zdenek Dvorak 2004-10-07 06:21:20 UTC
Fixed.