[PATCH] D103944: Set local_unnamed_addr for new library function declarations in InjectTLIMappings.

Wang Tianqing via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 10 01:25:31 PDT 2021


tianqing updated this revision to Diff 351088.
tianqing added a comment.

Fix typos.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D103944/new/

https://reviews.llvm.org/D103944

Files:
  llvm/lib/Transforms/Utils/InjectTLIMappings.cpp
  llvm/test/Transforms/Util/add-TLI-mappings-unnamed-addr.ll
  llvm/test/Transforms/Util/add-TLI-mappings.ll


Index: llvm/test/Transforms/Util/add-TLI-mappings.ll
===================================================================
--- llvm/test/Transforms/Util/add-TLI-mappings.ll
+++ llvm/test/Transforms/Util/add-TLI-mappings.ll
@@ -55,6 +55,18 @@
   ret float %call
 }
 
+; SVML: declare <2 x double> @__svml_sin2(<2 x double>) local_unnamed_addr
+; SVML: declare <4 x double> @__svml_sin4(<4 x double>) local_unnamed_addr
+; SVML: declare <8 x double> @__svml_sin8(<8 x double>) local_unnamed_addr
+; SVML: declare <4 x float> @__svml_log10f4(<4 x float>) local_unnamed_addr
+; SVML: declare <8 x float> @__svml_log10f8(<8 x float>) local_unnamed_addr
+; SVML: declare <16 x float> @__svml_log10f16(<16 x float>) local_unnamed_addr
+; MASSV: declare <2 x double> @__sind2_P8(<2 x double>) local_unnamed_addr
+; MASSV: declare <4 x float> @__log10f4_P8(<4 x float>) local_unnamed_addr
+; ACCELERATE: declare <4 x float> @vlog10f(<4 x float>) local_unnamed_addr
+; LIBMVEC-X86: declare <2 x double> @_ZGVbN2v_sin(<2 x double>) local_unnamed_addr
+; LIBMVEC-X86: declare <4 x double> @_ZGVdN4v_sin(<4 x double>) local_unnamed_addr
+
 declare float @llvm.log10.f32(float) #0
 attributes #0 = { nounwind readnone }
 
Index: llvm/test/Transforms/Util/add-TLI-mappings-unnamed-addr.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/Util/add-TLI-mappings-unnamed-addr.ll
@@ -0,0 +1,33 @@
+; Check that InjectTLIMappings adds local_unnamed_addr to newly-added function
+; declarations, and not to existing ones.
+; RUN: opt -vector-library=LIBMVEC-X86 -inject-tli-mappings        -S < %s | FileCheck %s
+; RUN: opt -vector-library=LIBMVEC-X86 -passes=inject-tli-mappings -S < %s | FileCheck %s
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+; CHECK-LABEL: @llvm.compiler.used = appending global
+; CHECK: [1 x i8*] [
+; CHECK:   i8* bitcast (<4 x double> (<4 x double>)* @_ZGVdN4v_sin to i8*)
+; CHECK: ], section "llvm.metadata"
+
+define double @sin_f64(double %in) {
+; CHECK-LABEL: @sin_f64(
+; CHECK:       call double @sin(double %{{.*}}) #[[SIN:[0-9]+]]
+  %call = tail call double @sin(double %in)
+  ret double %call
+}
+
+; CHECK: declare double @sin(double)
+declare double @sin(double) #0
+
+; CHECK: declare <2 x double> @_ZGVbN2v_sin(<2 x double>)
+; CHECK-NOT: local_unnamed_addr
+declare <2 x double> @_ZGVbN2v_sin(<2 x double>)
+; CHECK: declare <4 x double> @_ZGVdN4v_sin(<4 x double>) local_unnamed_addr
+
+attributes #0 = { nounwind readnone }
+
+; CHECK:      attributes #[[SIN]] = { "vector-function-abi-variant"=
+; CHECK-SAME:   "_ZGV_LLVM_N2v_sin(_ZGVbN2v_sin),
+; CHECK-SAME:   _ZGV_LLVM_N4v_sin(_ZGVdN4v_sin)" }
Index: llvm/lib/Transforms/Utils/InjectTLIMappings.cpp
===================================================================
--- llvm/lib/Transforms/Utils/InjectTLIMappings.cpp
+++ llvm/lib/Transforms/Utils/InjectTLIMappings.cpp
@@ -59,6 +59,14 @@
   LLVM_DEBUG(dbgs() << DEBUG_TYPE << ": Added to the module: `" << VFName
                     << "` of type " << *(VectorF->getType()) << "\n");
 
+  // Since we are adding a declaration we know the source code doesn't use the
+  // function directly and it's address can't be significant. Make sure the
+  // declaration is marked local_unnamed_addr, otherwise the compiler may emit
+  // unnecessary symbols for unused functions in some cases like LTO with
+  // .addrsig section enabled.
+  if (VectorF->getUnnamedAddr() == GlobalValue::UnnamedAddr::None)
+    VectorF->setUnnamedAddr(GlobalValue::UnnamedAddr::Local);
+
   // Make function declaration (without a body) "sticky" in the IR by
   // listing it in the @llvm.compiler.used intrinsic.
   assert(!VectorF->size() && "VFABI attribute requires `@llvm.compiler.used` "


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D103944.351088.patch
Type: text/x-patch
Size: 3825 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210610/368f7397/attachment-0001.bin>


More information about the llvm-commits mailing list