<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - TwoAddressInstructionPass fails to optimize mov+add to lea"
   href="http://llvm.org/bugs/show_bug.cgi?id=20701">20701</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>TwoAddressInstructionPass fails to optimize mov+add to lea
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Common Code Generator Code
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>wujingyue@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=12916" name="attach_12916" title="test case">attachment 12916</a> <a href="attachment.cgi?id=12916&action=edit" title="test case">[details]</a></span>
test case

I am not an expert on codegen, but it looks a misoptimization to me. 

The test case (b.ll) is attached. 

llc b.ll -mtriple=i386-apple-darwin -o -

gives

        movl    %esi, %eax                                                      
        movl    %edi, %ecx                                                      
        testb   $1, 4(%esp)                                                     
        je      LBB0_2                                                          
## BB#1:                                ## %then                                
        addl    $16, %eax                                                       
        retl                                                                    
LBB0_2:                                 ## %else                                
        addl    $32, %ecx                                                       
        movl    %ecx, %eax                                                      
        retl

where I believe the addl+movl in LBB0_2 should be combined to an leal. 

The problematic machine code pass is TwoAddressInstructionPass. The machine
code for BB#2 before this pass is:

BB#2: derived from LLVM BB %else                                                
    Predecessors according to CFG: BB#0                                         
        %vreg3<def,tied1> = ADD32ri8 %vreg6<kill,tied0>, 32,
%EFLAGS<imp-def,dead>; GR32:%vreg3,%vreg6
        %vreg9<def> = COPY %vreg3<kill>; GR32:%vreg9,%vreg3                     
    Successors according to CFG: BB#3

ConvertInstTo3Addr (TwoAddressInstructionPass.cpp:1159) is not invoked because
vreg6 is killed and isProfitableToConv3Addr returns false. As a result, the
machine code afterwards is:

BB#2: derived from LLVM BB %else                                                
    Predecessors according to CFG: BB#0                                         
        %vreg3<def> = COPY %vreg6<kill>; GR32:%vreg3,%vreg6                     
        %vreg3<def,tied1> = ADD32ri8 %vreg3<tied0>, 32, %EFLAGS<imp-def,dead>;
GR32:%vreg3
        %vreg9<def> = COPY %vreg3<kill>; GR32:%vreg9,%vreg3                     
    Successors according to CFG: BB#3

without combining ADDR32ri8 and COPY to LEA32r. 

I am not familiar with this pass. So it would be awesome if anyone can help me
figure out the root cause and discuss how to fix this issue (if it is really an
issue at first hand). 

Thanks,
Jingyue</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>