[PATCH] D122152: [InstCombine] Fold two select patterns into and-or

chenglin.bi via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 21 09:22:21 PDT 2022


bcl5980 added a comment.

In D122152#3396735 <https://reviews.llvm.org/D122152#3396735>, @RKSimon wrote:

> I'm almost afraid to ask - but should we consider supporting this with freeze?
>
>   ----------------------------------------
>   define i1 @src(i1 %a, i1 %b, i1 %c) {
>     %nota = xor i1 %a, 1
>     %cond = or i1 %nota, %c
>     %r = select i1 %cond, i1 %a, i1 %b
>     ret i1 %r
>   }
>   =>
>   define i1 @tgt(i1 %a, i1 %b, i1 %c) {
>     %bf = freeze i1 %b
>     %tmp = or i1 %bf, %c
>     %r = and i1 %tmp, %a
>     ret i1 %r
>   }
>   Transformation seems to be correct!
>   
>   
>   ----------------------------------------
>   define i1 @src(i1 %a, i1 %b, i1 %c) {
>     %notc = xor i1 %c, 1
>     %cond = and i1 %notc, %b
>     %r = select i1 %cond, i1 %a, i1 %b
>     ret i1 %r
>   }
>   =>
>   define i1 @tgt(i1 %a, i1 %b, i1 %c) {
>     %fa = freeze i1 %a
>     %tmp = or i1 %c, %fa
>     %r = and i1 %tmp, %b
>     ret i1 %r
>   }
>   Transformation seems to be correct!

A little strange. What I see is

  ----------------------------------------
  define i1 @src(i1 noundef %a, i1 %b, i1 %c) {
  %0:
    %notc = xor i1 %c, 1
    %cond = and i1 %notc, %b
    %r = select i1 %cond, i1 noundef %a, i1 %b
    ret i1 %r
  }
  =>
  define i1 @tgt(i1 noundef %a, i1 %b, i1 %c) {
  %0:
    %tmp = or i1 %c, noundef %a
    %r = and i1 %tmp, %b
    ret i1 %r
  }
  Transformation seems to be correct!
  ----------------------------------------
  define i1 @src(i1 %a, i1 noundef %b, i1 %c) {
  %0:
    %nota = xor i1 %a, 1
    %cond = or i1 %nota, %c
    %r = select i1 %cond, i1 %a, i1 noundef %b
    ret i1 %r
  }
  =>
  define i1 @tgt(i1 %a, i1 noundef %b, i1 %c) {
  %0:
    %tmp = or i1 noundef %b, %c
    %r = and i1 %tmp, %a
    ret i1 %r
  }
  Transformation seems to be correct!


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

https://reviews.llvm.org/D122152



More information about the llvm-commits mailing list