This is the mail archive of the
gcc-prs@gcc.gnu.org
mailing list for the GCC project.
optimization/9739: With -Os while and for loops can be arranged with one test instead of two
- From: lac at rgai dot hu
- To: gcc-gnats at gcc dot gnu dot org
- Date: 18 Feb 2003 09:54:23 -0000
- Subject: optimization/9739: With -Os while and for loops can be arranged with one test instead of two
- Reply-to: lac at rgai dot hu
>Number: 9739
>Category: optimization
>Synopsis: With -Os while and for loops can be arranged with one test instead of two
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: unassigned
>State: open
>Class: pessimizes-code
>Submitter-Id: net
>Arrival-Date: Tue Feb 18 10:06:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator: László Vidács
>Release: gcc version 3.3 20030210 (prerelease)
>Organization:
>Environment:
BUILD & HOST: Linux 2.4.20 i686 unknown
TARGET: arm-unknown-elf
>Description:
In the case of a while or for loop, gcc first tests whether to enter the loop or not; and at the end of the loop, it tests again whether to jump back to the beginning of the loop or not. One of these two test-and-conditional-jumps should be replaced with an unconditional jump to the other test when optimizing for size. When optimizing for speed this is not a problem.
Example (01.c): The compare and conditional return at lines 24-25 (in 01.s) are not needed, they are replaced by unconditional jump to the test (see 01_modified.s).
>How-To-Repeat:
arm-elf-gcc -S -g0 -Os
// 01.c:
# 1 "/home/alec/gcc/test/issues/_src/lac_5/01.c"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "/home/alec/gcc/test/issues/_src/lac_5/01.c"
int F()
{
return 2;
}
int main()
{
int i=F();
while (i>0)
{
i--;
}
return i;
}
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/x-gzip; name="dup-loop-tests.tar.gz"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="dup-loop-tests.tar.gz"
H4sIAMD9UT4AA+2YUWvbMBDH8+pAvoOWMkggtiXbSSBdy6CQvoztYew5KPbZFZNsI8ndutLvXsl2
zcbWdhskZUO/F0un01l34f62g0nARgcGE4xXKzzCGJP1MrFXTJLuaonXqxFer6IkMsMYW/8kiUcI
H/pglkZpKhEaFSB1JR73oxzSY5znyJwggqbhVSUgtBmGRZqGGpQOmVINqHCnZBpymu6WISZBOp2M
2x1v9g3j2mfl+WBJKyFomSHOShisfxSZlRptZ/PJ+HYyRkiCbmSJotPJ+G4y7lYFZeXgYA3szGw4
tbMvV4wDmrFzPLfT1qOD+X7rcfddVNZFfenqvzym9Orw93iy/0mEk5/7P3H9fwy8IDd94037FvQC
DV+1vVLOitKL7LDg1Z5yb9su39TgbRfodd6UqWZVORlvN2bhLaKyUOgM4QWqTZOBUYJ2kksqwA5b
p3a2KwEy6NcbBWpHy6q8EVVjRn2U1ttIyWfTsQVTGiRS9BoQcCZYSTVkgXER1bUnTZCTqPOXqA+d
V9Ico+JV0UDvV6cL42BzUOxbm0Pgb3+dqZWZIVk7+SFfa/j7lMlTKdtzsnqBVG0mSos881T9aoFu
c2O0C1yae6V3drXZew/Wk8QY9t0vlIq6K4mNxzPBAWjr2MZQdb8/eLfa9FGsd7uD/P52b++ZCEMx
uxoF/kPhWAal9qaXFxcbNLt8/2mO4iBGkXnU44hgNDPlksCBKphPnQq/JJjsRJWxnJmGOtSD4Dn9
J8to0P9lbMYkivHK6f8xcPr/n+m/Feb1o/pu1jZO5R0DEmgm4LD3eO77H9t3/k7/k8j+F0BIFEVO
/48BlcIHnvvm6xz5H5FfYOR/UK5bHQ6Hw+FwOBwOh8PhcDgcDofjX+cexh+FDQAoAAA=