public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "tom at deltasystem dot hu" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/50304] poor code for accessing certain element of arrays
Date: Thu, 08 Sep 2011 13:27:00 -0000	[thread overview]
Message-ID: <bug-50304-4-VpvtxEn7HI@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-50304-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #4 from Tamas Fenyvesi <tom at deltasystem dot hu> 2011-09-08 13:16:53 UTC ---
Please find a sample code and its objdump-ed asm in the attachment.

The command line is:
arm-none-eabi-gcc -D__REDLIB__ -DDEBUG -D__USE_CMSIS -D__CODE_RED -I"../cmsis"
-I"../config" -I"../driver" -O1 -g3 -Wall -c -fmessage-length=0 -fno-builtin
-ffunction-sections -fdata-sections -mcpu=cortex-m0 -mthumb -MMD -MP
-MF"src/bugreport.d" -MT"src/bugreport.d" -o"src/bugreport.o"
"../src/bugreport.c"

Some comments:
-It is the same from -O1 up to -O3. The -O0 is worse.

-Access of an int array differs somewhat but both have adding (or relative)
operation. Access of a struct doesn't differ in anything whether or not uses a
*const.

-All (* const) should have been exist (rather than have been replaced by some
adding of two (or more) other adders). It definetely costs more (in code area)
to have some offset vector and adding code than to have a precomputed ofsetted
address (even if the base address were stored elsewhere), not to mention the
huge wasted runtime. There can appear several cascaded adding operations for
computing a single address. The code is larger and much slower, plus it needs
more register to allocate, which in turn also increase code size and required
runtime.

-Why does the compiler resolve the mode of computing the ofsetted address
instead of simply materializing a *const if the user explicitly instructs it to
hace a *const? The code can have any number of copies of *const address (as it
can't change) if it were required for e.g. a pc-relative loading. There's
simply no point in not direct materializing any *const.

-Precompiling any known addesses and adding only the variables, on the other
hand, is good practice (and not uncommon in other compilers than gcc), even
without any *const. (E.g. for "a[1][2][var]" it should precompile "a[1][2]" and
add only "var".)


  parent reply	other threads:[~2011-09-08 13:17 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-06 14:59 [Bug tree-optimization/50304] New: " tom at deltasystem dot hu
2011-09-06 16:02 ` [Bug target/50304] " rguenth at gcc dot gnu.org
2011-09-08 13:16 ` tom at deltasystem dot hu
2011-09-08 13:17 ` tom at deltasystem dot hu
2011-09-08 13:27 ` tom at deltasystem dot hu [this message]
2013-03-04  8:06 ` rearnsha at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-50304-4-VpvtxEn7HI@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).