[LLVMbugs] [Bug 10322] New: -instcombine can deoptimize testcase?

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sun Jul 10 13:15:07 PDT 2011


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

           Summary: -instcombine can deoptimize testcase?
           Product: libraries
           Version: trunk
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Scalar Optimizations
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: rafael.espindola at gmail.com
                CC: llvmbugs at cs.uiuc.edu


In

%struct.Value = type { i8* }
define void @f1(%struct.Value* %foo, %struct.Value* %bar) {
entry:
  %arrayidx8 = getelementptr inbounds %struct.Value* %foo, i64 -2
  call void @f2(%struct.Value* %arrayidx8) nounwind
  call void @f2(%struct.Value* %bar) nounwind
  call void @f2(%struct.Value* %arrayidx8) nounwind
  call void @f2(%struct.Value* %bar) nounwind
  br label %if.then18
if.then18:
  %tmp2 = getelementptr inbounds %struct.Value* %arrayidx8, i64 0, i32 0
  %tmp3 = load i8** %tmp2, align 8
  call void @f3(i8* %tmp3) nounwind
  ret void
}
declare void @f2(%struct.Value*)
declare void @f3(i8*)

instcombine can transform the second gep in

 %tmp2 = getelementptr inbounds %struct.Value* %foo, i64 -2, i32 0

The original codegens to

        movq    %rsi, %r14
        movq    %rdi, %rbx
        addq    $-16, %rbx
        movq    %rbx, %rdi
        callq   _f2
        movq    %r14, %rdi
        callq   _f2
        movq    %rbx, %rdi
        callq   _f2
        movq    %r14, %rdi
        callq   _f2
        movq    (%rbx), %rdi
        callq   _f3

And the new one codegens to

        movq    %rsi, %r15
        movq    %rdi, %r14
        leaq    -16(%r14), %rbx
        movq    %rbx, %rdi
        callq   _f2
        movq    %r15, %rdi
        callq   _f2
        movq    %rbx, %rdi
        callq   _f2
        movq    %r15, %rdi
        callq   _f2
        movq    -16(%r14), %rdi
        callq   _f3

Note that we need an extra register. This can be fixed by adding a hasOneUse to
the optimization, but in this case that doesn't look like the right solution.
The right solution might be to do this "gep propagation" at the machine code
level too and produce

        movq    %rsi, %r15
        movq    %rdi, %r14
        leaq    -16(%r14), %rdi
        callq   _f2
        movq    %r15, %rdi
        callq   _f2
        leaq    -16(%r14), %rdi
        callq   _f2
        movq    %r15, %rdi
        callq   _f2
        movq    -16(%r14), %rdi
        callq   _f3

Yet another option is to disable the optimization if all the new indices are 0,
since in that case the two values are the "same", they just have a different
type.

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list