this patch want to fix the bug: https://llvm.org/bugs/show_bug.cgi?id=25892
When there is memset in code, llvm might transform memset to llvm.memset.*.
But llvm might not handle this well, so I use this patch to do it.
test:
check-llvm
Paths
| Differential D93360
[LibCallSimplifier] fold memset(malloc(x), 0, x) to calloc(1, x) if memset is intrinsic Needs ReviewPublic Authored by JudyZhu on Dec 15 2020, 7:11 PM.
Details
Summary this patch want to fix the bug: https://llvm.org/bugs/show_bug.cgi?id=25892 When there is memset in code, llvm might transform memset to llvm.memset.*. test:
Diff Detail Event TimelineComment Actions Please review the comments in D16337 - especially: 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 } Comment Actions yes, that might get an error.
Revision Contents
Diff 312089 llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
llvm/test/Transforms/InstCombine/memset-1.ll
llvm/test/Transforms/InstCombine/promot_malloc_and_memset_intrinsic.ll
|
Remove fixme