This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Does gcc optimize "if (constant)" inside while loops?
- From: Andrew Haley <aph at redhat dot com>
- To: Timur Tabi <timur at freescale dot com>
- Cc: gcc-help <gcc-help at gcc dot gnu dot org>
- Date: Tue, 05 May 2009 11:03:12 +0100
- Subject: Re: Does gcc optimize "if (constant)" inside while loops?
- References: <ed82fe3e0905041229m7ff9f020j95664a41338c373a@mail.gmail.com>
Timur Tabi wrote:
> I have this code:
>
> #define spin_event_timeout(condition, timeout, delay, rc) \
> { \
> unsigned long __loops = tb_ticks_per_usec * timeout; \
> unsigned long __start = get_tbl(); \
> while (!(rc = (condition)) && (tb_ticks_since(__start) <= __loops)) \
> if (delay) \
> udelay(delay); \
> else \
> cpu_relax(); \
> }
>
> assuming that the 'delay' parameter is a constant, will gcc
> optimize-out the "if (delay)" when this macro is compiled?
Yes, because one of the arms of the conditional is trivially dead.
Andrew.