[llvm-commits] Do more conditional propagation in GVN

Duncan Sands baldrick at free.fr
Sun Feb 26 10:06:01 PST 2012


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?

Ciao, Duncan.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: oppprop.diff
Type: text/x-patch
Size: 6008 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20120226/c1c52c74/attachment.bin>


More information about the llvm-commits mailing list