[PATCH] D99674: [InstCombine] Conditionally fold select i1 into and/or

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 7 08:46:59 PDT 2021


spatel added a comment.

In D99674#2673844 <https://reviews.llvm.org/D99674#2673844>, @nikic wrote:

> @spatel These are important canonicalization transforms, that allow us to treat logical and/or the same way as and/or in many other passes. There is shouldAvoidAbsorbingNotIntoSelect() to guard against infinite loops, and probably it needs to be applied in more places.

Ah - I stepped into the example here for a closer look. It's a vector partial-undef problem (conflicting with a demanded elements transform). I think we can avoid it by just making sure we're matching a true zero or one constant (no undef/poison elements).

Here's what I have the test down to:

  define i32 @main(<2 x i1> %a, <2 x i1> %b, <2 x i32> %x, <2 x i32> %y) {
    %t5 = add nsw <2 x i32> %y, <i32 2147483647, i32 2147483647>
    %t6 = icmp slt <2 x i32> %t5, %x
    %ab = and <2 x i1> %a, %b
    %t7 = select <2 x i1> %ab, <2 x i1> %t6, <2 x i1> <i1 0, i1 poison>
    %t10 = xor <2 x i1> %t7, <i1 true, i1 poison>
    %p = select <2 x i1> %t10, <2 x i32> zeroinitializer, <2 x i32> %y
    %t11 = extractelement <2 x i32> %p, i32 0
    ret i32 %t11
  }


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99674



More information about the llvm-commits mailing list