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.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
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.
llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp | ||
---|---|---|
2967 | Is this happening with vector cases, in which case would this work instead: ConstantSDNode *YConst = isConstOrConstSplat(Y) ? |
llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp | ||
---|---|---|
2967 | 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. |
llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp | ||
---|---|---|
2967 | Under what circumstances will the isConstOrConstSplat + isNullValue() fail but the comparison against Zero work? |
llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp | ||
---|---|---|
2967 | @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"); |
Is this happening with vector cases, in which case would this work instead:
ConstantSDNode *YConst = isConstOrConstSplat(Y) ?