[llvm] 800eba8 - [Attributor] Fix nofree inference for stores (#195656)
via llvm-commits
llvm-commits at lists.llvm.org
Mon May 4 09:41:48 PDT 2026
Author: Nikita Popov
Date: 2026-05-04T18:41:42+02:00
New Revision: 800eba89ea7f5541dfe5794c58612992b1f1a818
URL: https://github.com/llvm/llvm-project/commit/800eba89ea7f5541dfe5794c58612992b1f1a818
DIFF: https://github.com/llvm/llvm-project/commit/800eba89ea7f5541dfe5794c58612992b1f1a818.diff
LOG: [Attributor] Fix nofree inference for stores (#195656)
Stores were treated as nofree, but this is only valid for the store
pointer operand. If it's the value operand, the pointer may be re-loaded
and then freed.
Added:
Modified:
llvm/lib/Transforms/IPO/AttributorAttributes.cpp
llvm/test/Transforms/Attributor/openmp_parallel.ll
llvm/test/Transforms/Attributor/readattrs.ll
llvm/test/Transforms/Attributor/value-simplify-pointer-info.ll
llvm/test/Transforms/FunctionAttrs/readattrs.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
index 370fd5066deb5..7c50b9faf3c80 100644
--- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
+++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
@@ -2357,9 +2357,12 @@ struct AANoFreeFloating : AANoFreeImpl {
Follow = true;
return true;
}
- if (isa<StoreInst>(UserI) || isa<LoadInst>(UserI))
+ if (isa<LoadInst>(UserI))
return true;
+ if (isa<StoreInst>(UserI))
+ return U.getOperandNo() == StoreInst::getPointerOperandIndex();
+
if (isa<ReturnInst>(UserI) && getIRPosition().isArgumentPosition())
return true;
diff --git a/llvm/test/Transforms/Attributor/openmp_parallel.ll b/llvm/test/Transforms/Attributor/openmp_parallel.ll
index ca2c3cf8d2a29..4f7033f474d14 100644
--- a/llvm/test/Transforms/Attributor/openmp_parallel.ll
+++ b/llvm/test/Transforms/Attributor/openmp_parallel.ll
@@ -33,7 +33,7 @@ define dso_local void @func(ptr nocapture %a, ptr %b, i32 %N) local_unnamed_addr
;
; CGSCC: Function Attrs: nounwind uwtable
; CGSCC-LABEL: define {{[^@]+}}@func
-; CGSCC-SAME: (ptr nofree captures(none) [[A:%.*]], ptr nofree [[B:%.*]], i32 [[N:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+; CGSCC-SAME: (ptr captures(none) [[A:%.*]], ptr [[B:%.*]], i32 [[N:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
; CGSCC-NEXT: entry:
; CGSCC-NEXT: [[A_ADDR:%.*]] = alloca ptr, align 8
; CGSCC-NEXT: [[B_ADDR:%.*]] = alloca ptr, align 8
diff --git a/llvm/test/Transforms/Attributor/readattrs.ll b/llvm/test/Transforms/Attributor/readattrs.ll
index d36ab4801c585..a9cdd46b4eef7 100644
--- a/llvm/test/Transforms/Attributor/readattrs.ll
+++ b/llvm/test/Transforms/Attributor/readattrs.ll
@@ -76,7 +76,7 @@ declare void @test6_1()
; This is not a missed optz'n.
define void @test6_2(ptr %p, ptr %q) {
; CHECK-LABEL: define {{[^@]+}}@test6_2
-; CHECK-SAME: (ptr nofree noundef nonnull writeonly align 8 captures(none) dereferenceable(8) [[P:%.*]], ptr nofree [[Q:%.*]]) {
+; CHECK-SAME: (ptr nofree noundef nonnull writeonly align 8 captures(none) dereferenceable(8) [[P:%.*]], ptr [[Q:%.*]]) {
; CHECK-NEXT: store ptr [[Q]], ptr [[P]], align 8
; CHECK-NEXT: call void @test6_1()
; CHECK-NEXT: ret void
diff --git a/llvm/test/Transforms/Attributor/value-simplify-pointer-info.ll b/llvm/test/Transforms/Attributor/value-simplify-pointer-info.ll
index 1742bf98adaa9..164e3a7ba4bd9 100644
--- a/llvm/test/Transforms/Attributor/value-simplify-pointer-info.ll
+++ b/llvm/test/Transforms/Attributor/value-simplify-pointer-info.ll
@@ -2663,7 +2663,7 @@ define dso_local void @test_nested_memory(ptr %dst, ptr %src) {
; TUNIT-NEXT: ret void
;
; CGSCC-LABEL: define dso_local void @test_nested_memory(
-; CGSCC-SAME: ptr nofree [[DST:%.*]], ptr nofree [[SRC:%.*]]) {
+; CGSCC-SAME: ptr [[DST:%.*]], ptr [[SRC:%.*]]) {
; CGSCC-NEXT: [[ENTRY:.*:]]
; CGSCC-NEXT: [[LOCAL:%.*]] = alloca [[STRUCT_STY:%.*]], align 8
; CGSCC-NEXT: [[INNER:%.*]] = getelementptr inbounds [[STRUCT_STY]], ptr [[LOCAL]], i64 0, i32 2
diff --git a/llvm/test/Transforms/FunctionAttrs/readattrs.ll b/llvm/test/Transforms/FunctionAttrs/readattrs.ll
index 2663c2a619d75..264f6efb9530a 100644
--- a/llvm/test/Transforms/FunctionAttrs/readattrs.ll
+++ b/llvm/test/Transforms/FunctionAttrs/readattrs.ll
@@ -138,13 +138,13 @@ define void @test6_2(ptr %p, ptr %q) {
; FNATTRS-NEXT: ret void
;
; ATTRIBUTOR-LABEL: define {{[^@]+}}@test6_2
-; ATTRIBUTOR-SAME: (ptr nofree nonnull writeonly captures(none) [[P:%.*]], ptr nofree [[Q:%.*]]) {
+; ATTRIBUTOR-SAME: (ptr nofree nonnull writeonly captures(none) [[P:%.*]], ptr [[Q:%.*]]) {
; ATTRIBUTOR-NEXT: store ptr [[Q]], ptr [[P]], align 8
; ATTRIBUTOR-NEXT: call void @test6_1()
; ATTRIBUTOR-NEXT: ret void
;
; ATTRIBUTOR-CGSCC-LABEL: define {{[^@]+}}@test6_2
-; ATTRIBUTOR-CGSCC-SAME: (ptr nofree nonnull writeonly captures(none) [[P:%.*]], ptr nofree [[Q:%.*]]) {
+; ATTRIBUTOR-CGSCC-SAME: (ptr nofree nonnull writeonly captures(none) [[P:%.*]], ptr [[Q:%.*]]) {
; ATTRIBUTOR-CGSCC-NEXT: store ptr [[Q]], ptr [[P]], align 8
; ATTRIBUTOR-CGSCC-NEXT: call void @test6_1()
; ATTRIBUTOR-CGSCC-NEXT: ret void
More information about the llvm-commits
mailing list