[InstCombine] reassociate subtract-from-constant to add-constant
authorSanjay Patel <spatel@rotateright.com>
Tue, 28 Feb 2023 19:18:28 +0000 (14:18 -0500)
committerSanjay Patel <spatel@rotateright.com>
Tue, 28 Feb 2023 19:21:13 +0000 (14:21 -0500)
commit542e70f96c56edbcab5278c2952caa1a3f963fe6
tree2cf03522a76f1bf79af72cb255f8c2800941045b
parenta721b6b17902439e6974209119ad5f6830ed5e4c
[InstCombine] reassociate subtract-from-constant to add-constant

(C - X) + Y --> (Y - X) + C

Moving the constant operand to an 'add' gives more
flexibility to subsequent reassociation patterns,
and it may be better for codegen on targets that
don't have subtract-from-immediate instructions.
llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
llvm/test/Transforms/InstCombine/addsub-constant-folding.ll