Skip to content

Attributor: Propagate align to cmpxchg instructions #134838

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

arsenm
Copy link
Contributor

@arsenm arsenm commented Apr 8, 2025

Fixes #134480

Copy link
Contributor Author

arsenm commented Apr 8, 2025

@arsenm arsenm requested review from jdoerfert and shiltian April 8, 2025 10:52
@arsenm arsenm marked this pull request as ready for review April 8, 2025 10:52
@llvmbot
Copy link
Member

llvmbot commented Apr 8, 2025

@llvm/pr-subscribers-llvm-transforms

Author: Matt Arsenault (arsenm)

Changes

Fixes #134480


Full diff: https://github.com/llvm/llvm-project/pull/134838.diff

2 Files Affected:

  • (modified) llvm/lib/Transforms/IPO/AttributorAttributes.cpp (+9)
  • (modified) llvm/test/Transforms/Attributor/align-atomic.ll (+1-1)
diff --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
index 717ba7f688548..cc6e846f4f211 100644
--- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
+++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
@@ -5317,6 +5317,15 @@ struct AAAlignImpl : AAAlign {
             InstrChanged = ChangeStatus::CHANGED;
           }
         }
+      } else if (auto *CAS = dyn_cast<AtomicCmpXchgInst>(U.getUser())) {
+        if (CAS->getPointerOperand() == &AssociatedValue) {
+          if (CAS->getAlign() < getAssumedAlign()) {
+            STATS_DECLTRACK(AAAlign, AtomicCmpXchg,
+                            "Number of times alignment added to cmpxchg");
+            CAS->setAlignment(getAssumedAlign());
+            InstrChanged = ChangeStatus::CHANGED;
+          }
+        }
       }
     }
 
diff --git a/llvm/test/Transforms/Attributor/align-atomic.ll b/llvm/test/Transforms/Attributor/align-atomic.ll
index 0931c14685a87..0b363741cc168 100644
--- a/llvm/test/Transforms/Attributor/align-atomic.ll
+++ b/llvm/test/Transforms/Attributor/align-atomic.ll
@@ -37,7 +37,7 @@ define ptr @atomicrmw_non_ptr_op_no_propagate(ptr %ptr, ptr align 16 %val) {
 define i32 @cmpxchg_propagate(ptr align 8 %ptr, i32 %cmp, i32 %val) {
 ; CHECK-LABEL: define i32 @cmpxchg_propagate(
 ; CHECK-SAME: ptr nofree noundef nonnull align 8 captures(none) dereferenceable(4) [[PTR:%.*]], i32 [[CMP:%.*]], i32 [[VAL:%.*]]) #[[ATTR0]] {
-; CHECK-NEXT:    [[PAIR:%.*]] = cmpxchg ptr [[PTR]], i32 [[CMP]], i32 [[VAL]] seq_cst monotonic, align 2
+; CHECK-NEXT:    [[PAIR:%.*]] = cmpxchg ptr [[PTR]], i32 [[CMP]], i32 [[VAL]] seq_cst monotonic, align 8
 ; CHECK-NEXT:    [[RESULT:%.*]] = extractvalue { i32, i1 } [[PAIR]], 0
 ; CHECK-NEXT:    ret i32 [[RESULT]]
 ;

Copy link
Contributor Author

arsenm commented Apr 8, 2025

Merge activity

  • Apr 8, 11:01 AM EDT: A user started a stack merge that includes this pull request via Graphite.
  • Apr 8, 11:13 AM EDT: Graphite rebased this pull request as part of a merge.
  • Apr 8, 11:15 AM EDT: A user merged this pull request with Graphite.

@arsenm arsenm force-pushed the users/arsenm/attributor/propagate-align-to-atomicrmw-instructions branch from 396afde to 6fa8d75 Compare April 8, 2025 15:08
Base automatically changed from users/arsenm/attributor/propagate-align-to-atomicrmw-instructions to main April 8, 2025 15:12
@arsenm arsenm force-pushed the users/arsenm/attributor/propagate-align-to-cmpxchg-instructions branch from e945a79 to 4d6890e Compare April 8, 2025 15:12
@arsenm arsenm merged commit 34e8f00 into main Apr 8, 2025
5 of 10 checks passed
@arsenm arsenm deleted the users/arsenm/attributor/propagate-align-to-cmpxchg-instructions branch April 8, 2025 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AAAlign only handles load and store uses
3 participants