Skip to content

Attributor: Don't rely on use_empty for constants #137218

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 24, 2025

This allows inferring noalias on a null argument parameter. This
avoids a non-NFC diff in a future change.

This allows inferring noalias on a null argument parameter. This
avoids a non-NFC diff in a future change.
Copy link
Contributor Author

arsenm commented Apr 24, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

@arsenm arsenm requested review from jdoerfert and shiltian April 24, 2025 17:50
@arsenm arsenm marked this pull request as ready for review April 24, 2025 17:50
@llvmbot
Copy link
Member

llvmbot commented Apr 24, 2025

@llvm/pr-subscribers-llvm-transforms

Author: Matt Arsenault (arsenm)

Changes

This allows inferring noalias on a null argument parameter. This
avoids a non-NFC diff in a future change.


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

2 Files Affected:

  • (modified) llvm/lib/Transforms/IPO/AttributorAttributes.cpp (+1-1)
  • (modified) llvm/test/Transforms/Attributor/issue87856.ll (+1-1)
diff --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
index ac56df3823e20..1032dede7cb36 100644
--- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
+++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
@@ -5746,7 +5746,7 @@ bool AANoCapture::isImpliedByIR(Attributor &A, const IRPosition &IRP,
   assert(ImpliedAttributeKind == Attribute::Captures &&
          "Unexpected attribute kind");
   Value &V = IRP.getAssociatedValue();
-  if (!IRP.isArgumentPosition())
+  if (!isa<Constant>(V) && !IRP.isArgumentPosition())
     return V.use_empty();
 
   // You cannot "capture" null in the default address space.
diff --git a/llvm/test/Transforms/Attributor/issue87856.ll b/llvm/test/Transforms/Attributor/issue87856.ll
index 4990ef909dfaa..592ec33a31369 100644
--- a/llvm/test/Transforms/Attributor/issue87856.ll
+++ b/llvm/test/Transforms/Attributor/issue87856.ll
@@ -4,7 +4,7 @@
 define void @null_ptr_is_valid_call_with_null() #0 {
 ; CHECK-LABEL: define void @null_ptr_is_valid_call_with_null(
 ; CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
-; CHECK-NEXT:    call void @store_as0(ptr nofree noundef writeonly null) #[[ATTR4:[0-9]+]]
+; CHECK-NEXT:    call void @store_as0(ptr noalias nofree noundef writeonly null) #[[ATTR4:[0-9]+]]
 ; CHECK-NEXT:    ret void
 ;
   call void @store_as0(ptr null)

Copy link
Contributor Author

arsenm commented Apr 24, 2025

Merge activity

  • Apr 24, 3:40 PM EDT: A user started a stack merge that includes this pull request via Graphite.
  • Apr 24, 3:41 PM EDT: @arsenm merged this pull request with Graphite.

@arsenm arsenm merged commit 37b135c into main Apr 24, 2025
16 checks passed
@arsenm arsenm deleted the users/arsenm/attributor/do-not-rely-on-constants-with-use-empty branch April 24, 2025 19:41
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.

3 participants