-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
More instructions generated for Ord::clamp than manual max(X).min(Y) for saturating truncating cast from i32 to u8 #125738
Copy link
Copy link
Open
Labels
A-autovectorizationArea: Autovectorization, which can impact perf or code sizeArea: Autovectorization, which can impact perf or code sizeA-codegenArea: Code generationArea: Code generationC-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing suchS-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-autovectorizationArea: Autovectorization, which can impact perf or code sizeArea: Autovectorization, which can impact perf or code sizeA-codegenArea: Code generationArea: Code generationC-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing suchS-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Originally reported here
rust-lang/rust-clippy#12826
Related PR spawned from that issue
#125455
cc @blyxyas
Clamping and casting from
i32tou8, usingclamp(0, 255) as u8produces unnecessary instructions compared to.max(0).min(255) as u8when a loop is autovectorized.clippy'smanual_clamplint in the beta toolchain warns on this pattern to useclampinstead which can regress performance.Minimal example
https://rust.godbolt.org/z/zf73jsqjq
Manual clamp
`Ord::clamp`
Real code examples from functions in the
image-webpcratehttps://rust.godbolt.org/z/3rnY8d94v
https://rust.godbolt.org/z/53T7n9PGx