[PATCH] D65408: [Attributor] Heap-To-Stack Conversion

Dávid Bolvanský via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 15 15:42:02 PDT 2019


xbolva00 added a comment.

In D65408#1670705 <https://reviews.llvm.org/D65408#1670705>, @lebedev.ri wrote:

> In D65408#1670702 <https://reviews.llvm.org/D65408#1670702>, @xbolva00 wrote:
>
> > Quite questionable is “stackification” of mallocs in loops, we should avoid it I think. @efriedma, what do you think?
>
>
> Please can you be more specific?


Yes :) 
Heap to stack idea started some time ago and @efriedma raised some concerns: https://reviews.llvm.org/D47345#1112573.
Imagine

for (int i = 0; i < BIG_NUM; ++i) {

  void *p = malloc(128);
  ....
  free(p);

}

->

for (int i = 0; i < BIG_NUM; ++i) {

  void *p = alloca(128);
  ....

}

Nice stack overflow :)

And yes, we shouldn't do this on irreducible cfgs (also noted by Eli).

> 
> 
> In D65408#1670703 <https://reviews.llvm.org/D65408#1670703>, @xbolva00 wrote:
> 
>> IsMallocLikeFn returns true for C++ operator new which does throw on an allocation failure.
> 
> 
> Likewise, please can you be more specific in your messages? This doesn't actually explain what the problem is.

%1 = tail call dereferenceable(4) i8* @_Znwm(i64 4)
...some code...
tail call void @free(i8* nonnull %1)

is probably converted to alloca. I have no strong opinion what should be done here, ideally warning! :)  Anyway, I would like to see some tests with C++'s new.


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65408/new/

https://reviews.llvm.org/D65408





More information about the llvm-commits mailing list