[DAGCombiner] Avoid converting (x or/xor const) + y to (x + y) + const if benefit...
authorJuneyoung Lee <aqjune@gmail.com>
Wed, 15 Feb 2023 18:05:20 +0000 (18:05 +0000)
committerJuneyoung Lee <aqjune@gmail.com>
Wed, 8 Mar 2023 18:13:57 +0000 (18:13 +0000)
commita66bc1c4a30ca958fee094bd7dcb6bc4b9cdd49f
tree3847910ccd1887c988b1076e848054fcd6687dcb
parent79ebb6385b3afe2b78a6923b3bbddadb791b7840
[DAGCombiner] Avoid converting (x or/xor const) + y to (x + y) + const if benefit is unclear

This patch resolves suboptimal code generation reported by https://github.com/llvm/llvm-project/issues/60571 .

DAGCombiner currently converts `(x or/xor const) + y` to `(x + y) + const` if this is valid.
However, if `.. + const` is broken down into a sequences of adds with carries, the benefit is not clear, introducing two more add(-with-carry) ops (total 6) in the case of the reported issue whereas the optimal sequence must only have 4 add(-with-carry)s.

This patch resolves this issue by allowing this conversion only when (1) `.. + const` is legal or promotable, or (2) `const` is a sign bit because it does not introduce more adds.

Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D144116
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/test/CodeGen/AArch64/add-i256.ll [new file with mode: 0644]