Inlining leaves extra assembly #141144
Labels
A-codegen
Area: Code generation
A-LLVM
Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.
C-optimization
Category: An issue highlighting optimization opportunities or PRs implementing such
I-slow
Issue: Problems and improvements with respect to performance of generated code.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Uh oh!
There was an error while loading. Please reload this page.
I have found a weird issue with inlining. I have expected these two functions to have the same assembly, but the second one has extra code:
Code to reproduce: godbolt.org (nightly,
-C opt-level=3
)Code
Considering different examples (
if
ormatch
), especially(cmp == Less)
, my guess is that the second usage of thecmp
variable duplicates the assembly offn compare
.Update
Example with generics (closure), not affected by
-C debuginfo=0
or-C opt-level=1
: godbolt.orgCode
Full project with this issue
Here even
#[inline(always)]
for the closure does not help: https://github.com/RoDmitry/alphabet_detector/tree/141144File
alphabet_detector/src/lang/ucd/script.rs
starting from the line 453.Two identical functions, only difference is a generic
Fn
:cargo asm alphabet_detector::lang::ucd::script::UcdScript::find
Asm
cargo asm alphabet_detector::lang::ucd::script::UcdScript::find_broken
Asm
But if I replace
To
base = hint::select_unpredictable(cmp == Greater, base, mid);
, their assembly start to look closer to identical.rustc --version --verbose
:The text was updated successfully, but these errors were encountered: