[PATCH] D50000: [Inline] Copy "null-pointer-is-valid" attribute in caller.

Manoj Gupta via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 30 12:34:18 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL338292: [Inline] Copy "null-pointer-is-valid" attribute in caller. (authored by manojgupta, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D50000?vs=158037&id=158046#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D50000

Files:
  llvm/trunk/include/llvm/IR/Attributes.td
  llvm/trunk/lib/IR/Attributes.cpp
  llvm/trunk/test/Transforms/Inline/attributes.ll


Index: llvm/trunk/lib/IR/Attributes.cpp
===================================================================
--- llvm/trunk/lib/IR/Attributes.cpp
+++ llvm/trunk/lib/IR/Attributes.cpp
@@ -1709,6 +1709,15 @@
   }
 }
 
+/// If the inlined function has "null-pointer-is-valid=true" attribute,
+/// set this attribute in the caller post inlining.
+static void
+adjustNullPointerValidAttr(Function &Caller, const Function &Callee) {
+  if (Callee.nullPointerIsDefined() && !Caller.nullPointerIsDefined()) {
+    Caller.addFnAttr(Callee.getFnAttribute("null-pointer-is-valid"));
+  }
+}
+
 #define GET_ATTR_COMPAT_FUNC
 #include "AttributesCompatFunc.inc"
 
Index: llvm/trunk/include/llvm/IR/Attributes.td
===================================================================
--- llvm/trunk/include/llvm/IR/Attributes.td
+++ llvm/trunk/include/llvm/IR/Attributes.td
@@ -236,3 +236,4 @@
 def : MergeRule<"adjustCallerStackProbes">;
 def : MergeRule<"adjustCallerStackProbeSize">;
 def : MergeRule<"adjustMinLegalVectorWidth">;
+def : MergeRule<"adjustNullPointerValidAttr">;
Index: llvm/trunk/test/Transforms/Inline/attributes.ll
===================================================================
--- llvm/trunk/test/Transforms/Inline/attributes.ll
+++ llvm/trunk/test/Transforms/Inline/attributes.ll
@@ -333,9 +333,10 @@
 ; CHECK-NEXT: ret i32
 }
 
-; Calle with "null-pointer-is-valid"="true" attribute should not be inlined
-; into a caller without this attribute. Exception: alwaysinline callee
-; can still be inlined.
+; Callee with "null-pointer-is-valid"="true" attribute should not be inlined
+; into a caller without this attribute.
+; Exception: alwaysinline callee can still be inlined but
+; "null-pointer-is-valid"="true" should get copied to caller.
 
 define i32 @null-pointer-is-valid_callee0(i32 %i) "null-pointer-is-valid"="true" {
   ret i32 %i
@@ -355,29 +356,36 @@
 ; CHECK-NEXT: ret i32
 }
 
+; No inlining since caller does not have "null-pointer-is-valid"="true" attribute.
 define i32 @test_null-pointer-is-valid0(i32 %i) {
   %1 = call i32 @null-pointer-is-valid_callee0(i32 %i)
   ret i32 %1
 ; CHECK: @test_null-pointer-is-valid0(
 ; CHECK: call i32 @null-pointer-is-valid_callee0
 ; CHECK-NEXT: ret i32
 }
 
-define i32 @test_null-pointer-is-valid1(i32 %i) {
+; alwaysinline should force inlining even when caller does not have
+; "null-pointer-is-valid"="true" attribute. However, the attribute should be
+; copied to caller.
+define i32 @test_null-pointer-is-valid1(i32 %i) "null-pointer-is-valid"="false" {
   %1 = call i32 @null-pointer-is-valid_callee1(i32 %i)
   ret i32 %1
-; CHECK: @test_null-pointer-is-valid1(
+; CHECK: @test_null-pointer-is-valid1(i32 %i) [[NULLPOINTERISVALID:#[0-9]+]] {
 ; CHECK-NEXT: ret i32
 }
 
+; Can inline since both caller and callee have "null-pointer-is-valid"="true"
+; attribute.
 define i32 @test_null-pointer-is-valid2(i32 %i) "null-pointer-is-valid"="true" {
   %1 = call i32 @null-pointer-is-valid_callee2(i32 %i)
   ret i32 %1
-; CHECK: @test_null-pointer-is-valid2(
+; CHECK: @test_null-pointer-is-valid2(i32 %i) [[NULLPOINTERISVALID]] {
 ; CHECK-NEXT: ret i32
 }
 
 ; CHECK: attributes [[FPMAD_FALSE]] = { "less-precise-fpmad"="false" }
 ; CHECK: attributes [[FPMAD_TRUE]] = { "less-precise-fpmad"="true" }
 ; CHECK: attributes [[NOIMPLICITFLOAT]] = { noimplicitfloat }
 ; CHECK: attributes [[NOUSEJUMPTABLES]] = { "no-jump-tables"="true" }
+; CHECK: attributes [[NULLPOINTERISVALID]] = { "null-pointer-is-valid"="true" }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50000.158046.patch
Type: text/x-patch
Size: 3490 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180730/440a9b93/attachment.bin>


More information about the llvm-commits mailing list