[InstCombine] Fold `((X - Y) - Z)` to `X - (Y + Z)` (PR49858)
authorRoman Lebedev <lebedev.ri@gmail.com>
Tue, 6 Apr 2021 12:02:53 +0000 (15:02 +0300)
committerRoman Lebedev <lebedev.ri@gmail.com>
Tue, 6 Apr 2021 12:58:14 +0000 (15:58 +0300)
commit31d219d2997fed1b7dc97e0adf170d5aaf65883e
treea9e502a44434623475390a0e53aa8e745f5919e1
parent5ab489d9ae99c60d6f7e1e01194e0b4aacaf68af
[InstCombine] Fold `((X - Y) - Z)` to `X - (Y + Z)` (PR49858)

https://alive2.llvm.org/ce/z/67w-wQ

We prefer `add`s over `sub`, and this particular xform
allows further folds to happen:

Fixes https://bugs.llvm.org/show_bug.cgi?id=49858
llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
llvm/test/Transforms/InstCombine/abs-1.ll
llvm/test/Transforms/InstCombine/sub-from-sub.ll