[LLVMbugs] [Bug 9120] New: not taking advantage of known pointer alignment

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Feb 1 14:38:53 PST 2011


           Summary: not taking advantage of known pointer alignment
           Product: new-bugs
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: nlewycky at google.com
                CC: llvmbugs at cs.uiuc.edu

This is gcc pr 47579:

  #include <vector>
  extern void b1(), b2();
  void foo(const std::vector<int>& v) { if (v.size() == 0) b1(); else b2(); }

which demonstrates a really neat missed optimization:

define void @_Z3fooRKSt6vectorIiSaIiEE(%"class.std::vector"* nocapture %v) {
  %tmp2.i = getelementptr inbounds %"class.std::vector"* %v, i64 0, i32 0, i64
  %0 = bitcast i8* %tmp2.i to i32**
  %tmp3.i = load i32** %0, align 8, !tbaa !0
  %tmp5.i = bitcast %"class.std::vector"* %v to i32**
  %tmp6.i = load i32** %tmp5.i, align 8, !tbaa !0
  %sub.ptr.lhs.cast.i = ptrtoint i32* %tmp3.i to i64
  %sub.ptr.rhs.cast.i = ptrtoint i32* %tmp6.i to i64
  %sub.ptr.sub.i = sub i64 %sub.ptr.lhs.cast.i, %sub.ptr.rhs.cast.i
  %cmp = icmp ult i64 %sub.ptr.sub.i, 4
  br i1 %cmp, label %if.then, label %if.else

Is the difference between the pointers (%tmp3.i, %tmp6.i) less than 4? Well,
the pointers are aligned so that's always true. However, LLVM doesn't know

We mark pointer alignment at the use (load/store) instead of the definition. In
this case, I think we should add an alignment field to ptrtoint. Clang could
set this based on user annotations or the minimum alignment of the type.

If we need a source annotation to make this work, we should make sure libc++
has it too.

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