public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Ian Lance Taylor <iant@google.com>
To: Emese Revfy <re.emese@gmail.com>
Cc: gcc-help@gcc.gnu.org
Subject: Re: question about optimization and integer truncation
Date: Mon, 17 Oct 2011 21:11:00 -0000	[thread overview]
Message-ID: <mcrsjmr8gt9.fsf@coign.corp.google.com> (raw)
In-Reply-To: <4E9B35C5.4070709@gmail.com> (Emese Revfy's message of "Sun, 16	Oct 2011 21:51:33 +0200")

Emese Revfy <re.emese@gmail.com> writes:

> I have a question regarding where certain optimization takes place. Given the following code:
>
> 235         u32 string_area_size;
> 237         u32 cid_list_size;
> 239         u32 count;
> ...
> 294         cid_list_size = sizeof(struct acpica_device_id_list) +
> 295             ((count - 1) * sizeof(struct acpica_device_id)) + string_area_size;
>
>
> I get the following ssa representation:
>
> D.27638_41 = count_7 + 268435455;
> D.27639_42 = D.27638_41 * 16;
> D.27640_43 = D.27639_42 + string_area_size_4;
> cid_list_size_44 = D.27640_43 + 24;
> D.27641_45 = (acpi_size) cid_list_size_44;
>
> As you can see, the computation of (count - 1) * sizeof(...) is based on unsigned integer truncation.
> Can you tell me where exactly in gcc this optimization happens? (which file/function)

I would call it a canonicalization rather than an optimization.  It
happens in fold-const.c in fold_binary_loc.  Look for

      /* A - B -> A + (-B) if B is easily negatable.  */

Ian

      reply	other threads:[~2011-10-17 21:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-16 19:55 Emese Revfy
2011-10-17 21:11 ` Ian Lance Taylor [this message]

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=mcrsjmr8gt9.fsf@coign.corp.google.com \
    --to=iant@google.com \
    --cc=gcc-help@gcc.gnu.org \
    --cc=re.emese@gmail.com \
    /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).