Skip to content
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

Missed optimization of switch to arithmetic #67843

Open
ojeda opened this issue Sep 29, 2023 · 3 comments · May be fixed by #67881
Open

Missed optimization of switch to arithmetic #67843

ojeda opened this issue Sep 29, 2023 · 3 comments · May be fixed by #67881

Comments

@ojeda
Copy link

ojeda commented Sep 29, 2023

From: rust-lang/rust#116272

target datalayout = "n8:16:32:64"

define i32 @src(i8 %0) {
start:
  switch i8 %0, label %bb2 [
    i8 0, label %bb5
    i8 1, label %bb4
    i8 -1, label %bb1
  ]

bb2:                                              ; preds = %start
  unreachable

bb4:                                              ; preds = %start
  br label %bb5

bb1:                                              ; preds = %start
  br label %bb5

bb5:                                              ; preds = %start, %bb1, %bb4
  %.0 = phi i32 [ 255, %bb1 ], [ 1, %bb4 ], [ 0, %start ]
  ret i32 %.0
}

define i32 @tgt(i8) {
  %_2 = zext i8 %0 to i32
  ret i32 %_2
}

https://alive2.llvm.org/ce/z/NvmXJk

@nikic
Copy link
Contributor

nikic commented Sep 29, 2023

I'll close this as won't fix for the time being, as this should be addressed during the initial switch transform instead. It's of course possible to optimize the lookup table as well, but we shouldn't do so unless and until there is cause to do so.

@nikic nikic closed this as not planned Won't fix, can't repro, duplicate, stale Sep 29, 2023
@nikic
Copy link
Contributor

nikic commented Sep 29, 2023

Eh, I updated the test case to start with the switch instead.

@nikic nikic reopened this Sep 29, 2023
@nikic nikic changed the title Missed optimization Missed optimization of switch to arithmetic Sep 29, 2023
@ojeda
Copy link
Author

ojeda commented Sep 29, 2023

Makes sense -- thanks! Yeah, rustc uses a switch originally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants