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: Richard Henderson <rth at redhat dot com>
- To: Roger Sayle <roger at eyesopen dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Fri, 31 May 2002 14:49:23 -0700
- Subject: Re: [PATCH] Optimize "a || b" into "(a | b) != 0"
- References: <Pine.LNX.4.33.0205172105190.19323-100000@www.eyesopen.com>
On Fri, May 17, 2002 at 09:48:03PM -0600, Roger Sayle wrote:
> * fold-const.c (fold_truthop): Transform "a || b" into "(a|b) != 0"
> and "!p && !q" into "(p|q) == 0" under suitable conditions.
I guess this is ok for now.
I recall that Jan mentioned implementing some of this in ifcvt which
might be better at throttling itself when the chain gets too long.
Also consider that a long chain like
int foo(int a0, int a1, int a2, int a3, int a4, int a5, int a6, int a7)
{
return a0 || a1 || a2 || a3 || a4 || a5 || a6 || a7;
}
is _not_ best implemented with a string of IORs on ia64. There the
absolute best we could do with IORs is
or t1 = a0, a1
or t2 = a2, a3
or t3 = a4, a5
or t4 = a6 a7
;;
or t1 = t1, t2
or t3 = t3, t4
;;
or t1 = t1, t3
;;
cmp.ne p6, p7 = t1, r0
;;
(do something with p6) ; 4 cycles
(At present, I don't think we'll even re-organize the compares, so
we'll wind up with an 9-cycle linear chain of IORs.)
However, it also has a feature called a parallel comparison
in which we can perform lots of comparisons on an open collector:
cmp.ne p6, p7 = r0, r0
;;
cmp.ne.or.andcm p6, p7 = a0, r0
cmp.ne.or.andcm p6, p7 = a1, r0
cmp.ne.or.andcm p6, p7 = a2, r0
cmp.ne.or.andcm p6, p7 = a3, r0
cmp.ne.or.andcm p6, p7 = a4, r0
cmp.ne.or.andcm p6, p7 = a5, r0
cmp.ne.or.andcm p6, p7 = a6, r0
cmp.ne.or.andcm p6, p7 = a7, r0
cmp.ne.or.andcm p6, p7 = a8, r0
;;
(do something with p6) ; 2 cycles
(I'm sort-of fudging here with "2", assuming that the initialization
can be folded into some free slot beforehand. Which really isn't
going out on a limb too far.)
r~