[llvm-commits] Do more conditional propagation in GVN

Hal Finkel hfinkel at anl.gov
Sun Feb 26 11:33:51 PST 2012


On Sun, 26 Feb 2012 19:06:01 +0100
Duncan Sands <baldrick at free.fr> wrote:

> Hi all, suppose we have
> 
>      %cmp = icmp eq i32 %x, %y
>      br i1 %cmp, label %same, label %different
>    same:
>      %cmp2 = icmp eq i32 %x, %y
>      %cmp3 = icmp ne i32 %x, %y
> 
> Right now GVN will replace %cmp2 with "true" because you can only get
> to block "same" if %cmp is true, and %cmp2 is the same as %cmp.  But
> it doesn't replace %cmp3 with false.  The attached patch implements
> this (when the branch condition is any comparison, not just an
> equality comparison).  Currently no pass does this (tested using
> -std-compile-opts).
> 
> The logic fires here and there.  It zaps two compares and two blocks
> in bzip2 because the compares were replaced with constants thanks to
> this.  In "gcc as one big file" it zaps 50 or so comparisons,
> resulting in some minor knock-on simplifications.  On sqlite3, which
> showed the most compile time slowdown when the original logic was
> implemented, the compile time goes up by 2%, while in return it zaps
> about 40 or so comparisons resulting in some minor knock-on
> simplifications.
> 
> I didn't implement this because I needed it, I implemented it because
> I realized that it could be done quite easily.  But is it worth it?
> Any opinions?

I think that this is worthwhile; these kinds of expressions sometimes
appear in indexing expressions inside inner loops of numeric codes for
the purpose of handling boundary conditions. In such cases, these kinds
of optimizations can be a big win.

 -Hal

> 
> Ciao, Duncan.



-- 
Hal Finkel
Postdoctoral Appointee
Leadership Computing Facility
Argonne National Laboratory



More information about the llvm-commits mailing list