realloc(null, N) -> malloc(N)
Details
Diff Detail
Event Timeline
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 | ||
---|---|---|
847 |
test/Transforms/InstCombine/realloc.ll | ||
---|---|---|
13 | oh yes, I will rework test soon. |
test/Transforms/InstCombine/realloc.ll | ||
---|---|---|
13 | Done. |
lib/Transforms/Utils/BuildLibCalls.cpp | ||
---|---|---|
1051 | This isn't right; should be TLI->has(LibFunc_calloc). |
lib/Transforms/Utils/BuildLibCalls.cpp | ||
---|---|---|
1051 | 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? |
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);
Why are the implementations of emitMalloc and emitCalloc different? (I'm specifically concerned about missing call to inferLibFuncAttributes.)