This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Optimize "a || b" into "(a | b) != 0"
- From: Alexandre Oliva <aoliva at redhat dot com>
- To: Roger Sayle <roger at eyesopen dot com>
- Cc: <gcc-patches at gcc dot gnu dot org>
- Date: 18 May 2002 03:48:08 -0300
- Subject: Re: [PATCH] Optimize "a || b" into "(a | b) != 0"
- Organization: GCC Team, Red Hat
- References: <Pine.LNX.4.33.0205172105190.19323-100000@www.eyesopen.com>
On May 18, 2002, Roger Sayle <roger@eyesopen.com> wrote:
> The following patch converts "(a != 0) || (b != 0)" into the
> equivalent "(a | b) != 0" and converts "(a == 0) && (b == 0)"
> into the equivalent "(a | b) == 0". These transformations are
> only applied when BRANCH_COST >= 2 and "b" can be evaluated
> unconditionally and its operands are simple.
These transformations are only valid if b is guaranteed not to have
side effects nor trap. Think short circuiting, when the first test
guarantees the second won't invoke undefined behavior. If you apply
the transformation, you may break valid programs, unless there's some
code not shown in the patch context that rules out such complex
expressions.
--
Alexandre Oliva Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist Professional serial bug killer