When folding (X & Y) == Y to (~X & Y) == 0, we should only do the fold if the computed zero value is not Y. Otherwise, the resulting compare will match the same pattern ad infinitum.
This appeared using a quite old version of LLVM with an out-of-tree target and I'm having trouble getting a valid testcase out that runs with the latest LLVM/bugpoint. The code in question is exacly the same in the old and current LLVM so the bug still exists currently but I haven't yet been able to generate a testcase. Thought I would at least put this up for review. I'm not entirely confident current master could get into this situation but it seems wise to guard against it.
That would work for the case I saw. But it seems prudent to guard against future constructs which might appear. Anything that results in Y == Zero is going to cause an infinite loop.
@greened - I'm not sure if you're still looking at this, but by inspection this should work. Any luck on creating a test case?
ConstantSDNode *YConst = isConstOrConstSplat(Y, /*AllowUndefs*/ true, /*AllowTruncation*/ true); if (YConst && YConst->isNullValue()) return SDValue(); assert(Y != Zero && "Unknown zero value");