[llvm] [InstCombine] Generalize `(A + 1) + ~B` fold to any constant (PR #188271)

Ricardo Jesus via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 9 07:54:05 PDT 2026


================
@@ -94,7 +155,7 @@ define i32 @t6(i32 %x, i32 %y) {
 ; CHECK-NEXT:    [[T0:%.*]] = xor i32 [[X:%.*]], -1
 ; CHECK-NEXT:    [[T1:%.*]] = add i32 [[Y:%.*]], [[T0]]
 ; CHECK-NEXT:    call void @use32(i32 [[T1]])
-; CHECK-NEXT:    [[T2:%.*]] = sub i32 [[Y]], [[X]]
+; CHECK-NEXT:    [[T2:%.*]] = add i32 [[T1]], 1
----------------
rj-jesus wrote:

I think the SUB was preferable and preserves the behaviour before this generalisation. Perhaps add a multi-use exception for (A + ~B) + 1 as you did for (A + 1) + ~B.

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


More information about the llvm-commits mailing list