[llvm] InjectTLIMappings: remove incompatible attributes from vector declarations. (PR #173206)

via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 23 17:27:21 PST 2025


https://github.com/Ruhung updated https://github.com/llvm/llvm-project/pull/173206

>From 0df5b871b894f74fc78b2d14b9f031cc9a99312e Mon Sep 17 00:00:00 2001
From: Juhung Li <jhlee755 at andestech.com>
Date: Fri, 19 Dec 2025 15:55:12 +0800
Subject: [PATCH] InjectTLIMappings: remove incompatible attributes from vector
 declarations.

---
 .../Transforms/Utils/InjectTLIMappings.cpp    | 12 ++++++++++
 llvm/test/Transforms/Util/add-TLI-mappings.ll | 23 +++++++++++++++----
 2 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/llvm/lib/Transforms/Utils/InjectTLIMappings.cpp b/llvm/lib/Transforms/Utils/InjectTLIMappings.cpp
index ca2a02bfd031a..0a78551a8e2cf 100644
--- a/llvm/lib/Transforms/Utils/InjectTLIMappings.cpp
+++ b/llvm/lib/Transforms/Utils/InjectTLIMappings.cpp
@@ -17,6 +17,8 @@
 #include "llvm/Analysis/GlobalsModRef.h"
 #include "llvm/Analysis/TargetLibraryInfo.h"
 #include "llvm/Analysis/VectorUtils.h"
+#include "llvm/IR/AttributeMask.h"
+#include "llvm/IR/Attributes.h"
 #include "llvm/IR/InstIterator.h"
 #include "llvm/IR/VFABIDemangler.h"
 #include "llvm/Transforms/Utils/ModuleUtils.h"
@@ -55,6 +57,16 @@ static void addVariantDeclaration(CallInst &CI, const ElementCount &VF,
   Function *VecFunc =
       Function::Create(VectorFTy, Function::ExternalLinkage, VFName, M);
   VecFunc->copyAttributesFrom(CI.getCalledFunction());
+
+  // When mapping scalar functions to vector functions, some attributes
+  // (e.g. signext) are not valid on vector types. Remove attributes that are
+  // incompatible with the vectorized return type and arguments.
+  VecFunc->removeRetAttrs(AttributeFuncs::typeIncompatible(
+      VecFunc->getReturnType(), VecFunc->getAttributes().getRetAttrs()));
+  for (auto &Arg : VecFunc->args())
+    Arg.removeAttrs(
+        AttributeFuncs::typeIncompatible(Arg.getType(), Arg.getAttributes()));
+
   if (auto CC = VD->getCallingConv())
     VecFunc->setCallingConv(*CC);
   ++NumVFDeclAdded;
diff --git a/llvm/test/Transforms/Util/add-TLI-mappings.ll b/llvm/test/Transforms/Util/add-TLI-mappings.ll
index 5459512239b64..ce0275ecc07a4 100644
--- a/llvm/test/Transforms/Util/add-TLI-mappings.ll
+++ b/llvm/test/Transforms/Util/add-TLI-mappings.ll
@@ -42,7 +42,7 @@
 ; LIBMVEC-X86-SAME: [2 x ptr] [
 ; LIBMVEC-X86-SAME:   ptr @_ZGVbN2v_sin,
 ; LIBMVEC-X86-SAME:   ptr @_ZGVdN4v_sin
-; SLEEFGNUABI-SAME: [16 x ptr] [
+; SLEEFGNUABI-SAME: [18 x ptr] [
 ; SLEEFGNUABI-SAME:   ptr @_ZGVnN2vl8_modf,
 ; SLEEFGNUABI-SAME:   ptr @_ZGVsNxvl8_modf,
 ; SLEEFGNUABI-SAME:   ptr @_ZGVnN4vl4_modff,
@@ -58,8 +58,10 @@
 ; SLEEFGNUABI-SAME:   ptr @_ZGVnN4vl4l4_sincospif,
 ; SLEEFGNUABI-SAME:   ptr @_ZGVsNxvl4l4_sincospif,
 ; SLEEFGNUABI_SAME;   ptr @_ZGVnN4v_log10f,
-; SLEEFGNUABI-SAME:   ptr @_ZGVsMxv_log10f
-; ARMPL-SAME:       [16 x ptr] [
+; SLEEFGNUABI-SAME:   ptr @_ZGVsMxv_log10f,
+; SLEEFGNUABI-SAME:   ptr @_ZGVnN2vv_ldexp,
+; SLEEFGNUABI-SAME:   ptr @_ZGVsMxvv_ldexp
+; ARMPL-SAME:       [18 x ptr] [
 ; ARMPL-SAME:         ptr @armpl_vmodfq_f64,
 ; ARMPL-SAME:         ptr @armpl_svmodf_f64_x,
 ; ARMPL-SAME:         ptr @armpl_vmodfq_f32,
@@ -75,7 +77,9 @@
 ; ARMPL-SAME:         ptr @armpl_vsincospiq_f32,
 ; ARMPL-SAME:         ptr @armpl_svsincospi_f32_x,
 ; ARMPL-SAME:         ptr @armpl_vlog10q_f32,
-; ARMPL-SAME:         ptr @armpl_svlog10_f32_x
+; ARMPL-SAME:         ptr @armpl_svlog10_f32_x,
+; ARMPL-SAME:         ptr @armpl_vldexpq_f64,
+; ARMPL-SAME:         ptr @armpl_svldexp_f64_x
 ; COMMON-SAME:      ], section "llvm.metadata"
 
 define double @modf_f64(double %in, ptr %iptr) {
@@ -181,6 +185,16 @@ define float @call_llvm.log10.f32(float %in) {
 
 declare float @llvm.log10.f32(float) #0
 
+define double @ldexp_f64_signext(double %x, i32 signext %exp) {
+; COMMON-LABEL: @ldexp_f64_signext(
+; SLEEFGNUABI:  call double @ldexp(double %{{.*}}, i32 signext %{{.*}}) #[[LDEXP:[0-9]+]]
+; ARMPL:        call double @ldexp(double %{{.*}}, i32 signext %{{.*}}) #[[LDEXP:[0-9]+]]
+  %call = tail call double @ldexp(double %x, i32 signext %exp)
+  ret double %call
+}
+
+declare double @ldexp(double, i32 signext) #0
+
 ; SVML: declare <2 x double> @__svml_sin2(<2 x double>)
 ; SVML: declare <4 x double> @__svml_sin4(<4 x double>)
 ; SVML: declare <8 x double> @__svml_sin8(<8 x double>)
@@ -233,6 +247,7 @@ declare float @llvm.log10.f32(float) #0
 
 ; SLEEFGNUABI_RISCV: declare <vscale x 2 x double> @Sleef_sindx_u10rvvm2(<vscale x 2 x double>)
 ; SLEEFGNUABI_RISCV: declare <vscale x 4 x float> @Sleef_log10fx_u10rvvm2(<vscale x 4 x float>)
+; SLEEFGNUABI_RISCV: declare <vscale x 2 x double> @Sleef_ldexpdx_rvvm2(<vscale x 2 x double>, <vscale x 2 x i32>)
 
 ; ARMPL: declare aarch64_vector_pcs <2 x double> @armpl_vmodfq_f64(<2 x double>, ptr)
 ; ARMPL: declare <vscale x 2 x double> @armpl_svmodf_f64_x(<vscale x 2 x double>, ptr, <vscale x 2 x i1>)



More information about the llvm-commits mailing list