[PATCH] D74651: Add IR constructs for inalloca replacement preallocated call setup

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 23 12:28:31 PDT 2020


efriedma added a comment.

> We already have to write an IR transform utility to rewrite these intrinsics to allocas, at the very least for the inliner. Functionattrs (or the new Attributor) should remove this preallocated attributes when possible, so that pass will want this utility. And, if a call site gets eliminated because it is unreachable, we'll want to call this utility from standard cleanup passes like instcombine. Once we have the utility, we might as well just call it from CGP and rely on it later, instead of implementing it a second time.

I edited my comment a couple of times and I think I dropped one important bit.

I'm not sure it's safe to rewrite an call_preallocated_setup to an alloca in the entry block, in general.  There is no rule which prevents multiple calls to the same call_preallocated_setup in a loop, without deallocating the memory in between.  Because of that, reusing the memory could lead to a miscompile.  There wouldn't be any way to deallocate the result, but that isn't necessarily a problem. You could prove this doesn't happen in common cases, and clang wouldn't generate code like that.  But LLVM optimizations could introduce it, I think, if there isn't a rule specifically preventing it.

> Is it possible to put an align attribute on a return value? If so, we could put it on the return value at the call site. However, for our purposes, it would always be 4. That's never enough to do any interesting transforms, so it's almost as good as leaving it unspecified.

Saying that the alignment of preallocated arguments is always 4 without any way to tweak it seems a little obnoxious, if we ever want to use the intrinsics for any other purpose. I guess it works, though.

> Is it possible to put an align attribute on a return value? If so, we could put it on the return value at the call site. However, for our purposes, it would always be 4. That's never enough to do any interesting transforms, so it's almost as good as leaving it unspecified.

Yes, you can put align on a return value.  Probably more important would be putting align on the call arguments itself.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74651





More information about the llvm-commits mailing list