This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Teach combineDeMorganOfBoolean to handle (and (xor X, 1), (not Y)).
ClosedPublic

Authored by craig.topper on Aug 25 2022, 9:27 AM.

Details

Summary

SimplifyDemandedBits tries to agressively turn xor immediates into -1
to match a 'not' instruction. In this case, because X is a boolean, the
upper bits of (xor X, 1) are known to be 0. Because this is an AND
instruction, that means those bits aren't demanded from the other
operand, and thus SimplifyDemandedBits can turn (xor Y, 1) to (not Y).

We need to detect that this has happened to enable the DeMorgan
optimization. To do this we allow one of the xors to use -1 when
the outer operation is And.

Diff Detail

Event Timeline

craig.topper created this revision.Aug 25 2022, 9:27 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 25 2022, 9:27 AM
craig.topper requested review of this revision.Aug 25 2022, 9:27 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 25 2022, 9:27 AM
reames accepted this revision.Aug 25 2022, 9:49 AM

LGTM w/comment addressed.

llvm/lib/Target/RISCV/RISCVISelLowering.cpp
8435

Can you reword this comment to emphasize the bit about allowing only one of the two to xor N, -1? It's the bit about the other still needing to be 0/1 for the demanded bits to work out that I had missed in the original read through.

This revision is now accepted and ready to land.Aug 25 2022, 9:49 AM

Reword comment

This revision was landed with ongoing or failed builds.Aug 25 2022, 10:56 AM
This revision was automatically updated to reflect the committed changes.