Reland [InstCombine] Fold `((X - Y) - Z)` to `X - (Y + Z)` (PR49858)
authorRoman Lebedev <lebedev.ri@gmail.com>
Wed, 7 Apr 2021 08:04:57 +0000 (11:04 +0300)
committerRoman Lebedev <lebedev.ri@gmail.com>
Wed, 7 Apr 2021 09:06:25 +0000 (12:06 +0300)
commit2829094a8e252d04f13aabdf6f416c42a06af695
treee5e22d4714b45721c068faac843988ffe883181f
parent93d1d94b745b940c9ad0adf20322eb16ed624ef3
Reland [InstCombine] Fold `((X - Y) - Z)` to `X - (Y + Z)` (PR49858)

This reverts commit a547b4e26b311e417cd51100e379693f51a3f448,
relanding commit 31d219d2997fed1b7dc97e0adf170d5aaf65883e,
which was reverted because there was a conflicting inverse transform,
which was causing an endless combine loop, which has now been adjusted.

Original commit message:

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
clang/test/CodeGen/builtins-ppc-quadword-noi128.c
llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
llvm/test/Transforms/InstCombine/abs-1.ll
llvm/test/Transforms/InstCombine/sub-from-sub.ll