This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: question about optimization and integer truncation
- From: Ian Lance Taylor <iant at google dot com>
- To: Emese Revfy <re dot emese at gmail dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Mon, 17 Oct 2011 14:10:58 -0700
- Subject: Re: question about optimization and integer truncation
- References: <4E9B35C5.4070709@gmail.com>
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