[LLVMbugs] [Bug 20701] New: TwoAddressInstructionPass fails to optimize mov+add to lea

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Aug 18 13:01:14 PDT 2014


http://llvm.org/bugs/show_bug.cgi?id=20701

            Bug ID: 20701
           Summary: TwoAddressInstructionPass fails to optimize mov+add to
                    lea
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Common Code Generator Code
          Assignee: unassignedbugs at nondot.org
          Reporter: wujingyue at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Created attachment 12916
  --> http://llvm.org/bugs/attachment.cgi?id=12916&action=edit
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

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20140818/48bfb7a6/attachment.html>


More information about the llvm-bugs mailing list