[llvm] r251333 - [RS4GC] Strip noalias attribute after statepoint rewrite
Igor Laevsky via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 26 12:06:01 PDT 2015
Author: igor.laevsky
Date: Mon Oct 26 14:06:01 2015
New Revision: 251333
URL: http://llvm.org/viewvc/llvm-project?rev=251333&view=rev
Log:
[RS4GC] Strip noalias attribute after statepoint rewrite
We should remove noalias along with dereference and dereference_or_null attributes
because statepoint could potentially touch the entire heap including noalias objects.
Differential Revision: http://reviews.llvm.org/D14032
Modified:
llvm/trunk/include/llvm/IR/CallSite.h
llvm/trunk/include/llvm/IR/Function.h
llvm/trunk/include/llvm/IR/Instructions.h
llvm/trunk/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
llvm/trunk/test/Transforms/RewriteStatepointsForGC/deopt-bundles/deref-pointers.ll
llvm/trunk/test/Transforms/RewriteStatepointsForGC/deref-pointers.ll
Modified: llvm/trunk/include/llvm/IR/CallSite.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/CallSite.h?rev=251333&r1=251332&r2=251333&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/CallSite.h (original)
+++ llvm/trunk/include/llvm/IR/CallSite.h Mon Oct 26 14:06:01 2015
@@ -262,6 +262,13 @@ public:
CALLSITE_DELEGATE_GETTER(getDereferenceableOrNullBytes(i));
}
+ /// @brief Determine if the parameter or return value is marked with NoAlias
+ /// attribute.
+ /// @param n The parameter to check. 1 is the first parameter, 0 is the return
+ bool doesNotAlias(unsigned n) const {
+ CALLSITE_DELEGATE_GETTER(doesNotAlias(n));
+ }
+
/// \brief Return true if the call should not be treated as a call to a
/// builtin.
bool isNoBuiltin() const {
Modified: llvm/trunk/include/llvm/IR/Function.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Function.h?rev=251333&r1=251332&r2=251333&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/Function.h (original)
+++ llvm/trunk/include/llvm/IR/Function.h Mon Oct 26 14:06:01 2015
@@ -348,7 +348,8 @@ public:
AttributeSets.hasAttribute(2, Attribute::StructRet);
}
- /// @brief Determine if the parameter does not alias other parameters.
+ /// @brief Determine if the parameter or return value is marked with NoAlias
+ /// attribute.
/// @param n The parameter to check. 1 is the first parameter, 0 is the return
bool doesNotAlias(unsigned n) const {
return AttributeSets.hasAttribute(n, Attribute::NoAlias);
Modified: llvm/trunk/include/llvm/IR/Instructions.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Instructions.h?rev=251333&r1=251332&r2=251333&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/Instructions.h (original)
+++ llvm/trunk/include/llvm/IR/Instructions.h Mon Oct 26 14:06:01 2015
@@ -1618,6 +1618,13 @@ public:
return AttributeList.getDereferenceableOrNullBytes(i);
}
+ /// @brief Determine if the parameter or return value is marked with NoAlias
+ /// attribute.
+ /// @param n The parameter to check. 1 is the first parameter, 0 is the return
+ bool doesNotAlias(unsigned n) const {
+ return AttributeList.hasAttribute(n, Attribute::NoAlias);
+ }
+
/// \brief Return true if the call should not be treated as a call to a
/// builtin.
bool isNoBuiltin() const {
@@ -3480,6 +3487,13 @@ public:
return AttributeList.getDereferenceableOrNullBytes(i);
}
+ /// @brief Determine if the parameter or return value is marked with NoAlias
+ /// attribute.
+ /// @param n The parameter to check. 1 is the first parameter, 0 is the return
+ bool doesNotAlias(unsigned n) const {
+ return AttributeList.hasAttribute(n, Attribute::NoAlias);
+ }
+
/// \brief Return true if the call should not be treated as a call to a
/// builtin.
bool isNoBuiltin() const {
Modified: llvm/trunk/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp?rev=251333&r1=251332&r2=251333&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp Mon Oct 26 14:06:01 2015
@@ -115,7 +115,8 @@ struct RewriteStatepointsForGC : public
/// heap. stripNonValidAttributes (conservatively) restores correctness
/// by erasing all attributes in the module that externally imply
/// dereferenceability.
- ///
+ /// Similar reasoning also applies to the noalias attributes. gc.statepoint
+ /// can touch the entire heap including noalias objects.
void stripNonValidAttributes(Module &M);
// Helpers for stripNonValidAttributes
@@ -2501,6 +2502,8 @@ static void RemoveNonValidAttrAtIndex(LL
if (AH.getDereferenceableOrNullBytes(Index))
R.addAttribute(Attribute::get(Ctx, Attribute::DereferenceableOrNull,
AH.getDereferenceableOrNullBytes(Index)));
+ if (AH.doesNotAlias(Index))
+ R.addAttribute(Attribute::NoAlias);
if (!R.empty())
AH.setAttributes(AH.getAttributes().removeAttributes(
Modified: llvm/trunk/test/Transforms/RewriteStatepointsForGC/deopt-bundles/deref-pointers.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/RewriteStatepointsForGC/deopt-bundles/deref-pointers.ll?rev=251333&r1=251332&r2=251333&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/RewriteStatepointsForGC/deopt-bundles/deref-pointers.ll (original)
+++ llvm/trunk/test/Transforms/RewriteStatepointsForGC/deopt-bundles/deref-pointers.ll Mon Oct 26 14:06:01 2015
@@ -3,6 +3,7 @@
; CHECK: declare i8 addrspace(1)* @some_function_ret_deref()
; CHECK: define i8 addrspace(1)* @test_deref_arg(i8 addrspace(1)* %a)
; CHECK: define i8 addrspace(1)* @test_deref_or_null_arg(i8 addrspace(1)* %a)
+; CHECK: define i8 addrspace(1)* @test_noalias_arg(i8 addrspace(1)* %a)
declare void @foo()
@@ -11,6 +12,7 @@ declare i8 addrspace(1)* @some_function(
declare void @some_function_consumer(i8 addrspace(1)*) "gc-leaf-function"
declare dereferenceable(4) i8 addrspace(1)* @some_function_ret_deref() "gc-leaf-function"
+declare noalias i8 addrspace(1)* @some_function_ret_noalias() "gc-leaf-function"
define i8 addrspace(1)* @test_deref_arg(i8 addrspace(1)* dereferenceable(4) %a) gc "statepoint-example" {
entry:
@@ -24,6 +26,12 @@ entry:
ret i8 addrspace(1)* %a
}
+define i8 addrspace(1)* @test_noalias_arg(i8 addrspace(1)* noalias %a) gc "statepoint-example" {
+entry:
+ call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
+ ret i8 addrspace(1)* %a
+}
+
define i8 addrspace(1)* @test_deref_retval() gc "statepoint-example" {
; CHECK-LABEL: @test_deref_retval(
; CHECK: %a = call i8 addrspace(1)* @some_function()
@@ -42,6 +50,15 @@ entry:
ret i8 addrspace(1)* %a
}
+define i8 addrspace(1)* @test_noalias_retval() gc "statepoint-example" {
+; CHECK-LABEL: @test_noalias_retval(
+; CHECK: %a = call i8 addrspace(1)* @some_function()
+entry:
+ %a = call noalias i8 addrspace(1)* @some_function()
+ call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
+ ret i8 addrspace(1)* %a
+}
+
define i8 @test_md(i8 addrspace(1)* %ptr) gc "statepoint-example" {
; CHECK-LABEL: @test_md(
; CHECK: %tmp = load i8, i8 addrspace(1)* %ptr, !tbaa !0
@@ -61,6 +78,16 @@ entry:
ret i8 addrspace(1)* %a
}
+define i8 addrspace(1)* @test_decl_only_noalias(i8 addrspace(1)* %ptr) gc "statepoint-example" {
+; CHECK-LABEL: @test_decl_only_noalias(
+; No change here, but the prototype of some_function_ret_noalias should have changed.
+; CHECK: call i8 addrspace(1)* @some_function_ret_noalias()
+entry:
+ %a = call i8 addrspace(1)* @some_function_ret_noalias()
+ call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
+ ret i8 addrspace(1)* %a
+}
+
define i8 addrspace(1)* @test_callsite_arg_attribute(i8 addrspace(1)* %ptr) gc "statepoint-example" {
; CHECK-LABEL: @test_callsite_arg_attribute(
; CHECK: call void @some_function_consumer(i8 addrspace(1)* %ptr)
@@ -68,7 +95,7 @@ define i8 addrspace(1)* @test_callsite_a
; CHECK: !1 = !{!"red", !2}
; CHECK: !2 = !{!"blue"}
entry:
- call void @some_function_consumer(i8 addrspace(1)* dereferenceable(4) %ptr)
+ call void @some_function_consumer(i8 addrspace(1)* dereferenceable(4) noalias %ptr)
call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
ret i8 addrspace(1)* %ptr
}
Modified: llvm/trunk/test/Transforms/RewriteStatepointsForGC/deref-pointers.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/RewriteStatepointsForGC/deref-pointers.ll?rev=251333&r1=251332&r2=251333&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/RewriteStatepointsForGC/deref-pointers.ll (original)
+++ llvm/trunk/test/Transforms/RewriteStatepointsForGC/deref-pointers.ll Mon Oct 26 14:06:01 2015
@@ -5,6 +5,8 @@ declare i8 addrspace(1)* @some_function(
declare void @some_function_consumer(i8 addrspace(1)*)
declare dereferenceable(4) i8 addrspace(1)* @some_function_ret_deref()
; CHECK: declare i8 addrspace(1)* @some_function_ret_deref()
+declare noalias i8 addrspace(1)* @some_function_ret_noalias()
+; CHECK: declare i8 addrspace(1)* @some_function_ret_noalias()
define i8 addrspace(1)* @test_deref_arg(i8 addrspace(1)* dereferenceable(4) %a) gc "statepoint-example" {
; CHECK: define i8 addrspace(1)* @test_deref_arg(i8 addrspace(1)* %a)
@@ -65,6 +67,41 @@ entry:
call i32 (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @foo, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0)
ret i8 addrspace(1)* %ptr
}
+
+define i8 addrspace(1)* @test_noalias_arg(i8 addrspace(1)* noalias %a) gc "statepoint-example" {
+; CHECK: define i8 addrspace(1)* @test_noalias_arg(i8 addrspace(1)* %a)
+entry:
+ call i32 (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @foo, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0)
+ ret i8 addrspace(1)* %a
+}
+
+define i8 addrspace(1)* @test_noalias_retval() gc "statepoint-example" {
+; CHECK-LABEL: @test_noalias_retval(
+entry:
+ %a = call noalias i8 addrspace(1)* @some_function()
+; CHECK: %a = call i8 addrspace(1)* @some_function()
+ call i32 (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @foo, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0)
+ ret i8 addrspace(1)* %a
+}
+
+define i8 addrspace(1)* @test_decl_only_noalias(i8 addrspace(1)* %ptr) gc "statepoint-example" {
+; CHECK-LABEL: @test_decl_only_noalias(
+entry:
+; No change here, but the prototype of some_function_ret_noalias should have changed.
+; CHECK: call i8 addrspace(1)* @some_function_ret_noalias()
+ %a = call i8 addrspace(1)* @some_function_ret_noalias()
+ call i32 (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @foo, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0)
+ ret i8 addrspace(1)* %a
+}
+
+define i8 addrspace(1)* @test_callsite_arg_noalias(i8 addrspace(1)* %ptr) gc "statepoint-example" {
+; CHECK-LABEL: @test_callsite_arg_noalias(
+entry:
+; CHECK: call void @some_function_consumer(i8 addrspace(1)* %ptr)
+ call void @some_function_consumer(i8 addrspace(1)* noalias %ptr)
+ call i32 (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @foo, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0)
+ ret i8 addrspace(1)* %ptr
+}
declare i32 @llvm.experimental.gc.statepoint.p0f_isVoidf(i64, i32, void ()*, i32, i32, ...)
More information about the llvm-commits
mailing list