[PATCH] D47345: [InstructionCombining] Replace small allocations with local/global variable

Dávid Bolvanský via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 25 10:36:17 PDT 2018


xbolva00 added a comment.

Maybe introduce local cache to track:
Function --- Number of malloc -> alloca?

Or allow it only once per function? Or again some treshold value.



================
Comment at: lib/Transforms/InstCombine/InstructionCombining.cpp:2267
+  // Threshold whether change malloc to alloca or not
+  static unsigned FoldTreshold = 100;
+
----------------
efriedma wrote:
> Please make this an option, so it can be tweaked for debugging.
Command line option for opt? Ok.


================
Comment at: lib/Transforms/InstCombine/InstructionCombining.cpp:2314
+  Builder.SetInsertPoint(Malloc->getParent(), ++Malloc->getIterator());
+  Value *LocAlloc = Builder.CreateAlloca(Builder.getInt8Ty(), Size);
+  Malloc->replaceAllUsesWith(LocAlloc);
----------------
efriedma wrote:
> You probably don't want to insert an alloca in the middle of a function; allocas outside the entry block are treated as dynamic allocations, so they're slower, and won't work the way you want with code that uses llvm.stackrestore.
Ok, I will fix it.


https://reviews.llvm.org/D47345





More information about the llvm-commits mailing list