[compiler-rt] [InstCombine] Canonicalize `and(zext(A), B)` into `select A, B & 1, 0` (PR #66740)

via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 19 08:03:09 PDT 2023


goldsteinn wrote:

> I think this is the right canonicalization at the IR level, as select allows better analysis than zext(icmp). However, this seems to be universally worse for the backend: https://llvm.godbolt.org/z/Yh7brfc8b So I think we would need an SDAG undo transform. Interestingly, this already happens for riscv64, so maybe the undo transform already exists but is not enabled for all target.
> 
> @goldsteinn What do you think?

Yeah, I think I agree, I looked a bit around DAGCombiner and can't find where `risv` does this but pretty sure its in the `RISCV` target codes as commenting out the entirety of `visitSelect`, `visitSelect_CC`, and `visitAndLike` doesn't change the `riscv` codegen.

I'd say since we also do:
```
  %zx = sext i1 %x to i32
  %r = and i32 %zx, %y
```
to
```
  %r = select i1 %x, i32 %masked, i32 0
```
This makes sense in that context.

I'll throw up a patch shortly to cover this case in the backend.

https://github.com/llvm/llvm-project/pull/66740


More information about the llvm-commits mailing list