[llvm] [AArch64][DAG] Port adde and sube combine to AArch64 (PR #202227)
Ricardo Jesus via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 6 01:19:37 PDT 2026
================
@@ -38,6 +38,118 @@ define i32 @g_i32(i32 %a, i32 %b) nounwind {
ret i32 %r2
}
+define i64 @g_i64_add1(i64 %a, i64 %b) nounwind {
+; CHECK-LABEL: g_i64_add1:
+; CHECK: // %bb.0:
+; CHECK-NEXT: subs x8, x0, x1
+; CHECK-NEXT: cinc x0, x8, hs
+; CHECK-NEXT: ret
+ %ov = call {i64, i1} @llvm.usub.with.overflow.i64(i64 %a, i64 %b)
+ %val = extractvalue { i64, i1 } %ov, 0
+ %bit = extractvalue { i64, i1 } %ov, 1
+ %ext = sext i1 %bit to i64
+ %r = add i64 %val, %ext
+ %r2 = add i64 %r, 1
+ ret i64 %r2
+}
+
+define i32 @g_i32_add1(i32 %a, i32 %b) nounwind {
+; CHECK-LABEL: g_i32_add1:
+; CHECK: // %bb.0:
+; CHECK-NEXT: subs w8, w0, w1
+; CHECK-NEXT: cinc w0, w8, hs
+; CHECK-NEXT: ret
+ %ov = call {i32, i1} @llvm.usub.with.overflow.i32(i32 %a, i32 %b)
+ %val = extractvalue { i32, i1 } %ov, 0
+ %bit = extractvalue { i32, i1 } %ov, 1
+ %ext = sext i1 %bit to i32
+ %r = add i32 %val, %ext
+ %r2 = add i32 %r, 1
+ ret i32 %r2
+}
+
+; Fold should fire for negative constant addend with single use
+define i64 @g_i64_neg10(i64 %a, i64 %b) nounwind {
+; CHECK-LABEL: g_i64_neg10:
+; CHECK: // %bb.0:
+; CHECK-NEXT: mov w8, #10 // =0xa
+; CHECK-NEXT: subs x9, x0, x1
+; CHECK-NEXT: sbc x0, x9, x8
+; CHECK-NEXT: ret
+ %ov = call {i64, i1} @llvm.usub.with.overflow.i64(i64 %a, i64 %b)
+ %val = extractvalue { i64, i1 } %ov, 0
+ %bit = extractvalue { i64, i1 } %ov, 1
+ %ext = sext i1 %bit to i64
+ %r = add i64 %val, %ext
+ %r2 = add i64 %r, -10
+ ret i64 %r2
+}
----------------
rj-jesus wrote:
It doesn't look like the generated code here is due to this PR: https://godbolt.org/z/rn1Kz6rEq.
https://github.com/llvm/llvm-project/pull/202227
More information about the llvm-commits
mailing list