* question about optimization and integer truncation
@ 2011-10-16 19:55 Emese Revfy
2011-10-17 21:11 ` Ian Lance Taylor
0 siblings, 1 reply; 2+ messages in thread
From: Emese Revfy @ 2011-10-16 19:55 UTC (permalink / raw)
To: gcc-help
Hi,
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)
Thanks,
Emese
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: question about optimization and integer truncation
2011-10-16 19:55 question about optimization and integer truncation Emese Revfy
@ 2011-10-17 21:11 ` Ian Lance Taylor
0 siblings, 0 replies; 2+ messages in thread
From: Ian Lance Taylor @ 2011-10-17 21:11 UTC (permalink / raw)
To: Emese Revfy; +Cc: gcc-help
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-10-17 21:11 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-16 19:55 question about optimization and integer truncation Emese Revfy
2011-10-17 21:11 ` Ian Lance Taylor
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).