public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* optimization/9723: With -Os optimization increases size if the loop contains array element access
@ 2003-02-17 15:26 gertom
  0 siblings, 0 replies; only message in thread
From: gertom @ 2003-02-17 15:26 UTC (permalink / raw)
  To: gcc-gnats

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 3919 bytes --]


>Number:         9723
>Category:       optimization
>Synopsis:       With -Os optimization increases size if the loop contains array element access
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          pessimizes-code
>Submitter-Id:   net
>Arrival-Date:   Mon Feb 17 15:26:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     Tamás Gergely
>Release:        gcc version 3.3 20030210 (prerelease)
>Organization:
>Environment:
BUILD & HOST: Linux 2.4.20 i686 unknown
TARGET: arm-unknown-elf
>Description:
When an array element is accessed in a loop, gcc makes the following optimization: it counts the address of the first array element before the loop, and then in/decreases this value by the element size within the loop. This makes the loop faster and shorter than in the case of -O1, but the overall size increases (as opposit to the purpose of -Os).

Compare the result of arm-elf-gcc -S -g0 -Os with the output created using arm-elf-gcc -S -g0 -O1. GCC should produce the later kind of output with -Os.
>How-To-Repeat:
arm-elf-gcc -S -g0 -Os

// 01.c:

# 1 "01.c"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "01.c"
typedef struct {
        int si1;
        short ss1;
        char sc1;
        int si2;
        char sc2;
        short ss2;
        short ss3;
} st;

int f1(st* p, int c, int n)
{
  int i;
  for (i = c-1; i >= 0; i--) {
    if (p[i].si1 == n) {
      return 1;
    }
  }
  return 0;
}
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/x-gzip; name="array-in-loop.tar.gz"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="array-in-loop.tar.gz"

H4sIAKvWUD4AA+2YCVATVxjHo3htoDMe6Kh4PEEqERJ3k0DkSHRwkKIUU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++yhyzfJ0fEOCU47Uw+
p9WM77XzaUn5muSJ1XGbgg53+byiOGXY1MErPlYVdyk/4CiTT5IhaHnhhemPFw05m3hs/cLn53p5
OC2/n3t9mS+eVjpvx9HKZRG5N0ZHigb19F09c7hDoGVB3beOqnyX9PjwzFEuwbP6d/fsVx50WvHj
0pA849xtj5wzsz7df2O9o3LXhR3dZlND7xVl1E2dP+ux9/HA/tces3nFwSNu1ASEF+Y4Ng7wjCo8
cHpDZUHl8B2quMNl1RFhs6btxlaEpM3oW9Y1q3cS26VrWNZ4U8OxkKUD0osLjzvPVA3rkTU59KBy
z62idPeG2mtF1VVJyMWb9fWWfkVFO45fqe6xPPvZuFGavBbTqiWrHF3zWhZfb9pXflT2+2d1TZtb
KscenKXZ22/XxtqqzbVhk34Yuco532HBdh9if9D0IpEyYWvFSU3Oo5pRPSNq5p8t6PO1Yp+muyIn
lTTOcA/e2nh+7c25pWdyj4lye+SrUpEy1ZOh7mnIXl9htuXWSWZKSga5rUmfnKzK/nmOOO/YmcH1
frlRnsGx6bcH45fvB45tfpF+f3tFwYyskeu2JBy+HTt6ZZ9h8nDN/ROZkZuwolTPX1JXF0UvmxL0
bEOLKTTl9K/VVZf60i8ulJnXuVTMq9ld41MY/Ylf0mEnl+KH9ftezvkjM6h48gOnirDw9fii57VX
u+U0OwcG5ozc0+27lFsZd7aIVIOa5+vQlzO/ym9JUTVZFJGWh8uP5LYExyYdH0E1tOxviD4xxaKs
bbTcnBMzML2nRXD2kmToilsPvHudjpr6qHqJeszd7edK8pvdrtwb55Tf3Nh1w4pTTy+UjKu7vrj7
GLfrsz1OJoDfjoaHVS558o3nkUivAatLYwteHwJKYyZ96VIn8Hjf4voAoAlcoyc6do93nf9QRdv/
P5gcs57/pFL+/Ncp4LReTFBasU6tBuJpQKxDgTicAfA4SH4kfOskZp9835Xz8PDw8PDw8PDw8PDw
8PDw8PDwvIu/AE7esL8AKAAA


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2003-02-17 15:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-02-17 15:26 optimization/9723: With -Os optimization increases size if the loop contains array element access gertom

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).