This is an archive of the discontinued LLVM Phabricator instance.

[DagCombine] Fold (X & ~Y) | Y with truncated not
ClosedPublic

Authored by nikic on May 4 2022, 8:45 AM.

Details

Summary

This extends the (X & ~Y) | Y to X | Y fold to also work if ~Y is a truncated not (when taking into account the mask X). This is done by exporting the infrastructure added in D124856 and reusing it here.

I've retained the old value of AllowUndefs=false, though probably this can be switched to true with extra test coverage.

Diff Detail

Event Timeline

nikic created this revision.May 4 2022, 8:45 AM
nikic requested review of this revision.May 4 2022, 8:45 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 4 2022, 8:45 AM
RKSimon added inline comments.May 4 2022, 9:01 AM
llvm/include/llvm/CodeGen/SelectionDAGNodes.h
1691

note -> node

1692

an empty SDValue

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
4688–4689

Would this be more generally useful if we replaced Mask with a APInt DemandedBits?

nikic updated this revision to Diff 427231.May 5 2022, 12:47 AM
nikic marked 2 inline comments as done.

Fix comment typos

nikic added inline comments.May 5 2022, 12:52 AM
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
4688–4689

Yes -- though it would make the current callers, which all have the mask as an SDValue, more complicated. Would have to extract the isConstOrConstSplat part plus a fallback to an all-ones mask to each caller. I'd personally delay that until we have a use-case that requires passing an APInt.

RKSimon accepted this revision.May 5 2022, 1:10 AM

LGTM

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
4688–4689

OK - that's fine, there might be a couple of cases in SimplifyDemandedBits, but we can handle that if/when its useful to convert them to use this.

This revision is now accepted and ready to land.May 5 2022, 1:10 AM
This revision was automatically updated to reflect the committed changes.