[PATCH] D85463: [GlobalISel] Add combine for (x & mask) -> x when (x & mask) == x

Simon Pilgrim via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 7 02:05:31 PDT 2020


RKSimon added a comment.

In D85463#2201172 <https://reviews.llvm.org/D85463#2201172>, @paquette wrote:

> Also yeah, it looks like this is handled in `SelectionDAG::GetDemandedBits`:
>
>   case ISD::AND: {
>     // X & -1 -> X (ignoring bits which aren't demanded).
>     // Also handle the case where masked out bits in X are known to be zero.
>     if (ConstantSDNode *RHSC = isConstOrConstSplat(V.getOperand(1))) {
>       const APInt &AndVal = RHSC->getAPIntValue();
>       if (DemandedBits.isSubsetOf(AndVal) ||
>           DemandedBits.isSubsetOf(computeKnownBits(V.getOperand(0)).Zero |
>                                   AndVal))
>         return V.getOperand(0);
>     }
>
> So I guess that it might make sense to partially move this into GISelKnownBits.

Just a headsup - I'm trying to get rid of SelectionDAG::GetDemandedBits entirely and move all uses to SimplifyMultipleUseDemandedBits instead - its almost there, but GetDemandedBits is rather lax at OneUse checks when generating new ops/constants so the last few cases are taking a while (e.g. D77804 <https://reviews.llvm.org/D77804>)


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

https://reviews.llvm.org/D85463



More information about the llvm-commits mailing list