[llvm] r191315 - MemoryBuiltins: Reinstate optimizing (uninitialized) loads from operator new.

Benjamin Kramer benny.kra at googlemail.com
Tue Sep 24 10:34:29 PDT 2013


Author: d0k
Date: Tue Sep 24 12:34:29 2013
New Revision: 191315

URL: http://llvm.org/viewvc/llvm-project?rev=191315&view=rev
Log:
MemoryBuiltins: Reinstate optimizing (uninitialized) loads from operator new.

Modified:
    llvm/trunk/lib/Analysis/MemoryBuiltins.cpp
    llvm/trunk/test/Transforms/GVN/malloc-load-removal.ll

Modified: llvm/trunk/lib/Analysis/MemoryBuiltins.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/MemoryBuiltins.cpp?rev=191315&r1=191314&r2=191315&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/MemoryBuiltins.cpp (original)
+++ llvm/trunk/lib/Analysis/MemoryBuiltins.cpp Tue Sep 24 12:34:29 2013
@@ -31,12 +31,12 @@
 using namespace llvm;
 
 enum AllocType {
-  MallocLike         = 1<<0, // allocates
-  CallocLike         = 1<<1, // allocates + bzero
-  ReallocLike        = 1<<2, // reallocates
-  StrDupLike         = 1<<3,
-  OpNewLike          = 1<<4, // allocates; never returns null
-  AllocLike          = MallocLike | CallocLike | StrDupLike | OpNewLike,
+  OpNewLike          = 1<<0, // allocates; never returns null
+  MallocLike         = 1<<1 | OpNewLike, // allocates; may return null
+  CallocLike         = 1<<2, // allocates + bzero
+  ReallocLike        = 1<<3, // reallocates
+  StrDupLike         = 1<<4,
+  AllocLike          = MallocLike | CallocLike | StrDupLike,
   AnyAlloc           = AllocLike | ReallocLike
 };
 
@@ -118,7 +118,7 @@ static const AllocFnsTy *getAllocationDa
     return 0;
 
   const AllocFnsTy *FnData = &AllocationFnData[i];
-  if ((FnData->AllocTy & AllocTy) == 0)
+  if ((FnData->AllocTy & AllocTy) != FnData->AllocTy)
     return 0;
 
   // Check function prototype.

Modified: llvm/trunk/test/Transforms/GVN/malloc-load-removal.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GVN/malloc-load-removal.ll?rev=191315&r1=191314&r2=191315&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/GVN/malloc-load-removal.ll (original)
+++ llvm/trunk/test/Transforms/GVN/malloc-load-removal.ll Tue Sep 24 12:34:29 2013
@@ -7,7 +7,7 @@ target triple = "x86_64-apple-macosx10.8
 
 declare i8* @malloc(i64) nounwind
 
-define noalias i8* @test() nounwind uwtable ssp {
+define noalias i8* @test1() nounwind uwtable ssp {
 entry:
   %call = tail call i8* @malloc(i64 100) nounwind
   %0 = load i8* %call, align 1
@@ -21,11 +21,36 @@ if.then:
 if.end:                                           ; preds = %if.then, %entry
   ret i8* %call
 
-; CHECK-LABEL: @test(
+; CHECK-LABEL: @test1(
 ; CHECK-NOT: load
 ; CHECK-NOT: icmp
 
-; CHECK_NO_LIBCALLS-LABEL: @test(
+; CHECK_NO_LIBCALLS-LABEL: @test1(
+; CHECK_NO_LIBCALLS: load
+; CHECK_NO_LIBCALLS: icmp
+}
+
+declare i8* @_Znwm(i64) nounwind
+
+define noalias i8* @test2() nounwind uwtable ssp {
+entry:
+  %call = tail call i8* @_Znwm(i64 100) nounwind
+  %0 = load i8* %call, align 1
+  %tobool = icmp eq i8 %0, 0
+  br i1 %tobool, label %if.end, label %if.then
+
+if.then:                                          ; preds = %entry
+  store i8 0, i8* %call, align 1
+  br label %if.end
+
+if.end:                                           ; preds = %if.then, %entry
+  ret i8* %call
+
+; CHECK-LABEL: @test2(
+; CHECK-NOT: load
+; CHECK-NOT: icmp
+
+; CHECK_NO_LIBCALLS-LABEL: @test2(
 ; CHECK_NO_LIBCALLS: load
 ; CHECK_NO_LIBCALLS: icmp
 }





More information about the llvm-commits mailing list