[clang] [llvm] [InstCombine] Reassociate nested add/sub with constant (PR #191022)

Yingwei Zheng via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 9 10:09:05 PDT 2026


================
@@ -1523,6 +1523,34 @@ static Instruction *foldBoxMultiply(BinaryOperator &I) {
   return nullptr;
 }
 
+/// Canonicalize a nested add/sub with a constant on the inner RHS by
+/// sinking the constant to the outer RHS.
+/// (X +/- C) +/- Y  ->  (X +/- Y) +/- C
----------------
dtcxzyw wrote:

The optional LoopInfo dependency was dropped in https://github.com/llvm/llvm-project/commit/34b10e165d809bb133d37dfe934859800f21a100.

Not sure if InstCombine is the right place to perform the canonicalization. Is it reverted by other loop passes? cc @fhahn


https://github.com/llvm/llvm-project/pull/191022


More information about the cfe-commits mailing list