[PATCH] D93360: [LibCallSimplifier] fold memset(malloc(x), 0, x) to calloc(1, x) if memset is intrinsic

Judy via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 21 22:33:04 PST 2020


JudyZhu added a comment.

yes, that might get an error.
let me change it.

In D93360#2466015 <https://reviews.llvm.org/D93360#2466015>, @spatel wrote:

> Please review the comments in D16337 <https://reviews.llvm.org/D16337>  - especially:
> https://reviews.llvm.org/D16337#331117
>
> How does this patch guarantee that memory is not touched between the malloc and the memset? Is the transform safe on this example?
>
>   define float* @store_between_malloc_and_memset(i64 %size) {
>   entry:
>     %call = tail call i8* @malloc(i64 %size) #1
>     %bc1 = bitcast i8* %call to i32*
>     store i32 1, i32* %bc1, align 4
>     %cmp = icmp eq i8* %call, null
>     br i1 %cmp, label %cleanup, label %if.end
>   
>   if.end:
>     %bc = bitcast i8* %call to float*
>     %call3 = tail call i8* @memset(i8* %call, i32 0, i64 %size)
>     br label %cleanup
>   
>   cleanup:
>     %r = phi float* [ %bc, %if.end ], [ null, %entry ]
>     ret float* %r
>   }




CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93360/new/

https://reviews.llvm.org/D93360



More information about the llvm-commits mailing list