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: [email protected]
          Reporter: [email protected]
                CC: [email protected]
    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.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to