[LLVMbugs] [Bug 12036] New: Missed pointer comparison optimization (affects smallvector)

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sun Feb 19 17:04:21 PST 2012


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

             Bug #: 12036
           Summary: Missed pointer comparison optimization (affects
                    smallvector)
           Product: libraries
           Version: 1.0
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: clattner at apple.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified


In:

$ cat t.cc
#include "llvm/ADT/SmallVector.h"

using namespace llvm;
void g(SmallVector<int, 8>&);

void test() {
  SmallVector<int, 8> sv;
  sv.push_back(1);
  sv.push_back(2);
  g(sv);
}

It should be "obvious" that the push backs don't need to grow the vector.  We
avoid the call to grow in the first one, but not in the second one:

$ clang t.cc -I ~/llvm/include/ -S -o - -O3 -fno-exceptions -emit-llvm

<trimmed a bit>

define void @_Z4testv() nounwind uwtable ssp {
_ZN4llvm23SmallVectorTemplateBaseIiLb1EE9push_backERKi.exit:
  %sv = alloca %"class.llvm::SmallVector", align 16
  %FirstEl.i.i.i.i.i.i = getelementptr inbounds %"class.llvm::SmallVector"*
%sv, i64 0, i32 0, i32 0, i32 0, i32 0, i32 3
  %0 = bitcast %"union.llvm::SmallVectorBase::U"* %FirstEl.i.i.i.i.i.i to i8*
  %add.ptr.i.i.i.i.i.i = getelementptr inbounds
%"union.llvm::SmallVectorBase::U"* %FirstEl.i.i.i.i.i.i, i64 2
  %1 = bitcast %"union.llvm::SmallVectorBase::U"* %add.ptr.i.i.i.i.i.i to i8*
  %add.ptr.i = getelementptr inbounds i8* %0, i64 4
  %cmp.i4 = icmp ult i8* %add.ptr.i, %1
  br i1 %cmp.i4, label
%_ZN4llvm23SmallVectorTemplateBaseIiLb1EE9push_backERKi.exit8, label %if.end.i7

if.end.i7:                                        ; preds =
%_ZN4llvm23SmallVectorTemplateBaseIiLb1EE9push_backERKi.exit
  %3 = getelementptr inbounds %"class.llvm::SmallVector"* %sv, i64 0, i32 0,
i32 0, i32 0, i32 0
  call void
@_ZN4llvm15SmallVectorBase8grow_podEmm(%"class.llvm::SmallVectorBase"* %3, i64
0, i64 4) nounwind
  %.pre.i6 = load i8** %EndX.i.i.i.i.i.i, align 8, !tbaa !0
  br label %_ZN4llvm23SmallVectorTemplateBaseIiLb1EE9push_backERKi.exit8
...


It inst-simplify was smart enough to fold the %cmp.i4 comparison, then we'd
avoid emitting the if.end.i7 block entirely.  This would save code size, but
also possibly have secondary optimizations like reducing the inlining cost of
"test" into its callers etc.

-- 
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