[PATCH] D77868: [InstSimplify] fold select of bools using bitwise logic

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 10 07:55:19 PDT 2020


lebedev.ri added a comment.

> This fixes regressions that would be visible if we remove known poison-unsafe transforms in instcombine mentioned here:
>  https://reviews.llvm.org/D72396#1810460

I think the problem is being misunderstood:

  ----------------------------------------
  Name: fval is true
    %s = select i1 %cmp1, i1 %x, i1 1
    ret i1 %s
  =>
    %not = xor i1 %cmp1, 1
    %s = or i1 %not, %x
    ret i1 %s
  
  ERROR: Target is more poisonous than source for i1 %s
  
  Example:
  i1 %cmp1 = #x0 (0)
  i1 %x = poison
  i1 %not = #x1 (1)
  Source value: #x1 (1)
  Target value: poison
  
  
  ----------------------------------------
  Name: fval is false
    %s = select i1 %cmp1, i1 %x, i1 0
    ret i1 %s
  =>
    %s = and i1 %cmp1, %x
    ret i1 %s
  
  ERROR: Target is more poisonous than source for i1 %s
  
  Example:
  i1 %cmp1 = #x0 (0)
  i1 %x = poison
  Source value: #x0 (0)
  Target value: poison
  
  
  ----------------------------------------
  Name: tval is true
    %s = select i1 %cmp1, i1 1, i1 %x
    ret i1 %s
  =>
    %s = or i1 %cmp1, %x
    ret i1 %s
  
  ERROR: Target is more poisonous than source for i1 %s
  
  Example:
  i1 %cmp1 = #x1 (1)
  i1 %x = poison
  Source value: #x1 (1)
  Target value: poison
  
  
  ----------------------------------------
  Name: tval is false
    %s = select i1 %cmp1, i1 0, i1 %x
    ret i1 %s
  =>
    %not = xor i1 %cmp1, 1
    %s = and i1 %not, %x
    ret i1 %s
  
  ERROR: Target is more poisonous than source for i1 %s
  
  Example:
  i1 %cmp1 = #x1 (1)
  i1 %x = poison
  i1 %not = #x0 (0)
  Source value: #x0 (0)
  Target value: poison

  ----------------------------------------
  Name: fval is true
    %s = select i1 %cmp1, i1 %x, i1 1
    ret i1 %s
  =>
    %not = xor i1 %cmp1, 1
    %frozen_x = freeze i1 %x
    %s = or i1 %not, %frozen_x
    ret i1 %s
  
  Done: 1
  Transformation seems to be correct!
  
  ----------------------------------------
  Name: fval is false
    %s = select i1 %cmp1, i1 %x, i1 0
    ret i1 %s
  =>
    %frozen_x = freeze i1 %x
    %s = and i1 %cmp1, %frozen_x
    ret i1 %s
  
  Done: 1
  Transformation seems to be correct!
  
  ----------------------------------------
  Name: tval is true
    %s = select i1 %cmp1, i1 1, i1 %x
    ret i1 %s
  =>
    %frozen_x = freeze i1 %x
    %s = or i1 %cmp1, %frozen_x
    ret i1 %s
  
  Done: 1
  Transformation seems to be correct!
  
  ----------------------------------------
  Name: tval is false
    %s = select i1 %cmp1, i1 0, i1 %x
    ret i1 %s
  =>
    %not = xor i1 %cmp1, 1
    %frozen_x = freeze i1 %x
    %s = and i1 %not, %frozen_x
    ret i1 %s
  
  Done: 1
  Transformation seems to be correct!


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

https://reviews.llvm.org/D77868





More information about the llvm-commits mailing list