This is an archive of the discontinued LLVM Phabricator instance.

[DAGCombine] Canonicalize operands for visitANDLike
ClosedPublic

Authored by hev on Jul 8 2023, 1:09 AM.

Details

Summary

During the construction of SelectionDAG, there are no explicit canonicalization rules to adjust the order of operands for AND nodes. This may prevent the optimization in DAGCombiner::visitANDLike from being triggered. This patch canonicalizes the operands before matches, which can be observed to improve optimization on the RISC-V target architecture.

Canonicalize:

and(x, add) -> and(add, x)

Signed-off-by: WANG Rui <wangrui@loongson.cn>

Diff Detail

Event Timeline

hev created this revision.Jul 8 2023, 1:09 AM
hev requested review of this revision.Jul 8 2023, 1:09 AM

please can you add test cases?

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

Why are you having to swap all the ADD/SRL operand handling? Can't you just adjust the std::swap code above?

hev added a comment.Jul 8 2023, 6:25 AM

Thanks.

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

The following has another match N0 == ISD::SRL.

6234–6235

Here

hev updated this revision to Diff 538368.Jul 8 2023, 6:25 AM

Add a test case.

asb added a comment.Jul 9 2023, 9:41 AM

@hev you don't seem to have used update_llc_test_checks.py to regenerate the test case, as the new function doesn't have RV32I check lines, and RV64I check lines weren't added to @main.

jrtc27 added a comment.Jul 9 2023, 9:44 AM

And when you do that, please put the new tests in their own commit so this one shows the diff to the generated code

hev updated this revision to Diff 538484.Jul 9 2023, 7:12 PM

Rebase and update test case.

Description should say what the canonicalization is.

hev updated this revision to Diff 538523.Jul 10 2023, 12:24 AM
hev edited the summary of this revision. (Show Details)
  1. Update test case.
  2. Update description.

@hev please can you rebase after D146121?

hev updated this revision to Diff 541422.Jul 18 2023, 3:16 AM
hev edited the summary of this revision. (Show Details)

@RKSimon rebase done.

RKSimon accepted this revision.Jul 18 2023, 5:04 AM

LGTM - cheers

This revision is now accepted and ready to land.Jul 18 2023, 5:04 AM
This revision was automatically updated to reflect the committed changes.