[llvm] r191313 - MemoryBuiltins: Fix operator new bits.

Hal Finkel hfinkel at anl.gov
Tue Sep 24 10:38:27 PDT 2013


Ben,

Kind of off topic, but since you're looking at this code, can you see why posix_memalign is in this list:

  {LibFunc::posix_memalign,      MallocLike,  3, 2,  -1},

As far as I can tell, getAllocationData will always fail on it because of this check:

if (FTy->getReturnType() == Type::getInt8PtrTy(FTy->getContext()) && ...

Thanks,
Hal


----- Original Message -----
> Author: d0k
> Date: Tue Sep 24 12:15:14 2013
> New Revision: 191313
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=191313&view=rev
> Log:
> MemoryBuiltins: Fix operator new bits.
> 
> We really don't want to optimize malloc return value checks away.
> 
> Modified:
>     llvm/trunk/lib/Analysis/MemoryBuiltins.cpp
>     llvm/trunk/test/Transforms/InstSimplify/call.ll
> 
> Modified: llvm/trunk/lib/Analysis/MemoryBuiltins.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/MemoryBuiltins.cpp?rev=191313&r1=191312&r2=191313&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Analysis/MemoryBuiltins.cpp (original)
> +++ llvm/trunk/lib/Analysis/MemoryBuiltins.cpp Tue Sep 24 12:15:14
> 2013
> @@ -35,9 +35,9 @@ enum AllocType {
>    CallocLike         = 1<<1, // allocates + bzero
>    ReallocLike        = 1<<2, // reallocates
>    StrDupLike         = 1<<3,
> -  OpNewLike          = MallocLike | (1<<4), // allocates; never
> returns null
> -  AllocLike          = MallocLike | CallocLike | StrDupLike,
> -  AnyAlloc           = MallocLike | CallocLike | ReallocLike |
> StrDupLike
> +  OpNewLike          = 1<<4, // allocates; never returns null
> +  AllocLike          = MallocLike | CallocLike | StrDupLike |
> OpNewLike,
> +  AnyAlloc           = AllocLike | ReallocLike
>  };
>  
>  struct AllocFnsTy {
> 
> Modified: llvm/trunk/test/Transforms/InstSimplify/call.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/call.ll?rev=191313&r1=191312&r2=191313&view=diff
> ==============================================================================
> --- llvm/trunk/test/Transforms/InstSimplify/call.ll (original)
> +++ llvm/trunk/test/Transforms/InstSimplify/call.ll Tue Sep 24
> 12:15:14 2013
> @@ -121,3 +121,23 @@ cast.end:
>  }
>  
>  declare noalias i8* @_Znwm(i64)
> +
> +define i8* @malloc_can_return_null() {
> +entry:
> +  %call = tail call noalias i8* @malloc(i64 8)
> +  %cmp = icmp eq i8* %call, null
> +  br i1 %cmp, label %cast.end, label %cast.notnull
> +
> +cast.notnull:                                     ; preds = %entry
> +  %add.ptr = getelementptr inbounds i8* %call, i64 4
> +  br label %cast.end
> +
> +cast.end:                                         ; preds =
> %cast.notnull, %entry
> +  %cast.result = phi i8* [ %add.ptr, %cast.notnull ], [ null, %entry
> ]
> +  ret i8* %cast.result
> +
> +; CHECK-LABEL: @malloc_can_return_null
> +; CHECK: br i1 %cmp, label %cast.end, label %cast.notnull
> +}
> +
> +declare noalias i8* @malloc(i64)
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
> 

-- 
Hal Finkel
Assistant Computational Scientist
Leadership Computing Facility
Argonne National Laboratory



More information about the llvm-commits mailing list