[PATCH] D137497: [ArgumentPromotion] Allow the frontend to specify the maximum number of elements to promote on a per-function basis via metadata.

Patrick Walton via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Nov 5 13:25:33 PDT 2022


pcwalton created this revision.
Herald added subscribers: ormris, JDevlieghere, hiraditya.
Herald added a project: All.
pcwalton requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

In Rust, argument promotion on destructor functions (core::ptr::drop_in_place)
is an important optimization, because those functions are marked cold in
exceptional paths and as such are rarely inlined, making them often the only
functions standing in the way of SROA. The default cap on the number of
elements to promote, 2, is too conservative for these specific functions in
Rust. At the same time, we don't want to raise the element cap across the
board, because that could make argument promotion unprofitable in some
circumstances. Additionally, argument promotion only runs on -O3 today, but for
these functions argument promotion is so important that the Rust frontend wants
to run the pass at any optimization level.

This patch addresses both of these problems by introducing a new piece of
per-function metadata, !argpromotion !{i64}. The i64 value represents the
maximum number of elements that argument promotion will promote into and
overrides the MaxElements setting that the pass itself defaults to. At -O3, the
Rust frontend can run argument promotion as usual with MaxElements to 2; at
-O2, it can run the pass with MaxElements set to 0. The frontend will tag
destructor functions with !argpromotion set to some high value, perhaps 8 or

16. This should allow better optimization for typical Rust code, especially

code that uses iterators frequently.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137497

Files:
  llvm/lib/Transforms/IPO/ArgumentPromotion.cpp
  llvm/test/Transforms/ArgumentPromotion/arg-promotion-metadata.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137497.473455.patch
Type: text/x-patch
Size: 6044 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221105/0ea1be82/attachment.bin>


More information about the llvm-commits mailing list