Skip to content

Missed optimization of switch to arithmetic #67842

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Missed optimization of switch to arithmetic #67842

ojeda opened this issue Sep 29, 2023 · 0 comments · May be fixed by #67882

Comments

@ojeda
Copy link

ojeda commented Sep 29, 2023

From: rust-lang/rust#116272

define i8 @src(i32) {
start:
  switch i32 %0, label %bb2 [
    i32 0, label %bb5
    i32 1, label %bb4
    i32 255, 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 i8 [ -1, %bb1 ], [ 1, %bb4 ], [ 0, %start ]
  ret i8 %.0
}

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

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

@nikic nikic changed the title Missed optimization Missed optimization of switch to arithmetic Sep 29, 2023
@dtcxzyw dtcxzyw self-assigned this Sep 29, 2023
@dtcxzyw dtcxzyw linked a pull request Sep 30, 2023 that will close this issue
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants