This is the mail archive of the gcc-patches@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: [PATCH] Optimize "a || b" into "(a | b) != 0"


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


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