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

Juneyoung Lee via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 10 10:15:45 PDT 2020


aqjune added a comment.

I think what @nikic said is correct:

  // select Cond, T, false --> Cond & T
  if (match(F, m_ZeroInt()))
    return SimplifyAndInst(Cond, T, Q);

If Cond is false and T is poison, the select is constantly false, but `SimplifyAndInst(Cond, T, Q)` can exploit the fact that T is poison regardless of Cond.

To address this, T should not be poison if Cond isn't poison. T = undef is okay, because `undef & false` is false.
It will be great if there is an analysis like 'is X poison when Y is poison?', but I guess it doesn't exist in ValueTracking yet. 
We can use `isGuaranteedNotToBeUndefOrPoison` now, to check whether T is never poison.
If we have `isGuaranteedNotToBePoison`, which checks poison only, the optimization can be more aggressive.


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

https://reviews.llvm.org/D77868





More information about the llvm-commits mailing list