realloc(null, N) -> malloc(N)
Details
Details
Diff Detail
Diff Detail
Event Timeline
Comment Actions
I would like to hear your feedback on these three changes
- malloc(N) + realloc(ptr, N + X) -> fold to -> malloc(N + X), remove realloc
- malloc(N) + realloc(ptr, N - X) -> fold to -> malloc(N), remove realloc
- realloc(NULL, N) -> malloc(N)
@efriedma @lebedev.ri @spatel and others...
Edit: I think only 3. should stay in this patch..
lib/Transforms/Utils/SimplifyLibCalls.cpp | ||
---|---|---|
823 |
test/Transforms/InstCombine/realloc.ll | ||
---|---|---|
14 | oh yes, I will rework test soon. |
test/Transforms/InstCombine/realloc.ll | ||
---|---|---|
14 | Done. |
lib/Transforms/Utils/BuildLibCalls.cpp | ||
---|---|---|
1062 ↗ | (On Diff #142247) | This isn't right; should be TLI->has(LibFunc_calloc). |
lib/Transforms/Utils/BuildLibCalls.cpp | ||
---|---|---|
1062 ↗ | (On Diff #142247) | Fixed. Anyway, emitCalloc function I just copied from SimplifyLibCalls since it has no sense to have it there. So some time ago when it was merged and there was without proper review? |
Comment Actions
The patch doesn't compile as-is. Please post a corrected patch.
/llvm/lib/Transforms/Utils/BuildLibCalls.cpp:1061:11: error: member reference type 'const llvm::TargetLibraryInfo' is not a pointer; did you mean to use '.'? if (!TLI->has(LibFunc_calloc)) ~~~^~ . /llvm/lib/Transforms/Utils/BuildLibCalls.cpp:1069:53: error: indirection requires pointer operand ('const llvm::TargetLibraryInfo' invalid) inferLibFuncAttributes(*M->getFunction("calloc"), *TLI);
This is somehow problematic, if I remove this check, this code will crash on 32bit.
define i8* @foo(i32 %n) #0 {
}
Any ideas why, @spatel @efriedma ?