This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: question about optimization and integer truncation


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]