[LLVMbugs] [Bug 17616] New: pointer arithmetic simplification

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Oct 18 13:50:20 PDT 2013


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

            Bug ID: 17616
           Summary: pointer arithmetic simplification
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: marc.glisse at normalesup.org
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

int* f(int*b,int*e){
  return b+(e-b);
}

generates this code on x86_64:

    subq    %rdi, %rsi
    andq    $-4, %rsi
    addq    %rdi, %rsi
    movq    %rsi, %rax

or in llvm terms:

  %sub.ptr.lhs.cast = ptrtoint i32* %e to i64
  %sub.ptr.rhs.cast = ptrtoint i32* %b to i64
  %sub.ptr.sub = sub i64 %sub.ptr.lhs.cast, %sub.ptr.rhs.cast
  %sub.ptr.div = ashr exact i64 %sub.ptr.sub, 2
  %add.ptr = getelementptr inbounds i32* %b, i64 %sub.ptr.div
  ret i32* %add.ptr

I'm sure you can guess what optimization I'd like to see...

Note that this happens in real code, for instance as a way to cast away
constness if e was const int*.

-- 
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/20131018/af7c35a0/attachment.html>


More information about the llvm-bugs mailing list