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

optimize access of temporary array of 2 elements #58982

Open
rotateright opened this issue Nov 14, 2022 · 0 comments
Open

optimize access of temporary array of 2 elements #58982

rotateright opened this issue Nov 14, 2022 · 0 comments

Comments

@rotateright
Copy link
Contributor

rotateright commented Nov 14, 2022

I was curious if we could optimize code as suggested in https://reviews.llvm.org/D137688 .
I'm not sure which passes are responsible, but it's a mess on a reduced example:

int src(int i, int x, int y) {
  if (i != 0 && i != 1)
    __builtin_unreachable();

  int a[2] = {x, y};  
  return a[1 - i];
}

int foo(int i, int x, int y) {
  if (i != 0 && i != 1)
    __builtin_unreachable();

  int a[2] = {x, y};  
  return i ? a[0] : a[1];
}

Bad in IR:
https://alive2.llvm.org/ce/z/tqrgci

And that carries over to bad asm:
https://godbolt.org/z/exc56dW4z

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

2 participants