This is an archive of the discontinued LLVM Phabricator instance.

[SDAG] Handle truncated not in haveNoCommonBitsSet()
ClosedPublic

Authored by nikic on May 3 2022, 8:18 AM.

Details

Summary

Demanded bits analysis may replace a full-width not with a any_extend (not (truncate X)) pattern. This patch looks through this kind of pattern in haveNoCommonBitsSet(). Of course, we can only do this if we only need negated bits in the non-extended part, as the other bits may now be arbitrary. For example, if we have haveNoCommonBitsSet(~X & Y, X) then ~X only needs to actually negate bits set in Y.

This is only a partial solution to the problem in that it allows add -> or conversion, but the resulting or doesn't get folded yet. (I guess that will involve exposing getBitwiseNotOperand() as a more general helper and using that in the relevant transform.)

Diff Detail

Event Timeline

nikic created this revision.May 3 2022, 8:18 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 3 2022, 8:18 AM
nikic requested review of this revision.May 3 2022, 8:18 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 3 2022, 8:18 AM
RKSimon added inline comments.May 4 2022, 1:44 AM
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
4702

Sorry I haven't checked this properly - but do we need to confirm the size of the pre-truncated value?

nikic updated this revision to Diff 426946.May 4 2022, 1:53 AM

Check size of truncated value.

nikic marked an inline comment as done.May 4 2022, 1:55 AM
nikic added inline comments.
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
4702

I don't think this is strictly necessary, because we'd just fail the comparison between different-sized SDValues later on. However, I still think it makes sense to include the check from an API perspective, so that getBitwiseNotOperand always returns a value of the same size as its argument.

nikic updated this revision to Diff 426947.May 4 2022, 1:59 AM
nikic marked an inline comment as done.

Slightly simplify condition -- directly compare VTs rather than sizes.

RKSimon accepted this revision.May 4 2022, 3:47 AM

LGTM - cheers

This revision is now accepted and ready to land.May 4 2022, 3:47 AM
This revision was automatically updated to reflect the committed changes.