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>
Why are you having to swap all the ADD/SRL operand handling? Can't you just adjust the std::swap code above?