This is an archive of the discontinued LLVM Phabricator instance.

[DAGCombiner] fold or (xor x, y),? patterns
ClosedPublic

Authored by bcl5980 on Nov 20 2022, 10:47 PM.

Details

Summary

or (xor x, y), x --> or x, y
or (xor x, y), y --> or x, y
or (xor x, y), (and x, y) --> or x, y
or (xor x, y), (or x, y) --> or x, y

Diff Detail

Event Timeline

bcl5980 created this revision.Nov 20 2022, 10:47 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 20 2022, 10:47 PM
bcl5980 requested review of this revision.Nov 20 2022, 10:47 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 20 2022, 10:47 PM
foad added a comment.Nov 20 2022, 11:09 PM

Does instcombine do this at the IR level? Is there a need to do it in selectiondag too?

Does instcombine do this at the IR level? Is there a need to do it in selectiondag too?

Yeah, instsimplify do this. But I find some corner cases in selectiondag can trigger this code because of some logical op generated by SelectionDAG itself. So, I add all similar code in this change.

RKSimon added inline comments.Nov 21 2022, 3:20 AM
llvm/test/CodeGen/X86/combine-sra-load.ll
99

This test probably needs adjusting so the multiple uses of %shift remains.

foad added a comment.Nov 21 2022, 6:02 AM

Does instcombine do this at the IR level? Is there a need to do it in selectiondag too?

Yeah, instsimplify do this. But I find some corner cases in selectiondag can trigger this code because of some logical op generated by SelectionDAG itself. So, I add all similar code in this change.

Can you add a test that shows that happening?

bcl5980 updated this revision to Diff 477066.Nov 21 2022, 10:59 PM

add a test to amdgpu for or (xor x, y), x --> or x, y
adjust test sra_to_sextload_multiple_sra_uses

Does instcombine do this at the IR level? Is there a need to do it in selectiondag too?

Yeah, instsimplify do this. But I find some corner cases in selectiondag can trigger this code because of some logical op generated by SelectionDAG itself. So, I add all similar code in this change.

Can you add a test that shows that happening?

If you think the test is OK I can precommit the test.

foad added a comment.Nov 22 2022, 3:37 AM

Does instcombine do this at the IR level? Is there a need to do it in selectiondag too?

Yeah, instsimplify do this. But I find some corner cases in selectiondag can trigger this code because of some logical op generated by SelectionDAG itself. So, I add all similar code in this change.

Can you add a test that shows that happening?

If you think the test is OK I can precommit the test.

Yes, please do.

bcl5980 updated this revision to Diff 477141.Nov 22 2022, 4:44 AM

rebase code

bcl5980 marked an inline comment as done.Nov 22 2022, 4:44 AM
foad added inline comments.Nov 22 2022, 5:56 AM
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
7001–7002

Should we also handle the commuted forms of the OR?
or x, (xor x, y)
or (x and/or y), (xor x, y)

bcl5980 marked an inline comment as done.Nov 22 2022, 6:17 AM
bcl5980 added inline comments.
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
7001–7002

We already handle these case. This code is in the function visitORCommutative. It will call twice with (N0, N1) and (N1, N0).

foad accepted this revision.Nov 22 2022, 6:22 AM

LGTM, thanks.

Please consider adding a similar combine for GlobalISel.

This revision is now accepted and ready to land.Nov 22 2022, 6:22 AM
This revision was automatically updated to reflect the committed changes.
bcl5980 marked an inline comment as done.