[llvm] r265060 - [NVPTX] Infer __nvvm_reflect as nounwind, readnone

David Majnemer via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 31 14:29:57 PDT 2016


Author: majnemer
Date: Thu Mar 31 16:29:57 2016
New Revision: 265060

URL: http://llvm.org/viewvc/llvm-project?rev=265060&view=rev
Log:
[NVPTX] Infer __nvvm_reflect as nounwind, readnone

This patch simply mirrors the attributes we give to @llvm.nvvm.reflect
to the __nvvm_reflect libdevice call.  This shaves about 30% of the code
in libdevice away because of CSE opportunities.  It's also helps us
figure out that libdevice implementations of transcendental functions
don't have side-effects.

Modified:
    llvm/trunk/include/llvm/Analysis/TargetLibraryInfo.def
    llvm/trunk/lib/Analysis/TargetLibraryInfo.cpp
    llvm/trunk/lib/Transforms/IPO/InferFunctionAttrs.cpp
    llvm/trunk/test/Transforms/InferFunctionAttrs/annotate.ll

Modified: llvm/trunk/include/llvm/Analysis/TargetLibraryInfo.def
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/TargetLibraryInfo.def?rev=265060&r1=265059&r2=265060&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/TargetLibraryInfo.def (original)
+++ llvm/trunk/include/llvm/Analysis/TargetLibraryInfo.def Thu Mar 31 16:29:57 2016
@@ -195,6 +195,11 @@ TLI_DEFINE_STRING_INTERNAL("__memmove_ch
 /// void *__memset_chk(void *s, char v, size_t n, size_t s1size);
 TLI_DEFINE_ENUM_INTERNAL(memset_chk)
 TLI_DEFINE_STRING_INTERNAL("__memset_chk")
+
+// int __nvvm_reflect(const char *)
+TLI_DEFINE_ENUM_INTERNAL(nvvm_reflect)
+TLI_DEFINE_STRING_INTERNAL("__nvvm_reflect")
+
 /// double __sincospi_stret(double x);
 TLI_DEFINE_ENUM_INTERNAL(sincospi_stret)
 TLI_DEFINE_STRING_INTERNAL("__sincospi_stret")

Modified: llvm/trunk/lib/Analysis/TargetLibraryInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/TargetLibraryInfo.cpp?rev=265060&r1=265059&r2=265060&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/TargetLibraryInfo.cpp (original)
+++ llvm/trunk/lib/Analysis/TargetLibraryInfo.cpp Thu Mar 31 16:29:57 2016
@@ -396,8 +396,12 @@ static void initialize(TargetLibraryInfo
   //
   // FIXME: Having no standard library prevents e.g. many fastmath
   // optimizations, so this situation should be fixed.
-  if (T.isNVPTX())
+  if (T.isNVPTX()) {
     TLI.disableAllFunctions();
+    TLI.setAvailable(LibFunc::nvvm_reflect);
+  } else {
+    TLI.setUnavailable(LibFunc::nvvm_reflect);
+  }
 
   TLI.addVectorizableFunctionsFromVecLib(ClVectorLibrary);
 }

Modified: llvm/trunk/lib/Transforms/IPO/InferFunctionAttrs.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/InferFunctionAttrs.cpp?rev=265060&r1=265059&r2=265060&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/InferFunctionAttrs.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/InferFunctionAttrs.cpp Thu Mar 31 16:29:57 2016
@@ -924,6 +924,15 @@ static bool inferPrototypeAttributes(Fun
     Changed |= setOnlyReadsMemory(F, 2);
     return Changed;
 
+  // int __nvvm_reflect(const char *)
+  case LibFunc::nvvm_reflect:
+    if (FTy->getNumParams() != 1 || !isa<PointerType>(FTy->getParamType(0)))
+      return false;
+
+    Changed |= setDoesNotAccessMemory(F);
+    Changed |= setDoesNotThrow(F);
+    return Changed;
+
   default:
     // FIXME: It'd be really nice to cover all the library functions we're
     // aware of here.

Modified: llvm/trunk/test/Transforms/InferFunctionAttrs/annotate.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InferFunctionAttrs/annotate.ll?rev=265060&r1=265059&r2=265060&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InferFunctionAttrs/annotate.ll (original)
+++ llvm/trunk/test/Transforms/InferFunctionAttrs/annotate.ll Thu Mar 31 16:29:57 2016
@@ -1,6 +1,7 @@
 ; RUN: opt < %s -inferattrs -S | FileCheck %s
 ; RUN: opt < %s -passes=inferattrs -S | FileCheck %s
 ; RUN: opt < %s -mtriple=x86_64-apple-macosx10.8.0 -inferattrs -S | FileCheck -check-prefix=CHECK-POSIX %s
+; RUN: opt < %s -mtriple=nvptx -inferattrs -S | FileCheck -check-prefix=CHECK-NVPTX %s
 
 declare i8* @fopen(i8*, i8*)
 ; CHECK: declare noalias i8* @fopen(i8* nocapture readonly, i8* nocapture readonly) [[G0:#[0-9]]] 
@@ -33,3 +34,7 @@ declare i32 @gettimeofday(i8*, i8*)
 ; CHECK: attributes [[G1]] = { nounwind readonly }
 ; CHECK-POSIX: attributes [[G0]] = { nounwind }
 ; CHECK-POSIX: attributes [[G2]] = { argmemonly }
+
+declare i32 @__nvvm_reflect(i8*)
+; CHECK-NVPTX: declare i32 @__nvvm_reflect(i8*) [[G0:#[0-9]+]]
+; CHECK-NVPTX: attributes [[G0]] = { nounwind readnone }




More information about the llvm-commits mailing list