[llvm] [Instcombine] Write Instcombine pass to strength reduce lock xadd to lock sub (PR #184715)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 5 06:33:03 PST 2026
================
@@ -0,0 +1,49 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
+; RUN: opt -passes=instcombine -S %s | FileCheck %s
+
+; Regression case: atomicrmw sub is unchanged by this transform.
+define i1 @fn_sub(ptr noundef nonnull align 8 captures(none) dereferenceable(8) %a, i64 noundef %n) {
+; CHECK-LABEL: define i1 @fn_sub(
+; CHECK-SAME: ptr noundef nonnull align 8 captures(none) dereferenceable(8) [[A:%.*]], i64 noundef [[N:%.*]]) {
+; CHECK-NEXT: [[ENTRY:.*:]]
+; CHECK-NEXT: [[TMP0:%.*]] = atomicrmw sub ptr [[A]], i64 [[N]] monotonic, align 8
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[TMP0]], [[N]]
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+entry:
+ %0 = atomicrmw sub ptr %a, i64 %n monotonic, align 8
+ %cmp = icmp eq i64 %0, %n
----------------
nikic wrote:
Drop the comparison, just return the value.
https://github.com/llvm/llvm-project/pull/184715
More information about the llvm-commits
mailing list