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

[SimplifyCFG] SwitchToLookupTable missing optimizations. #64231

Open
DianQK opened this issue Jul 30, 2023 · 1 comment · May be fixed by #67885
Open

[SimplifyCFG] SwitchToLookupTable missing optimizations. #64231

DianQK opened this issue Jul 30, 2023 · 1 comment · May be fixed by #67885

Comments

@DianQK
Copy link
Member

DianQK commented Jul 30, 2023

https://alive2.llvm.org/ce/z/7Mhqtr

define i64 @src(i8 %0) {
start:
  switch i8 %0, label %bb2 [
    i8 126, label %bb3
    i8 127, label %bb4
    i8 -128, label %bb5
  ]

bb2:
  unreachable

bb3:
  br label %bb10

bb4:
  br label %bb10

bb5:
  br label %bb10

bb10:
  %result= phi i64 [ 3, %bb3 ], [ 4, %bb4 ], [ 5, %bb5 ]
  ret i64 %result
}

It can be converted to:

define i64 @tgt(i8 %0) {
start:
  %switch.tableidx = sub i8 %0, 126
  %switch.idx.cast = zext i8 %switch.tableidx to i64
  %switch.offset = add nuw nsw i64 %switch.idx.cast, 3
  ret i64 %switch.offset
}
@DianQK
Copy link
Member Author

DianQK commented Jul 30, 2023

Candidate Patch: https://reviews.llvm.org/D156612.

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.

1 participant