[llvm] Attributor: Don't rely on use_empty for constants (PR #137218)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 24 10:49:51 PDT 2025
https://github.com/arsenm created https://github.com/llvm/llvm-project/pull/137218
This allows inferring noalias on a null argument parameter. This
avoids a non-NFC diff in a future change.
>From c45c927526220f10722010865bb5de71790397e1 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Thu, 24 Apr 2025 19:34:23 +0200
Subject: [PATCH] Attributor: Don't rely on use_empty for constants
This allows inferring noalias on a null argument parameter. This
avoids a non-NFC diff in a future change.
---
llvm/lib/Transforms/IPO/AttributorAttributes.cpp | 2 +-
llvm/test/Transforms/Attributor/issue87856.ll | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
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)
More information about the llvm-commits
mailing list