[LLVMdev] Missed optimization opportunity

Benjamin Kramer benny.kra at googlemail.com
Wed Dec 29 08:44:03 PST 2010


On 29.12.2010, at 17:25, Wesley Peck wrote:

> On Dec 28, 2010, at 12:48 PM, Chris Lattner wrote:
>> On Dec 28, 2010, at 9:39 AM, Lup Gratian wrote:
>>> I find it strange that it hasn't found that %add and %mul have the same value, %cmp would be then false, selecting and returning 15. If 'a' is replaced by a constant it works.
>> 
>> You're right, that is a missed optimization.  I added it to the missed optimization notes in r122603.  Did this come from a larger example, or was this just a test?
> 
> Just as a note, if you run this example through the opt tool as well then the output is the expected "ret i32 15".

Right, GVN catches this one. The problem is this optimization opportunity on the original testcase is only available after
gvn has run.

before gvn:
  %tmp5 = load i32* %arrayidx4, align 8
  %add = add i32 %tmp5, %a
  %mul = shl i32 %a, 1
  %cmp = icmp ugt i32 %add, %mul

gvn figures out that the load is equal to %a:
  %add = add i32 %a, %a
  %mul = shl i32 %a, 1
  %cmp = icmp ugt i32 %add, %mul

instcombine then canonicalizes the add into a shl, too late for GVN to CSE it.



More information about the llvm-dev mailing list