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: pr26026: udiv and umod optimization


> 
> Alan Modra writes:
>  > This patch optimizes code in a hot loop of a certain well known
>  > benchmark.  Sorry for being mysterious, but I'm not sure I'm allowed
>  > to publish numbers or even mention the benchmark by name since the
>  > 2006 version (where this optimization triggers) hasn't been released
>  > yet.
>  > 
>  > Bootstrapped and regression tested powerpc64-linux.  OK for mainline?
>  > 
>  > 	PR rtl-optimization/26026
>  > 	* expr.c (expand_expr_real_1): Optimize div and mod where the divisor
>  > 	is a known power of two shifted left a variable amount.
> 
> I'm with Graham on this one.
> 
> In Java, 
> 
>                a / (4096 << 32)
> 
> is not equal to
> 
>                a >>> (32 + 12)

Java really does not have unsigned types.
In C and most likely C++, 1 << 32 is undefined so it is safe for a/(1<<n) to
be foldded to a >> n for unsigned types.  Maybe the changelog should be clearer
here, as it does not mention unsigned types.

I want to say this really should into fold as the trees we get in expand is only
because of TER which right now is officially a work around for expand not working
on the SSA form.

Also looking at the patch, you special case 1, that seems wrong as exact_log2 (1) should
be zero and the fold_build2 would just return back in sh_cnt in the same type.  You
only might possibly create on extra integer_CST but that is nothing considering
they are shared already.

Also I forgot the type system for shifts, you might need to use fold_convert (cast) the
this shift count to be the correct type and you may as well use fold_build2 instead of
build2.

-- Pinski


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