-
Notifications
You must be signed in to change notification settings - Fork 13.3k
match generates more branch instructions #122726
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
There should be multiple ways to solve this. Let me try one first. @rustbot claim |
[WIP] Use assume rather than range metadata Fixes rust-lang#122726. Currently, range can only be used in load, call and invoke instructions. Due to SROA being run before other passes, even in the simplest IR, LLVM cannot infer that `%i1` is 0. ```llvm define noundef i32 `@src(i32` noundef %arg) { %i = alloca i32, align 4 store i32 %arg, ptr %i, align 4 %i1 = load i32, ptr %i, align 4, !range !0 ret i32 %i1 } ``` https://alive2.llvm.org/ce/z/MjsH9b r? `@ghost`
#122664 marginally improves the example, removing the branch, but it doesn't get down to the optimal code: define noundef i32 @foo(i1 noundef %0, i32 %1, i1 noundef %2, i32 %3) unnamed_addr #0 {
start:
%. = zext i1 %2 to i32
%4 = select i1 %2, i32 %3, i32 0
%spec.select = add i32 %4, %1
%_0.0 = select i1 %0, i32 %spec.select, i32 %.
ret i32 %_0.0
} foo:
mov r8d, edx
and r8d, 1
xor eax, eax
test dl, 1
cmovne eax, ecx
add eax, esi
test dil, 1
cmove eax, r8d
ret |
Hmm, possibly related to backend handling |
I think the problem is that there is no register equivalent to the For codegen/backend, the following IR may be considered equivalent: define noundef i32 @foo(i32 noundef %0, i32 %1, i32 noundef %2, i32 %3) unnamed_addr #0 {
start:
%_2 = trunc i32 %2 to i1
%. = zext i1 %_2 to i32
%4 = select i1 %_2, i32 %3, i32 0
%spec.select = add i32 %4, %1
%_0 = trunc i32 %0 to i1
%_0.0 = select i1 %_0, i32 %spec.select, i32 %.
ret i32 %_0.0
} I would be concerned about the actual impact of the |
Unfortunately after experimenting, I don't think it's possible to represent enum discriminants as |
I tried this code:
The generated assembly code:
godbolt: https://rust.godbolt.org/z/7dGEccqcW.
We can get less code with alive2 validation:
godbolt (llc): https://llvm.godbolt.org/z/331WYovKG
Meta
rustc --version --verbose
:@rustbot modify labels: +C-optimization +A-codegen +A-LLVM +I-slow
The text was updated successfully, but these errors were encountered: