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

Missed transform: (a & !b) ? a : b into a | b #64558

Closed
Kmeakin opened this issue Aug 9, 2023 · 4 comments
Closed

Missed transform: (a & !b) ? a : b into a | b #64558

Kmeakin opened this issue Aug 9, 2023 · 4 comments

Comments

@Kmeakin
Copy link
Contributor

Kmeakin commented Aug 9, 2023

godbolt, alive

#include <stdbool.h>

bool src(bool a, bool b) { return (a & !b) ? a : b; }
bool tgt(bool a, bool b) { return a | b; }
define i1 @src(i1 %0, i1 %1){
  %3 = xor i1 %1, true
  %4 = and i1 %3, %0
  %5 = select i1 %4, i1 %0, i1 %1
  ret i1 %5
}

define i1 @tgt(i1 %0, i1 %1){
  %3 = or i1 %0, %1
  ret i1 %3
}

Note that the x864-64 backend is able to optimise src into tgt, but AArch64 and RISCV are not, so there is probably a missind DAG combine too

@llvmbot
Copy link
Member

llvmbot commented Aug 9, 2023

@llvm/issue-subscribers-backend-aarch64

@llvmbot
Copy link
Member

llvmbot commented Aug 9, 2023

@llvm/issue-subscribers-backend-risc-v

@dtcxzyw dtcxzyw self-assigned this Aug 28, 2023
@dtcxzyw
Copy link
Member

dtcxzyw commented Aug 28, 2023

Generalized transform: https://alive2.llvm.org/ce/z/x8ZSY9

@dtcxzyw
Copy link
Member

dtcxzyw commented Aug 28, 2023

Candidate patch: https://reviews.llvm.org/D158983

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

4 participants