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] eliminateDeadSwitchCases does not eliminate dead branches. #78281

Open
DianQK opened this issue Jan 16, 2024 · 0 comments
Open

Comments

@DianQK
Copy link
Member

DianQK commented Jan 16, 2024

I tried the following code, which I expect to be optimized.

define i32 @src(i32 noundef %0) {
  %2 = icmp eq i32 %0, 0
  %3 = icmp eq i32 %0, 1
  %foo = zext i1 %3 to i32
  %bar = select i1 %2, i32 -1, i32 %foo
  switch i32 %bar, label %4 [
    i32 0, label %7
    i32 -1, label %7
  ]

4:                                                ; preds = %1
  %5 = icmp eq i32 %0, 2
  %6 = zext i1 %5 to i32
  br label %7

7:                                                ; preds = %4, %1, %1
  %8 = phi i32 [ %6, %4 ], [ 1, %1 ], [ 1, %1 ]
  ret i32 %8
}

define i32 @tgt(i32 noundef %0) {
  %.not = icmp ne i32 %0, 1
  %2 = zext i1 %.not to i32
  ret i32 %2
}

Alive2: https://alive2.llvm.org/ce/z/zyMuXt

Similar to #73446. But it's more complicated.
This should be caused by KnownBits.

We know that this %bar can only be -1, 0 and 1. So we can transform the default branch to a branch with a specific value.
There are several variants of this issue, such as replacing -1 with some other value and increasing the number of cases.

From: rust-lang/rust#119520.

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

No branches or pull requests

1 participant