[PATCH] D145157: [InstCombine] Implement "A & (~A | B) --> A & B" like transform for boolean vectors.

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 2 10:48:29 PST 2023


spatel added inline comments.


================
Comment at: llvm/test/Transforms/InstCombine/logical-select.ll:1132
+  %not = xor <2 x i1> %a, <i1 true, i1 true>
+  %or = or <2 x i1> %b, %not
+  %and = select <2 x i1> %a, <2 x i1> %or, <2 x i1> zeroinitializer
----------------
paulwalker-arm wrote:
> spatel wrote:
> > This isn't doing what we wanted - the `not` will get commuted to operand 0.
> > To keep it as operand 1, we need something like this:
> > 
> > 
> > ```
> > declare i1 @gen()
> > 
> > define i1 @and_commute1(i1 %a) {
> >   %b = call i1 @gen()
> >   %nota = xor i1 %a, 1
> >   %or = or i1 %b, %nota
> >   %and = select i1 %a, i1 %or, i1 0
> >   ret i1 %and
> > }
> > ```
> > 
> > We also need matching and tests for patterns where the "or-not" is the condition value of the select?
> The "or-not is the condition" case already works, whereby it's converted to an "and" (See https://alive2.llvm.org/ce/z/bxZ37W). I'm not sure why that case doesn't have the same poison issues that my case has.
Ah, I see now. We get the commuted case where `or` is the condition because we use `impliesPoison()` to convert the select into a regular bitwise logic `and`, and the fold is handled by matching regular bitwise logic ops.

When the `or` is the true value of the select, we can't do that. That's because if %b is poison, then the select can prevent it from leaking to the final result value: 
https://alive2.llvm.org/ce/z/H-HKdz


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145157/new/

https://reviews.llvm.org/D145157



More information about the llvm-commits mailing list