[DAGCombine] Canonicalize operands for visitANDLike
authorWANG Rui <wangrui@loongson.cn>
Mon, 24 Jul 2023 05:24:07 +0000 (13:24 +0800)
committerWeining Lu <luweining@loongson.cn>
Mon, 24 Jul 2023 08:52:04 +0000 (16:52 +0800)
commit595d5f36f4f9cebccca9efaf0db4bc20cc44ea2f
tree9dbd831b028b3cad5b6b341d0c4083db68f744bd
parentcea980f380e1966892cf8a45064e46c757803bd1
[DAGCombine] Canonicalize operands for visitANDLike

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>
Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D154760
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/test/CodeGen/RISCV/and-add-lsr.ll