[llvm-commits] Do more conditional propagation in GVN

Duncan Sands baldrick at free.fr
Mon Feb 27 00:30:29 PST 2012


Hi Hal,

>> 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).
...
>> 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.

OK, I've applied it in commit 151517.  The only reason not to apply it is
the compile time impact (which is basically nothing for most programs; the
worst I measured was a 2% slowdown in GVN).  I have some ideas about how to
speed up the conditional propagation logic, so hopefully the compile time
issue will go away soon.

Ciao, Duncan.



More information about the llvm-commits mailing list