Skip to content

Switch default destination not eliminated despite known value range #76085

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

Closed
mattiase opened this issue Dec 20, 2023 · 2 comments · Fixed by #76295
Closed

Switch default destination not eliminated despite known value range #76085

mattiase opened this issue Dec 20, 2023 · 2 comments · Fixed by #76295

Comments

@mattiase
Copy link

A fully populated switch with known value range (but no explicit default clause) will still generate a conditional jump to the default destination:

void canthappen(void);
int g(int);

int f(int x) {
  if (x >= 0 && x <= 3) {
    switch (x) {
    case 0: return g(2);
    case 1: return g(3);
    case 2: return g(4);
    case 3: return g(5);
    }
    canthappen();
  }
  return -23;
}

results in a never-taken conditional branch to code that calls canthappen.
llvm 18.0.0git (9f74e6e).

@nikic
Copy link
Contributor

nikic commented Dec 20, 2023

@dtcxzyw dtcxzyw self-assigned this Dec 21, 2023
dickmao pushed a commit to commercial-emacs/commercial-emacs that referenced this issue Dec 22, 2023
* src/eval.c (funcall_subr): Help the compiler by reducing aliasing
problems, and compensate for a missed-optimisation bug in LLVM where
switches sometimes forget to use variable range information (reported
in llvm/llvm-project#76085).
dickmao pushed a commit to commercial-emacs/commercial-emacs that referenced this issue Dec 22, 2023
* src/eval.c (funcall_subr): Help the compiler by reducing aliasing
problems, and compensate for a missed-optimisation bug in LLVM where
switches sometimes forget to use variable range information (reported
in llvm/llvm-project#76085).
dtcxzyw added a commit that referenced this issue Jan 8, 2024
This patch eliminates unreachable default cases using range information.
Fixes #76085.
@mattiase
Copy link
Author

mattiase commented Jan 9, 2024

Nice, thank you!

justinfargnoli pushed a commit to justinfargnoli/llvm-project that referenced this issue Jan 28, 2024
This patch eliminates unreachable default cases using range information.
Fixes llvm#76085.
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