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
- This should allow better optimization for typical Rust code, especially
code that uses iterators frequently.