[llvm] a505801 - [rs4gc] Strip nofree and nosync attributes when lowering from abstract model

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 2 09:15:02 PDT 2021


Author: Philip Reames
Date: 2021-04-02T09:12:24-07:00
New Revision: a505801e2b7ba13b224e8f2015a64cbe03e62d35

URL: https://github.com/llvm/llvm-project/commit/a505801e2b7ba13b224e8f2015a64cbe03e62d35
DIFF: https://github.com/llvm/llvm-project/commit/a505801e2b7ba13b224e8f2015a64cbe03e62d35.diff

LOG: [rs4gc] Strip nofree and nosync attributes when lowering from abstract model

The safepoints being inserted exists to free memory, or coordinate with another thread to do so.  Thus, we must strip any inferred attributes and reinfer them after the lowering.

I'm not aware of any active miscompiles caused by this, but since I'm working on strengthening inference of both and leveraging them in the optimization decisions, I figured a bit of future proofing was warranted.

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
    llvm/test/Transforms/RewriteStatepointsForGC/strip-invalid-attributes.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
index 2603ea0f92ed..644e3c005f99 100644
--- a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
+++ b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
@@ -1348,6 +1348,8 @@ static AttributeList legalizeCallAttributes(LLVMContext &Ctx,
   AttrBuilder FnAttrs = AL.getFnAttributes();
   FnAttrs.removeAttribute(Attribute::ReadNone);
   FnAttrs.removeAttribute(Attribute::ReadOnly);
+  FnAttrs.removeAttribute(Attribute::NoSync);
+  FnAttrs.removeAttribute(Attribute::NoFree);
   for (Attribute A : AL.getFnAttributes()) {
     if (isStatepointDirectiveAttr(A))
       FnAttrs.remove(A);
@@ -2587,6 +2589,8 @@ static void RemoveNonValidAttrAtIndex(LLVMContext &Ctx, AttrHolder &AH,
                                   AH.getDereferenceableOrNullBytes(Index)));
   if (AH.getAttributes().hasAttribute(Index, Attribute::NoAlias))
     R.addAttribute(Attribute::NoAlias);
+  if (AH.getAttributes().hasAttribute(Index, Attribute::NoFree))
+    R.addAttribute(Attribute::NoFree);
 
   if (!R.empty())
     AH.setAttributes(AH.getAttributes().removeAttributes(Ctx, Index, R));
@@ -2602,6 +2606,9 @@ static void stripNonValidAttributesFromPrototype(Function &F) {
 
   if (isa<PointerType>(F.getReturnType()))
     RemoveNonValidAttrAtIndex(Ctx, F, AttributeList::ReturnIndex);
+
+  F.removeFnAttr(Attribute::NoSync);
+  F.removeFnAttr(Attribute::NoFree);
 }
 
 /// Certain metadata on instructions are invalid after running RS4GC.

diff  --git a/llvm/test/Transforms/RewriteStatepointsForGC/strip-invalid-attributes.ll b/llvm/test/Transforms/RewriteStatepointsForGC/strip-invalid-attributes.ll
index bc3d970df596..5e551293977c 100644
--- a/llvm/test/Transforms/RewriteStatepointsForGC/strip-invalid-attributes.ll
+++ b/llvm/test/Transforms/RewriteStatepointsForGC/strip-invalid-attributes.ll
@@ -43,3 +43,15 @@ define noalias i8 addrspace(1)* @noalias_ret(i8 addrspace(1)* %arg) gc "statepoi
   ret i8 addrspace(1)* %arg
 }
 
+define i8 addrspace(1)* @nofree(i8 addrspace(1)* nofree %arg) nofree gc "statepoint-example" {
+; CHECK: define i8 addrspace(1)* @nofree(i8 addrspace(1)* %arg) gc "statepoint-example" {
+  call void @f()
+  ret i8 addrspace(1)* %arg
+}
+
+define i8 addrspace(1)* @nosync(i8 addrspace(1)* %arg) nosync gc "statepoint-example" {
+; CHECK: define i8 addrspace(1)* @nosync(i8 addrspace(1)* %arg) gc "statepoint-example" {
+  call void @f()
+  ret i8 addrspace(1)* %arg
+}
+


        


More information about the llvm-commits mailing list