This is an archive of the discontinued LLVM Phabricator instance.

[DAGCombiner] Add fold for `~x & x` -> `0`
ClosedPublic

Authored by goldstein.w.n on Mar 1 2023, 11:43 PM.

Details

Summary

This is generally done by the InstCombine, but can be emitted as an
intermediate step and is cheap to handle.

Diff Detail

Event Timeline

goldstein.w.n created this revision.Mar 1 2023, 11:43 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 1 2023, 11:43 PM
goldstein.w.n requested review of this revision.Mar 1 2023, 11:43 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 1 2023, 11:43 PM

Did you look at performing this inside SimplifyDemandedBits instead?

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
6636

Use isBitwiseNot / getBitwiseNotOperand ?

Did you look at performing this inside SimplifyDemandedBits instead?

Just took a look. Seems to me SimplifyDemandedBits is not really the place to check for patterns between operands, but could move there if you prefer

goldstein.w.n marked an inline comment as done.Mar 2 2023, 12:29 PM
goldstein.w.n added inline comments.
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
6636

Made new helper that uses isBitwiseNot.

goldstein.w.n marked an inline comment as done.

Use new helper + isBitwiseNot

RKSimon accepted this revision.Mar 2 2023, 2:11 PM

LGTM with a couple of minors

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
6634

Don't bother with the helper - just inline the check.

6636

Use VT instead of getScalarValueSizeInBits/getValueType

This revision is now accepted and ready to land.Mar 2 2023, 2:11 PM
RKSimon added inline comments.Mar 2 2023, 2:13 PM
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
6634

Keep areBitwiseNotOfEachother - sorry I didn't see D145177 :)

goldstein.w.n marked an inline comment as done.Mar 2 2023, 11:40 PM
goldstein.w.n added inline comments.
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
6636

Also change for the add patch.

goldstein.w.n marked an inline comment as done.Mar 2 2023, 11:40 PM
This revision was landed with ongoing or failed builds.Mar 6 2023, 6:31 PM
This revision was automatically updated to reflect the committed changes.