realloc(null, N) -> malloc(N)
Details
Details
Diff Detail
Diff Detail
- Repository
- rL LLVM
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 | ||
|---|---|---|
| 847 ↗ | (On Diff #141545) | |
| lib/Transforms/Utils/BuildLibCalls.cpp | ||
|---|---|---|
| 1059 ↗ | (On Diff #142131) | Why are the implementations of emitMalloc and emitCalloc different? (I'm specifically concerned about missing call to inferLibFuncAttributes.) |
| test/Transforms/InstCombine/realloc.ll | ||
| 13 ↗ | (On Diff #142131) | This doesn't look like it's what you meant to test. |
| test/Transforms/InstCombine/realloc.ll | ||
|---|---|---|
| 13 ↗ | (On Diff #142131) | oh yes, I will rework test soon. |
| test/Transforms/InstCombine/realloc.ll | ||
|---|---|---|
| 13 ↗ | (On Diff #142131) | 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);