core::fmt fails to optimize on arm-none-eabi

a116167
Opened by Daniel Egger at 2020-04-06 23:35:55

While generating code for an Cortex-M0 I noticed that using core::fmt to generate printable output generates extremely bloated code, even when just using a plain string as format.

According to @rkruppe on IRC this is most likely due to a missed elimination of dead code by LTO.

A stripped down example can be found here: https://gist.github.com/anonymous/7cfc8b881fcb8fdc792428dd772502cb

The generated assembly is here: https://gist.github.com/anonymous/9cfa48e53e3b1c8ba1ddb69f8ae3ea3b

I also have an example (serial_slow_helloworld) in this repo https://github.com/therealprof/stm32f042.git . xargo build --release --examples will create a binary demonstrating the problem.

This happens for me with:

rustc 1.20.0-nightly (8f1339af2 2017-07-16)
binary: rustc
commit-hash: 8f1339af2e5d1b33ec9ee3c8a3c531bcd61770fc
commit-date: 2017-07-16
host: x86_64-apple-darwin
release: 1.20.0-nightly
LLVM version: 4.0