[clang] Revert "[FMV] Emit the resolver along with the default version definition." (PR #85914)

2024-03-20 Thread Paschalis Mpeis via cfe-commits

https://github.com/paschalis-mpeis approved this pull request.

Approving 'revert commit'.

https://github.com/llvm/llvm-project/pull/85914
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [LV][LAA] Vectorize math lib calls with mem write-only attribute (PR #78432)

2024-02-27 Thread Paschalis Mpeis via cfe-commits

https://github.com/paschalis-mpeis updated 
https://github.com/llvm/llvm-project/pull/78432

>From a74ba110994e4535cd6c9206aa02d50503fb5577 Mon Sep 17 00:00:00 2001
From: Paschalis Mpeis 
Date: Tue, 27 Feb 2024 15:00:28 +
Subject: [PATCH 1/7] [AArch64][TLI] Add TLI mappings for ArmPL modf, sincos,
 sincospi

---
 llvm/include/llvm/Analysis/VecFuncs.def   |  6 ++
 .../AArch64/veclib-function-calls.ll  | 66 ++-
 llvm/test/Transforms/Util/add-TLI-mappings.ll | 32 +++--
 3 files changed, 67 insertions(+), 37 deletions(-)

diff --git a/llvm/include/llvm/Analysis/VecFuncs.def 
b/llvm/include/llvm/Analysis/VecFuncs.def
index 394e4a05fbc0cf..10f1333cf8885c 100644
--- a/llvm/include/llvm/Analysis/VecFuncs.def
+++ b/llvm/include/llvm/Analysis/VecFuncs.def
@@ -1005,6 +1005,8 @@ TLI_DEFINE_VECFUNC("llvm.log2.f32", "armpl_svlog2_f32_x", 
SCALABLE(4), MASKED, "
 
 TLI_DEFINE_VECFUNC("modf", "armpl_vmodfq_f64", FIXED(2), NOMASK, 
"_ZGV_LLVM_N2vl8")
 TLI_DEFINE_VECFUNC("modff", "armpl_vmodfq_f32", FIXED(4), NOMASK, 
"_ZGV_LLVM_N4vl4")
+TLI_DEFINE_VECFUNC("modf", "armpl_svmodf_f64_x", SCALABLE(2), MASKED, 
"_ZGVsMxvl8")
+TLI_DEFINE_VECFUNC("modff", "armpl_svmodf_f32_x", SCALABLE(4), MASKED, 
"_ZGVsMxvl4")
 
 TLI_DEFINE_VECFUNC("nextafter", "armpl_vnextafterq_f64", FIXED(2), NOMASK, 
"_ZGV_LLVM_N2vv")
 TLI_DEFINE_VECFUNC("nextafterf", "armpl_vnextafterq_f32", FIXED(4), NOMASK, 
"_ZGV_LLVM_N4vv")
@@ -1033,9 +1035,13 @@ TLI_DEFINE_VECFUNC("llvm.sin.f32", "armpl_svsin_f32_x", 
SCALABLE(4), MASKED, "_Z
 
 TLI_DEFINE_VECFUNC("sincos", "armpl_vsincosq_f64", FIXED(2), NOMASK, 
"_ZGV_LLVM_N2vl8l8")
 TLI_DEFINE_VECFUNC("sincosf", "armpl_vsincosq_f32", FIXED(4), NOMASK, 
"_ZGV_LLVM_N4vl4l4")
+TLI_DEFINE_VECFUNC("sincos", "armpl_svsincos_f64_x", SCALABLE(2), MASKED, 
"_ZGVsMxvl8l8")
+TLI_DEFINE_VECFUNC("sincosf", "armpl_svsincos_f32_x", SCALABLE(4), MASKED, 
"_ZGVsMxvl4l4")
 
 TLI_DEFINE_VECFUNC("sincospi", "armpl_vsincospiq_f64", FIXED(2), NOMASK, 
"_ZGV_LLVM_N2vl8l8")
 TLI_DEFINE_VECFUNC("sincospif", "armpl_vsincospiq_f32", FIXED(4), NOMASK, 
"_ZGV_LLVM_N4vl4l4")
+TLI_DEFINE_VECFUNC("sincospi", "armpl_svsincospi_f64_x", SCALABLE(2), MASKED, 
"_ZGVsMxvl8l8")
+TLI_DEFINE_VECFUNC("sincospif", "armpl_svsincospi_f32_x", SCALABLE(4), MASKED, 
"_ZGVsMxvl4l4")
 
 TLI_DEFINE_VECFUNC("sinh", "armpl_vsinhq_f64", FIXED(2), NOMASK, 
"_ZGV_LLVM_N2v")
 TLI_DEFINE_VECFUNC("sinhf", "armpl_vsinhq_f32", FIXED(4), NOMASK, 
"_ZGV_LLVM_N4v")
diff --git 
a/llvm/test/Transforms/LoopVectorize/AArch64/veclib-function-calls.ll 
b/llvm/test/Transforms/LoopVectorize/AArch64/veclib-function-calls.ll
index dd1495626eb984..d9cc630482fc80 100644
--- a/llvm/test/Transforms/LoopVectorize/AArch64/veclib-function-calls.ll
+++ b/llvm/test/Transforms/LoopVectorize/AArch64/veclib-function-calls.ll
@@ -2925,11 +2925,12 @@ define void @modf_f64(ptr noalias %a, ptr noalias %b, 
ptr noalias %c) {
 ;
 ; ARMPL-SVE-LABEL: define void @modf_f64
 ; ARMPL-SVE-SAME: (ptr noalias [[A:%.*]], ptr noalias [[B:%.*]], ptr noalias 
[[C:%.*]]) #[[ATTR0]] {
-; ARMPL-SVE:[[DATA:%.*]] = call double @modf(double [[NUM:%.*]], ptr 
[[GEPB:%.*]]) #[[ATTR4:[0-9]+]]
+; ARMPL-SVE:[[TMP23:%.*]] = call  
@armpl_svmodf_f64_x( [[WIDE_MASKED_LOAD:%.*]], ptr 
[[TMP22:%.*]],  [[ACTIVE_LANE_MASK:%.*]])
 ;
 ; ARMPL-SVE-NOPRED-LABEL: define void @modf_f64
 ; ARMPL-SVE-NOPRED-SAME: (ptr noalias [[A:%.*]], ptr noalias [[B:%.*]], ptr 
noalias [[C:%.*]]) #[[ATTR0]] {
-; ARMPL-SVE-NOPRED:[[TMP5:%.*]] = call <2 x double> @armpl_vmodfq_f64(<2 x 
double> [[WIDE_LOAD:%.*]], ptr [[TMP4:%.*]])
+; ARMPL-SVE-NOPRED:[[TMP17:%.*]] = call  
@armpl_svmodf_f64_x( [[WIDE_LOAD:%.*]], ptr [[TMP16:%.*]], 
 shufflevector ( insertelement ( poison, i1 true, i64 0),  poison,  
zeroinitializer))
+; ARMPL-SVE-NOPRED:[[DATA:%.*]] = call double @modf(double [[NUM:%.*]], 
ptr [[GEPB:%.*]]) #[[ATTR64:[0-9]+]]
 ;
 entry:
   br label %for.body
@@ -2970,11 +2971,12 @@ define void @modf_f32(ptr noalias %a, ptr noalias %b, 
ptr noalias %c) {
 ;
 ; ARMPL-SVE-LABEL: define void @modf_f32
 ; ARMPL-SVE-SAME: (ptr noalias [[A:%.*]], ptr noalias [[B:%.*]], ptr noalias 
[[C:%.*]]) #[[ATTR0]] {
-; ARMPL-SVE:[[DATA:%.*]] = call float @modff(float [[NUM:%.*]], ptr 
[[GEPB:%.*]]) #[[ATTR5:[0-9]+]]
+; ARMPL-SVE:[[TMP23:%.*]] = call  
@armpl_svmodf_f32_x( [[WIDE_MASKED_LOAD:%.*]], ptr 
[[TMP22:%.*]],  [[ACTIVE_LANE_MASK:%.*]])
 ;
 ; ARMPL-SVE-NOPRED-LABEL: define void @modf_f32
 ; ARMPL-SVE-NOPRED-SAME: (ptr noalias [[A:%.*]], ptr noalias [[B:%.*]], ptr 
noalias [[C:%.*]]) #[[ATTR0]] {
-; ARMPL-SVE-NOPRED:[[TMP5:%.*]] = call <4 x float> @armpl_vmodfq_f32(<4 x 
float> [[WIDE_LOAD:%.*]], ptr [[TMP4:%.*]])
+; ARMPL-SVE-NOPRED:[[TMP17:%.*]] = call  
@armpl_svmodf_f32_x( [[WIDE_LOAD:%.*]], ptr [[TMP16:%.*]], 
 shufflevector ( insertelement ( poison, i1 true, i64 0),  poison,  
zeroinitializer))
+; ARMPL-SVE-NOPRED:[[DATA:%.*]] = call float @modff(float [[NUM:%.*]], ptr 
[[GEPB:%.*]]) #[[A

[clang] [llvm] [LV][LAA] Vectorize math lib calls with mem write-only attribute (PR #78432)

2024-02-06 Thread Paschalis Mpeis via cfe-commits

https://github.com/paschalis-mpeis updated 
https://github.com/llvm/llvm-project/pull/78432

>From fbe30cfa2e9474241be71f334228bb811678d0a2 Mon Sep 17 00:00:00 2001
From: Paschalis Mpeis 
Date: Tue, 16 Jan 2024 10:53:09 +
Subject: [PATCH 1/5] LAA cannot vectorize lib calls like modf/modff

Functions like modf/modff are math lib calls that set memory write-only
attribute. Given that a target has vectorized mappings, LAA should allow
vectorization.
---
 ...arch64-veclib-function-calls-linear-ptrs.c | 57 +++
 1 file changed, 57 insertions(+)
 create mode 100644 
clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c

diff --git a/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c 
b/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c
new file mode 100644
index 0..a449fac147058
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c
@@ -0,0 +1,57 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --filter "call.*(frexp|modf)" --version 4
+// RUN: %clang --target=aarch64-linux-gnu -march=armv8-a+sve -O3 -mllvm 
-vector-library=ArmPL -mllvm -force-vector-interleave=1 -mllvm 
-prefer-predicate-over-epilogue=predicate-dont-vectorize -emit-llvm -S -o - %s 
| FileCheck %s
+
+// REQUIRES: aarch64-registered-target
+
+/*
+Testing vectorization of math functions that have the attribute write-only to
+memory set. Given they have vectorized counterparts, they should be able to
+vectorize.
+*/
+
+// The following define is required to access some math functions.
+#define _GNU_SOURCE
+#include 
+
+// frexp/frexpf have no TLI mappings yet.
+
+// CHECK-LABEL: define dso_local void @frexp_f64(
+// CHECK-SAME: ptr nocapture noundef readonly [[IN:%.*]], ptr nocapture 
noundef writeonly [[OUT1:%.*]], ptr nocapture noundef writeonly [[OUT2:%.*]], 
i32 noundef [[N:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK:[[CALL:%.*]] = tail call double @frexp(double noundef 
[[TMP0:%.*]], ptr noundef [[ADD_PTR:%.*]]) #[[ATTR2:[0-9]+]]
+//
+void frexp_f64(double *in, double *out1, int *out2, int N) {
+  for (int i = 0; i < N; ++i)
+*out1 = frexp(in[i], out2+i);
+}
+
+// CHECK-LABEL: define dso_local void @frexp_f32(
+// CHECK-SAME: ptr nocapture noundef readonly [[IN:%.*]], ptr nocapture 
noundef writeonly [[OUT1:%.*]], ptr nocapture noundef writeonly [[OUT2:%.*]], 
i32 noundef [[N:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK:[[CALL:%.*]] = tail call float @frexpf(float noundef 
[[TMP0:%.*]], ptr noundef [[ADD_PTR:%.*]]) #[[ATTR2]]
+//
+void frexp_f32(float *in, float *out1, int *out2, int N) {
+  for (int i = 0; i < N; ++i)
+*out1 = frexpf(in[i], out2+i);
+}
+
+
+// TODO: LAA must allow vectorization.
+
+// CHECK-LABEL: define dso_local void @modf_f64(
+// CHECK-SAME: ptr nocapture noundef readonly [[IN:%.*]], ptr nocapture 
noundef writeonly [[OUT1:%.*]], ptr nocapture noundef writeonly [[OUT2:%.*]], 
i32 noundef [[N:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK:[[CALL:%.*]] = tail call double @modf(double noundef 
[[TMP0:%.*]], ptr noundef [[ADD_PTR:%.*]]) #[[ATTR3:[0-9]+]]
+//
+void modf_f64(double *in, double *out1, double *out2, int N) {
+  for (int i = 0; i < N; ++i)
+  out1[i] = modf(in[i], out2+i);
+}
+
+// TODO: LAA must allow vectorization.
+
+// CHECK-LABEL: define dso_local void @modf_f32(
+// CHECK-SAME: ptr nocapture noundef readonly [[IN:%.*]], ptr nocapture 
noundef writeonly [[OUT1:%.*]], ptr nocapture noundef writeonly [[OUT2:%.*]], 
i32 noundef [[N:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK:[[CALL:%.*]] = tail call float @modff(float noundef [[TMP0:%.*]], 
ptr noundef [[ADD_PTR:%.*]]) #[[ATTR4:[0-9]+]]
+//
+void modf_f32(float *in, float *out1, float *out2, int N) {
+  for (int i = 0; i < N; ++i)
+  out1[i] = modff(in[i], out2+i);
+}

>From 80a86c8a75877cc1e00e2d72bc4ed424728ec6fc Mon Sep 17 00:00:00 2001
From: Paschalis Mpeis 
Date: Wed, 17 Jan 2024 09:44:45 +
Subject: [PATCH 2/5] [LV][LAA] Vectorize math lib calls with mem write-only
 attribute

Teach LAA to consider safe specific math lib calls which are known to
have set the memory write-only attribute. Those attributes are set to
calls by inferNonMandatoryLibFuncAttrs, in BuildLibCalls.cpp, and the
current ones are modf/modff and frexp/frexpf.

This happens only when the calls are found through TLI to have
vectorized counterparts.
---
 ...arch64-veclib-function-calls-linear-ptrs.c | 15 ++-
 llvm/lib/Analysis/LoopAccessAnalysis.cpp  | 19 +++
 2 files changed, 25 insertions(+), 9 deletions(-)

diff --git a/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c 
b/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c
index a449fac147058..957b3f5cb235d 100644
--- a/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c
+++ b/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c
@@ -17,7 +17,7 @@ vectorize.
 
 // CHECK-L

[llvm] [clang] [LV][LAA] Vectorize math lib calls with mem write-only attribute (PR #78432)

2024-01-24 Thread Paschalis Mpeis via cfe-commits

https://github.com/paschalis-mpeis ready_for_review 
https://github.com/llvm/llvm-project/pull/78432
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [LTO] Fix Veclib flags correctly pass to LTO flags (PR #78749)

2024-01-25 Thread Paschalis Mpeis via cfe-commits

https://github.com/paschalis-mpeis closed 
https://github.com/llvm/llvm-project/pull/78749
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] LV][LAA] Vectorize math lib calls with mem write-only attribute (PR #78432)

2024-01-17 Thread Paschalis Mpeis via cfe-commits

https://github.com/paschalis-mpeis created 
https://github.com/llvm/llvm-project/pull/78432

Teach LAA to consider safe specific math lib calls which are known to
 have set the memory write-only attribute. Those attributes are set to
 calls by `inferNonMandatoryLibFuncAttrs`, in BuildLibCalls.cpp, and the
 current ones are `modf`/`modff` and `frexp`/`frexpf`.

 This happens only when the calls are found through TLI to have
 vectorized counterparts.

>From ff9557fe913fd7901cd5a18757a2a41bffbe5c0e Mon Sep 17 00:00:00 2001
From: Paschalis Mpeis 
Date: Tue, 16 Jan 2024 10:53:09 +
Subject: [PATCH 1/2] LAA cannot vectorize lib calls like modf/modff

Functions like modf/modff are math lib calls that set memory write-only
attribute. Given that a target has vectorized mappings, LAA should allow
vectorization.
---
 ...arch64-veclib-function-calls-linear-ptrs.c | 57 +++
 1 file changed, 57 insertions(+)
 create mode 100644 
clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c

diff --git a/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c 
b/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c
new file mode 100644
index 00..a449fac147058a
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c
@@ -0,0 +1,57 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --filter "call.*(frexp|modf)" --version 4
+// RUN: %clang --target=aarch64-linux-gnu -march=armv8-a+sve -O3 -mllvm 
-vector-library=ArmPL -mllvm -force-vector-interleave=1 -mllvm 
-prefer-predicate-over-epilogue=predicate-dont-vectorize -emit-llvm -S -o - %s 
| FileCheck %s
+
+// REQUIRES: aarch64-registered-target
+
+/*
+Testing vectorization of math functions that have the attribute write-only to
+memory set. Given they have vectorized counterparts, they should be able to
+vectorize.
+*/
+
+// The following define is required to access some math functions.
+#define _GNU_SOURCE
+#include 
+
+// frexp/frexpf have no TLI mappings yet.
+
+// CHECK-LABEL: define dso_local void @frexp_f64(
+// CHECK-SAME: ptr nocapture noundef readonly [[IN:%.*]], ptr nocapture 
noundef writeonly [[OUT1:%.*]], ptr nocapture noundef writeonly [[OUT2:%.*]], 
i32 noundef [[N:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK:[[CALL:%.*]] = tail call double @frexp(double noundef 
[[TMP0:%.*]], ptr noundef [[ADD_PTR:%.*]]) #[[ATTR2:[0-9]+]]
+//
+void frexp_f64(double *in, double *out1, int *out2, int N) {
+  for (int i = 0; i < N; ++i)
+*out1 = frexp(in[i], out2+i);
+}
+
+// CHECK-LABEL: define dso_local void @frexp_f32(
+// CHECK-SAME: ptr nocapture noundef readonly [[IN:%.*]], ptr nocapture 
noundef writeonly [[OUT1:%.*]], ptr nocapture noundef writeonly [[OUT2:%.*]], 
i32 noundef [[N:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK:[[CALL:%.*]] = tail call float @frexpf(float noundef 
[[TMP0:%.*]], ptr noundef [[ADD_PTR:%.*]]) #[[ATTR2]]
+//
+void frexp_f32(float *in, float *out1, int *out2, int N) {
+  for (int i = 0; i < N; ++i)
+*out1 = frexpf(in[i], out2+i);
+}
+
+
+// TODO: LAA must allow vectorization.
+
+// CHECK-LABEL: define dso_local void @modf_f64(
+// CHECK-SAME: ptr nocapture noundef readonly [[IN:%.*]], ptr nocapture 
noundef writeonly [[OUT1:%.*]], ptr nocapture noundef writeonly [[OUT2:%.*]], 
i32 noundef [[N:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK:[[CALL:%.*]] = tail call double @modf(double noundef 
[[TMP0:%.*]], ptr noundef [[ADD_PTR:%.*]]) #[[ATTR3:[0-9]+]]
+//
+void modf_f64(double *in, double *out1, double *out2, int N) {
+  for (int i = 0; i < N; ++i)
+  out1[i] = modf(in[i], out2+i);
+}
+
+// TODO: LAA must allow vectorization.
+
+// CHECK-LABEL: define dso_local void @modf_f32(
+// CHECK-SAME: ptr nocapture noundef readonly [[IN:%.*]], ptr nocapture 
noundef writeonly [[OUT1:%.*]], ptr nocapture noundef writeonly [[OUT2:%.*]], 
i32 noundef [[N:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK:[[CALL:%.*]] = tail call float @modff(float noundef [[TMP0:%.*]], 
ptr noundef [[ADD_PTR:%.*]]) #[[ATTR4:[0-9]+]]
+//
+void modf_f32(float *in, float *out1, float *out2, int N) {
+  for (int i = 0; i < N; ++i)
+  out1[i] = modff(in[i], out2+i);
+}

>From 2a3b1e60c3f68c2f823a42bcd6e67111a0b8a529 Mon Sep 17 00:00:00 2001
From: Paschalis Mpeis 
Date: Wed, 17 Jan 2024 09:44:45 +
Subject: [PATCH 2/2] [LV][LAA] Vectorize math lib calls with mem write-only
 attribute

Teach LAA to consider safe specific math lib calls which are known to
have set the memory write-only attribute. Those attributes are set to
calls by inferNonMandatoryLibFuncAttrs, in BuildLibCalls.cpp, and the
current ones are modf/modff and frexp/frexpf.

This happens only when the calls are found through TLI to have
vectorized counterparts.
---
 ...arch64-veclib-function-calls-linear-ptrs.c | 15 ++-
 llvm/lib/Analysis/LoopAccessAnalysis.cpp  | 19 +++
 2 files changed, 25 insertions(+), 9 deletions(-

[llvm] [clang] [LV][LAA] Vectorize math lib calls with mem write-only attribute (PR #78432)

2024-01-18 Thread Paschalis Mpeis via cfe-commits

https://github.com/paschalis-mpeis updated 
https://github.com/llvm/llvm-project/pull/78432

>From ff9557fe913fd7901cd5a18757a2a41bffbe5c0e Mon Sep 17 00:00:00 2001
From: Paschalis Mpeis 
Date: Tue, 16 Jan 2024 10:53:09 +
Subject: [PATCH 1/3] LAA cannot vectorize lib calls like modf/modff

Functions like modf/modff are math lib calls that set memory write-only
attribute. Given that a target has vectorized mappings, LAA should allow
vectorization.
---
 ...arch64-veclib-function-calls-linear-ptrs.c | 57 +++
 1 file changed, 57 insertions(+)
 create mode 100644 
clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c

diff --git a/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c 
b/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c
new file mode 100644
index 00..a449fac147058a
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c
@@ -0,0 +1,57 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --filter "call.*(frexp|modf)" --version 4
+// RUN: %clang --target=aarch64-linux-gnu -march=armv8-a+sve -O3 -mllvm 
-vector-library=ArmPL -mllvm -force-vector-interleave=1 -mllvm 
-prefer-predicate-over-epilogue=predicate-dont-vectorize -emit-llvm -S -o - %s 
| FileCheck %s
+
+// REQUIRES: aarch64-registered-target
+
+/*
+Testing vectorization of math functions that have the attribute write-only to
+memory set. Given they have vectorized counterparts, they should be able to
+vectorize.
+*/
+
+// The following define is required to access some math functions.
+#define _GNU_SOURCE
+#include 
+
+// frexp/frexpf have no TLI mappings yet.
+
+// CHECK-LABEL: define dso_local void @frexp_f64(
+// CHECK-SAME: ptr nocapture noundef readonly [[IN:%.*]], ptr nocapture 
noundef writeonly [[OUT1:%.*]], ptr nocapture noundef writeonly [[OUT2:%.*]], 
i32 noundef [[N:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK:[[CALL:%.*]] = tail call double @frexp(double noundef 
[[TMP0:%.*]], ptr noundef [[ADD_PTR:%.*]]) #[[ATTR2:[0-9]+]]
+//
+void frexp_f64(double *in, double *out1, int *out2, int N) {
+  for (int i = 0; i < N; ++i)
+*out1 = frexp(in[i], out2+i);
+}
+
+// CHECK-LABEL: define dso_local void @frexp_f32(
+// CHECK-SAME: ptr nocapture noundef readonly [[IN:%.*]], ptr nocapture 
noundef writeonly [[OUT1:%.*]], ptr nocapture noundef writeonly [[OUT2:%.*]], 
i32 noundef [[N:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK:[[CALL:%.*]] = tail call float @frexpf(float noundef 
[[TMP0:%.*]], ptr noundef [[ADD_PTR:%.*]]) #[[ATTR2]]
+//
+void frexp_f32(float *in, float *out1, int *out2, int N) {
+  for (int i = 0; i < N; ++i)
+*out1 = frexpf(in[i], out2+i);
+}
+
+
+// TODO: LAA must allow vectorization.
+
+// CHECK-LABEL: define dso_local void @modf_f64(
+// CHECK-SAME: ptr nocapture noundef readonly [[IN:%.*]], ptr nocapture 
noundef writeonly [[OUT1:%.*]], ptr nocapture noundef writeonly [[OUT2:%.*]], 
i32 noundef [[N:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK:[[CALL:%.*]] = tail call double @modf(double noundef 
[[TMP0:%.*]], ptr noundef [[ADD_PTR:%.*]]) #[[ATTR3:[0-9]+]]
+//
+void modf_f64(double *in, double *out1, double *out2, int N) {
+  for (int i = 0; i < N; ++i)
+  out1[i] = modf(in[i], out2+i);
+}
+
+// TODO: LAA must allow vectorization.
+
+// CHECK-LABEL: define dso_local void @modf_f32(
+// CHECK-SAME: ptr nocapture noundef readonly [[IN:%.*]], ptr nocapture 
noundef writeonly [[OUT1:%.*]], ptr nocapture noundef writeonly [[OUT2:%.*]], 
i32 noundef [[N:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK:[[CALL:%.*]] = tail call float @modff(float noundef [[TMP0:%.*]], 
ptr noundef [[ADD_PTR:%.*]]) #[[ATTR4:[0-9]+]]
+//
+void modf_f32(float *in, float *out1, float *out2, int N) {
+  for (int i = 0; i < N; ++i)
+  out1[i] = modff(in[i], out2+i);
+}

>From 2a3b1e60c3f68c2f823a42bcd6e67111a0b8a529 Mon Sep 17 00:00:00 2001
From: Paschalis Mpeis 
Date: Wed, 17 Jan 2024 09:44:45 +
Subject: [PATCH 2/3] [LV][LAA] Vectorize math lib calls with mem write-only
 attribute

Teach LAA to consider safe specific math lib calls which are known to
have set the memory write-only attribute. Those attributes are set to
calls by inferNonMandatoryLibFuncAttrs, in BuildLibCalls.cpp, and the
current ones are modf/modff and frexp/frexpf.

This happens only when the calls are found through TLI to have
vectorized counterparts.
---
 ...arch64-veclib-function-calls-linear-ptrs.c | 15 ++-
 llvm/lib/Analysis/LoopAccessAnalysis.cpp  | 19 +++
 2 files changed, 25 insertions(+), 9 deletions(-)

diff --git a/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c 
b/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c
index a449fac147058a..957b3f5cb235d3 100644
--- a/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c
+++ b/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c
@@ -17,7 +17,7 @@ vectorize.
 
 // CHE

[llvm] [clang] [LV][LAA] Vectorize math lib calls with mem write-only attribute (PR #78432)

2024-01-19 Thread Paschalis Mpeis via cfe-commits

https://github.com/paschalis-mpeis updated 
https://github.com/llvm/llvm-project/pull/78432

>From ff9557fe913fd7901cd5a18757a2a41bffbe5c0e Mon Sep 17 00:00:00 2001
From: Paschalis Mpeis 
Date: Tue, 16 Jan 2024 10:53:09 +
Subject: [PATCH 1/4] LAA cannot vectorize lib calls like modf/modff

Functions like modf/modff are math lib calls that set memory write-only
attribute. Given that a target has vectorized mappings, LAA should allow
vectorization.
---
 ...arch64-veclib-function-calls-linear-ptrs.c | 57 +++
 1 file changed, 57 insertions(+)
 create mode 100644 
clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c

diff --git a/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c 
b/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c
new file mode 100644
index 00..a449fac147058a
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c
@@ -0,0 +1,57 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --filter "call.*(frexp|modf)" --version 4
+// RUN: %clang --target=aarch64-linux-gnu -march=armv8-a+sve -O3 -mllvm 
-vector-library=ArmPL -mllvm -force-vector-interleave=1 -mllvm 
-prefer-predicate-over-epilogue=predicate-dont-vectorize -emit-llvm -S -o - %s 
| FileCheck %s
+
+// REQUIRES: aarch64-registered-target
+
+/*
+Testing vectorization of math functions that have the attribute write-only to
+memory set. Given they have vectorized counterparts, they should be able to
+vectorize.
+*/
+
+// The following define is required to access some math functions.
+#define _GNU_SOURCE
+#include 
+
+// frexp/frexpf have no TLI mappings yet.
+
+// CHECK-LABEL: define dso_local void @frexp_f64(
+// CHECK-SAME: ptr nocapture noundef readonly [[IN:%.*]], ptr nocapture 
noundef writeonly [[OUT1:%.*]], ptr nocapture noundef writeonly [[OUT2:%.*]], 
i32 noundef [[N:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK:[[CALL:%.*]] = tail call double @frexp(double noundef 
[[TMP0:%.*]], ptr noundef [[ADD_PTR:%.*]]) #[[ATTR2:[0-9]+]]
+//
+void frexp_f64(double *in, double *out1, int *out2, int N) {
+  for (int i = 0; i < N; ++i)
+*out1 = frexp(in[i], out2+i);
+}
+
+// CHECK-LABEL: define dso_local void @frexp_f32(
+// CHECK-SAME: ptr nocapture noundef readonly [[IN:%.*]], ptr nocapture 
noundef writeonly [[OUT1:%.*]], ptr nocapture noundef writeonly [[OUT2:%.*]], 
i32 noundef [[N:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK:[[CALL:%.*]] = tail call float @frexpf(float noundef 
[[TMP0:%.*]], ptr noundef [[ADD_PTR:%.*]]) #[[ATTR2]]
+//
+void frexp_f32(float *in, float *out1, int *out2, int N) {
+  for (int i = 0; i < N; ++i)
+*out1 = frexpf(in[i], out2+i);
+}
+
+
+// TODO: LAA must allow vectorization.
+
+// CHECK-LABEL: define dso_local void @modf_f64(
+// CHECK-SAME: ptr nocapture noundef readonly [[IN:%.*]], ptr nocapture 
noundef writeonly [[OUT1:%.*]], ptr nocapture noundef writeonly [[OUT2:%.*]], 
i32 noundef [[N:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK:[[CALL:%.*]] = tail call double @modf(double noundef 
[[TMP0:%.*]], ptr noundef [[ADD_PTR:%.*]]) #[[ATTR3:[0-9]+]]
+//
+void modf_f64(double *in, double *out1, double *out2, int N) {
+  for (int i = 0; i < N; ++i)
+  out1[i] = modf(in[i], out2+i);
+}
+
+// TODO: LAA must allow vectorization.
+
+// CHECK-LABEL: define dso_local void @modf_f32(
+// CHECK-SAME: ptr nocapture noundef readonly [[IN:%.*]], ptr nocapture 
noundef writeonly [[OUT1:%.*]], ptr nocapture noundef writeonly [[OUT2:%.*]], 
i32 noundef [[N:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK:[[CALL:%.*]] = tail call float @modff(float noundef [[TMP0:%.*]], 
ptr noundef [[ADD_PTR:%.*]]) #[[ATTR4:[0-9]+]]
+//
+void modf_f32(float *in, float *out1, float *out2, int N) {
+  for (int i = 0; i < N; ++i)
+  out1[i] = modff(in[i], out2+i);
+}

>From 2a3b1e60c3f68c2f823a42bcd6e67111a0b8a529 Mon Sep 17 00:00:00 2001
From: Paschalis Mpeis 
Date: Wed, 17 Jan 2024 09:44:45 +
Subject: [PATCH 2/4] [LV][LAA] Vectorize math lib calls with mem write-only
 attribute

Teach LAA to consider safe specific math lib calls which are known to
have set the memory write-only attribute. Those attributes are set to
calls by inferNonMandatoryLibFuncAttrs, in BuildLibCalls.cpp, and the
current ones are modf/modff and frexp/frexpf.

This happens only when the calls are found through TLI to have
vectorized counterparts.
---
 ...arch64-veclib-function-calls-linear-ptrs.c | 15 ++-
 llvm/lib/Analysis/LoopAccessAnalysis.cpp  | 19 +++
 2 files changed, 25 insertions(+), 9 deletions(-)

diff --git a/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c 
b/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c
index a449fac147058a..957b3f5cb235d3 100644
--- a/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c
+++ b/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c
@@ -17,7 +17,7 @@ vectorize.
 
 // CHE

[clang] [llvm] [LV][LAA] Vectorize math lib calls with mem write-only attribute (PR #78432)

2024-01-19 Thread Paschalis Mpeis via cfe-commits


@@ -2274,6 +2274,26 @@ bool LoopAccessInfo::canAnalyzeLoop() {
   return true;
 }
 
+/// Returns whether \p I is a known math library call that has attribute
+/// 'memory(argmem: write)' set.
+static bool isMathLibCallMemWriteOnly(const TargetLibraryInfo *TLI,
+  const Instruction &I) {
+  auto *Call = dyn_cast(&I);
+  if (!Call)
+return false;
+
+  Function *F = Call->getCalledFunction();
+  if (!F->hasFnAttribute(Attribute::AttrKind::Memory))
+return false;
+
+  auto ME = F->getFnAttribute(Attribute::AttrKind::Memory).getMemoryEffects();

paschalis-mpeis wrote:

Good suggestion thanks, latest commit applies this.

https://github.com/llvm/llvm-project/pull/78432
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [LTO] Fix Veclib flags correctly pass to LTO flags (PR #78749)

2024-01-19 Thread Paschalis Mpeis via cfe-commits

https://github.com/paschalis-mpeis created 
https://github.com/llvm/llvm-project/pull/78749

Flags `-fveclib=name` were not passed to LTO flags.
This pass fixes that by converting the `-fveclib` flags to their relevant names 
for opt's `-vector-lib=name` flags.

For example:
`-fveclib=SLEEF` would become `-vector-library=sleefgnuabi` and passed through 
the `-plugin-opt` flag.

>From e1f97413fc7cf42a4b47b27b6ec6d377ea8113b1 Mon Sep 17 00:00:00 2001
From: Paschalis Mpeis 
Date: Fri, 19 Jan 2024 16:27:20 +
Subject: [PATCH] [LTO] Fix Veclib flags correctly pass to LTO flags

Flags `-fveclib=name` were not passed to LTO flags.
This pass fixes that by converting the `-fveclib` flags to their
relevant names for opt's `-vector-lib=name` flags.

For example:
`-fveclib=SLEEF` would become `-vector-library=sleefgnuabi` and passed
through the -plugin-opt` flag.
---
 clang/lib/Driver/ToolChains/CommonArgs.cpp | 22 +
 clang/test/Driver/fveclib.c| 28 ++
 2 files changed, 50 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 385f66f3782bc1..470145849e4187 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -783,6 +783,28 @@ void tools::addLTOOptions(const ToolChain &ToolChain, 
const ArgList &Args,
  "-generate-arange-section"));
   }
 
+  // Pass vector library arguments to LTO.
+  Arg *ArgVecLib = Args.getLastArg(options::OPT_fveclib);
+  if (ArgVecLib && ArgVecLib->getNumValues() == 1) {
+// Map the vector library names from clang front-end to opt front-end. The
+// values are taken from the TargetLibraryInfo class command line options.
+std::optional OptVal =
+llvm::StringSwitch>(ArgVecLib->getValue())
+.Case("Accelerate", "Accelerate")
+.Case("LIBMVEC", "LIBMVEC-X86")
+.Case("MASSV", "MASSV")
+.Case("SVML", "SVML")
+.Case("SLEEF", "sleefgnuabi")
+.Case("Darwin_libsystem_m", "Darwin_libsystem_m")
+.Case("ArmPL", "ArmPL")
+.Case("none", "none")
+.Default(std::nullopt);
+
+if (OptVal)
+  CmdArgs.push_back(Args.MakeArgString(
+  Twine(PluginOptPrefix) + "-vector-library=" + OptVal.value()));
+  }
+
   // Try to pass driver level flags relevant to LTO code generation down to
   // the plugin.
 
diff --git a/clang/test/Driver/fveclib.c b/clang/test/Driver/fveclib.c
index e2a7619e9b89f7..8ce7bcbb67ae0b 100644
--- a/clang/test/Driver/fveclib.c
+++ b/clang/test/Driver/fveclib.c
@@ -31,3 +31,31 @@
 
 // RUN: %clang -fveclib=Accelerate %s -nodefaultlibs -target 
arm64-apple-ios8.0.0 -### 2>&1 | FileCheck 
--check-prefix=CHECK-LINK-NODEFAULTLIBS %s
 // CHECK-LINK-NODEFAULTLIBS-NOT: "-framework" "Accelerate"
+
+
+/* Verify that the correct vector library is passed to LTO flags. */
+
+
+// RUN: %clang -### -fveclib=none -flto %s -v 2>&1  | FileCheck -check-prefix 
CHECK-LTO-NOLIB %s
+// CHECK-LTO-NOLIB: "-plugin-opt=-vector-library=none"
+
+// RUN: %clang -### -fveclib=Accelerate -flto %s -v 2>&1  | FileCheck 
-check-prefix CHECK-LTO-ACCELERATE %s
+// CHECK-LTO-ACCELERATE: "-plugin-opt=-vector-library=Accelerate"
+
+// RUN: %clang -### -fveclib=LIBMVEC -flto %s -v 2>&1  | FileCheck 
-check-prefix CHECK-LTO-LIBMVEC %s
+// CHECK-LTO-LIBMVEC: "-plugin-opt=-vector-library=LIBMVEC-X86"
+
+// RUN: %clang -### -fveclib=MASSV -flto %s -v 2>&1  | FileCheck -check-prefix 
CHECK-LTO-MASSV %s
+// CHECK-LTO-MASSV: "-plugin-opt=-vector-library=MASSV"
+
+// RUN: not %clang -### -fveclib=SVML -flto %s -v 2>&1  | FileCheck 
-check-prefix CHECK-LTO-SVML %s
+// CHECK-LTO-SVML: "-plugin-opt=-vector-library=SVML"
+
+// RUN: %clang -### -fveclib=SLEEF -flto %s -v 2>&1  | FileCheck -check-prefix 
CHECK-LTO-SLEEF %s
+// CHECK-LTO-SLEEF: "-plugin-opt=-vector-library=sleefgnuabi"
+
+// RUN: %clang -### -fveclib=Darwin_libsystem_m -flto %s -v 2>&1  | FileCheck 
-check-prefix CHECK-LTO-DARWIN %s
+// CHECK-LTO-DARWIN: "-plugin-opt=-vector-library=Darwin_libsystem_m"
+
+// RUN: %clang -### -fveclib=ArmPL -flto %s -v 2>&1  | FileCheck -check-prefix 
CHECK-LTO-ARMPL %s
+// CHECK-LTO-ARMPL: "-plugin-opt=-vector-library=ArmPL"

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [LTO] Fix Veclib flags correctly pass to LTO flags (PR #78749)

2024-01-22 Thread Paschalis Mpeis via cfe-commits


@@ -783,6 +783,28 @@ void tools::addLTOOptions(const ToolChain &ToolChain, 
const ArgList &Args,
  "-generate-arange-section"));
   }
 
+  // Pass vector library arguments to LTO.
+  Arg *ArgVecLib = Args.getLastArg(options::OPT_fveclib);
+  if (ArgVecLib && ArgVecLib->getNumValues() == 1) {
+// Map the vector library names from clang front-end to opt front-end. The
+// values are taken from the TargetLibraryInfo class command line options.
+std::optional OptVal =
+llvm::StringSwitch>(ArgVecLib->getValue())

paschalis-mpeis wrote:

Reusing code for mapping the strings is a great suggestion, however, 
`TargetLibraryInfo` statically creates some `cl::opt` (command line options) 
and I'm not sure ATM what would be a clean way to do this.

I would suggest such change (if is doable in a clean way) to be dealt in a 
separate patch.


https://github.com/llvm/llvm-project/pull/78749
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [LTO] Fix Veclib flags correctly pass to LTO flags (PR #78749)

2024-01-22 Thread Paschalis Mpeis via cfe-commits


@@ -31,3 +31,31 @@
 
 // RUN: %clang -fveclib=Accelerate %s -nodefaultlibs -target 
arm64-apple-ios8.0.0 -### 2>&1 | FileCheck 
--check-prefix=CHECK-LINK-NODEFAULTLIBS %s
 // CHECK-LINK-NODEFAULTLIBS-NOT: "-framework" "Accelerate"
+
+
+/* Verify that the correct vector library is passed to LTO flags. */
+
+
+// RUN: %clang -### -fveclib=none -flto %s -v 2>&1  | FileCheck -check-prefix 
CHECK-LTO-NOLIB %s
+// CHECK-LTO-NOLIB: "-plugin-opt=-vector-library=none"
+
+// RUN: %clang -### -fveclib=Accelerate -flto %s -v 2>&1  | FileCheck 
-check-prefix CHECK-LTO-ACCELERATE %s
+// CHECK-LTO-ACCELERATE: "-plugin-opt=-vector-library=Accelerate"
+
+// RUN: %clang -### -fveclib=LIBMVEC -flto %s -v 2>&1  | FileCheck 
-check-prefix CHECK-LTO-LIBMVEC %s
+// CHECK-LTO-LIBMVEC: "-plugin-opt=-vector-library=LIBMVEC-X86"
+
+// RUN: %clang -### -fveclib=MASSV -flto %s -v 2>&1  | FileCheck -check-prefix 
CHECK-LTO-MASSV %s
+// CHECK-LTO-MASSV: "-plugin-opt=-vector-library=MASSV"
+
+// RUN: not %clang -### -fveclib=SVML -flto %s -v 2>&1  | FileCheck 
-check-prefix CHECK-LTO-SVML %s
+// CHECK-LTO-SVML: "-plugin-opt=-vector-library=SVML"
+
+// RUN: %clang -### -fveclib=SLEEF -flto %s -v 2>&1  | FileCheck -check-prefix 
CHECK-LTO-SLEEF %s
+// CHECK-LTO-SLEEF: "-plugin-opt=-vector-library=sleefgnuabi"
+
+// RUN: %clang -### -fveclib=Darwin_libsystem_m -flto %s -v 2>&1  | FileCheck 
-check-prefix CHECK-LTO-DARWIN %s
+// CHECK-LTO-DARWIN: "-plugin-opt=-vector-library=Darwin_libsystem_m"
+
+// RUN: %clang -### -fveclib=ArmPL -flto %s -v 2>&1  | FileCheck -check-prefix 
CHECK-LTO-ARMPL %s

paschalis-mpeis wrote:

True. This caused some issues when testing on an x86 machine.
Submitting a new patch added target to relevant instructions soon.

Thanks you both.

https://github.com/llvm/llvm-project/pull/78749
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [LTO] Fix Veclib flags correctly pass to LTO flags (PR #78749)

2024-01-22 Thread Paschalis Mpeis via cfe-commits

https://github.com/paschalis-mpeis edited 
https://github.com/llvm/llvm-project/pull/78749
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [LTO] Fix Veclib flags correctly pass to LTO flags (PR #78749)

2024-01-22 Thread Paschalis Mpeis via cfe-commits

https://github.com/paschalis-mpeis edited 
https://github.com/llvm/llvm-project/pull/78749
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [LTO] Fix Veclib flags correctly pass to LTO flags (PR #78749)

2024-01-22 Thread Paschalis Mpeis via cfe-commits

https://github.com/paschalis-mpeis edited 
https://github.com/llvm/llvm-project/pull/78749
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [LTO] Fix Veclib flags correctly pass to LTO flags (PR #78749)

2024-01-22 Thread Paschalis Mpeis via cfe-commits

https://github.com/paschalis-mpeis updated 
https://github.com/llvm/llvm-project/pull/78749

>From c342eea051da7eed2ef4541e5daf445114258e1d Mon Sep 17 00:00:00 2001
From: Paschalis Mpeis 
Date: Fri, 19 Jan 2024 16:27:20 +
Subject: [PATCH] [LTO] Fix Veclib flags correctly pass to LTO flags

Flags `-fveclib=name` were not passed to LTO flags.
This pass fixes that by converting the `-fveclib` flags to their
relevant names for opt's `-vector-lib=name` flags.

For example:
`-fveclib=SLEEF` would become `-vector-library=sleefgnuabi` and passed
through the -plugin-opt` flag.
---
 clang/lib/Driver/ToolChains/CommonArgs.cpp | 22 
 clang/test/Driver/fveclib.c| 24 ++
 2 files changed, 46 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 385f66f3782bc1..470145849e4187 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -783,6 +783,28 @@ void tools::addLTOOptions(const ToolChain &ToolChain, 
const ArgList &Args,
  "-generate-arange-section"));
   }
 
+  // Pass vector library arguments to LTO.
+  Arg *ArgVecLib = Args.getLastArg(options::OPT_fveclib);
+  if (ArgVecLib && ArgVecLib->getNumValues() == 1) {
+// Map the vector library names from clang front-end to opt front-end. The
+// values are taken from the TargetLibraryInfo class command line options.
+std::optional OptVal =
+llvm::StringSwitch>(ArgVecLib->getValue())
+.Case("Accelerate", "Accelerate")
+.Case("LIBMVEC", "LIBMVEC-X86")
+.Case("MASSV", "MASSV")
+.Case("SVML", "SVML")
+.Case("SLEEF", "sleefgnuabi")
+.Case("Darwin_libsystem_m", "Darwin_libsystem_m")
+.Case("ArmPL", "ArmPL")
+.Case("none", "none")
+.Default(std::nullopt);
+
+if (OptVal)
+  CmdArgs.push_back(Args.MakeArgString(
+  Twine(PluginOptPrefix) + "-vector-library=" + OptVal.value()));
+  }
+
   // Try to pass driver level flags relevant to LTO code generation down to
   // the plugin.
 
diff --git a/clang/test/Driver/fveclib.c b/clang/test/Driver/fveclib.c
index e2a7619e9b89f7..ffe6937bd22ccc 100644
--- a/clang/test/Driver/fveclib.c
+++ b/clang/test/Driver/fveclib.c
@@ -31,3 +31,27 @@
 
 // RUN: %clang -fveclib=Accelerate %s -nodefaultlibs -target 
arm64-apple-ios8.0.0 -### 2>&1 | FileCheck 
--check-prefix=CHECK-LINK-NODEFAULTLIBS %s
 // CHECK-LINK-NODEFAULTLIBS-NOT: "-framework" "Accelerate"
+
+
+/* Verify that the correct vector library is passed to LTO flags. */
+
+// RUN: %clang -### -fveclib=Accelerate -flto %s -v 2>&1 | FileCheck 
-check-prefix CHECK-LTO-ACCELERATE %s
+// CHECK-LTO-ACCELERATE: "-plugin-opt=-vector-library=Accelerate"
+
+// RUN: %clang -### --target=x86_64-unknown-linux-gnu  -fveclib=LIBMVEC -flto 
%s -v 2>&1 | FileCheck -check-prefix CHECK-LTO-LIBMVEC %s
+// CHECK-LTO-LIBMVEC: "-plugin-opt=-vector-library=LIBMVEC-X86"
+
+// RUN: %clang -### -fveclib=MASSV -flto %s -v 2>&1 | FileCheck -check-prefix 
CHECK-LTO-MASSV %s
+// CHECK-LTO-MASSV: "-plugin-opt=-vector-library=MASSV"
+
+// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fveclib=SVML -flto %s 
-v 2>&1 | FileCheck -check-prefix CHECK-LTO-SVML %s
+// CHECK-LTO-SVML: "-plugin-opt=-vector-library=SVML"
+
+// RUN: %clang -### --target=aarch64-linux-gnu -fveclib=SLEEF -flto %s -v 2>&1 
| FileCheck -check-prefix CHECK-LTO-SLEEF %s
+// CHECK-LTO-SLEEF: "-plugin-opt=-vector-library=sleefgnuabi"
+
+// RUN: %clang -### -fveclib=Darwin_libsystem_m -flto %s -v 2>&1 | FileCheck 
-check-prefix CHECK-LTO-DARWIN %s
+// CHECK-LTO-DARWIN: "-plugin-opt=-vector-library=Darwin_libsystem_m"
+
+// RUN: %clang -### --target=aarch64-linux-gnu -fveclib=ArmPL -flto %s -v 2>&1 
| FileCheck -check-prefix CHECK-LTO-ARMPL %s
+// CHECK-LTO-ARMPL: "-plugin-opt=-vector-library=ArmPL"

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [LTO] Fix Veclib flags correctly pass to LTO flags (PR #78749)

2024-01-22 Thread Paschalis Mpeis via cfe-commits

https://github.com/paschalis-mpeis updated 
https://github.com/llvm/llvm-project/pull/78749

>From c342eea051da7eed2ef4541e5daf445114258e1d Mon Sep 17 00:00:00 2001
From: Paschalis Mpeis 
Date: Fri, 19 Jan 2024 16:27:20 +
Subject: [PATCH 1/2] [LTO] Fix Veclib flags correctly pass to LTO flags

Flags `-fveclib=name` were not passed to LTO flags.
This pass fixes that by converting the `-fveclib` flags to their
relevant names for opt's `-vector-lib=name` flags.

For example:
`-fveclib=SLEEF` would become `-vector-library=sleefgnuabi` and passed
through the -plugin-opt` flag.
---
 clang/lib/Driver/ToolChains/CommonArgs.cpp | 22 
 clang/test/Driver/fveclib.c| 24 ++
 2 files changed, 46 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 385f66f3782bc1a..470145849e4187f 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -783,6 +783,28 @@ void tools::addLTOOptions(const ToolChain &ToolChain, 
const ArgList &Args,
  "-generate-arange-section"));
   }
 
+  // Pass vector library arguments to LTO.
+  Arg *ArgVecLib = Args.getLastArg(options::OPT_fveclib);
+  if (ArgVecLib && ArgVecLib->getNumValues() == 1) {
+// Map the vector library names from clang front-end to opt front-end. The
+// values are taken from the TargetLibraryInfo class command line options.
+std::optional OptVal =
+llvm::StringSwitch>(ArgVecLib->getValue())
+.Case("Accelerate", "Accelerate")
+.Case("LIBMVEC", "LIBMVEC-X86")
+.Case("MASSV", "MASSV")
+.Case("SVML", "SVML")
+.Case("SLEEF", "sleefgnuabi")
+.Case("Darwin_libsystem_m", "Darwin_libsystem_m")
+.Case("ArmPL", "ArmPL")
+.Case("none", "none")
+.Default(std::nullopt);
+
+if (OptVal)
+  CmdArgs.push_back(Args.MakeArgString(
+  Twine(PluginOptPrefix) + "-vector-library=" + OptVal.value()));
+  }
+
   // Try to pass driver level flags relevant to LTO code generation down to
   // the plugin.
 
diff --git a/clang/test/Driver/fveclib.c b/clang/test/Driver/fveclib.c
index e2a7619e9b89f7f..ffe6937bd22ccc3 100644
--- a/clang/test/Driver/fveclib.c
+++ b/clang/test/Driver/fveclib.c
@@ -31,3 +31,27 @@
 
 // RUN: %clang -fveclib=Accelerate %s -nodefaultlibs -target 
arm64-apple-ios8.0.0 -### 2>&1 | FileCheck 
--check-prefix=CHECK-LINK-NODEFAULTLIBS %s
 // CHECK-LINK-NODEFAULTLIBS-NOT: "-framework" "Accelerate"
+
+
+/* Verify that the correct vector library is passed to LTO flags. */
+
+// RUN: %clang -### -fveclib=Accelerate -flto %s -v 2>&1 | FileCheck 
-check-prefix CHECK-LTO-ACCELERATE %s
+// CHECK-LTO-ACCELERATE: "-plugin-opt=-vector-library=Accelerate"
+
+// RUN: %clang -### --target=x86_64-unknown-linux-gnu  -fveclib=LIBMVEC -flto 
%s -v 2>&1 | FileCheck -check-prefix CHECK-LTO-LIBMVEC %s
+// CHECK-LTO-LIBMVEC: "-plugin-opt=-vector-library=LIBMVEC-X86"
+
+// RUN: %clang -### -fveclib=MASSV -flto %s -v 2>&1 | FileCheck -check-prefix 
CHECK-LTO-MASSV %s
+// CHECK-LTO-MASSV: "-plugin-opt=-vector-library=MASSV"
+
+// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fveclib=SVML -flto %s 
-v 2>&1 | FileCheck -check-prefix CHECK-LTO-SVML %s
+// CHECK-LTO-SVML: "-plugin-opt=-vector-library=SVML"
+
+// RUN: %clang -### --target=aarch64-linux-gnu -fveclib=SLEEF -flto %s -v 2>&1 
| FileCheck -check-prefix CHECK-LTO-SLEEF %s
+// CHECK-LTO-SLEEF: "-plugin-opt=-vector-library=sleefgnuabi"
+
+// RUN: %clang -### -fveclib=Darwin_libsystem_m -flto %s -v 2>&1 | FileCheck 
-check-prefix CHECK-LTO-DARWIN %s
+// CHECK-LTO-DARWIN: "-plugin-opt=-vector-library=Darwin_libsystem_m"
+
+// RUN: %clang -### --target=aarch64-linux-gnu -fveclib=ArmPL -flto %s -v 2>&1 
| FileCheck -check-prefix CHECK-LTO-ARMPL %s
+// CHECK-LTO-ARMPL: "-plugin-opt=-vector-library=ArmPL"

>From f82dadfb125c9c4496db98abbebda3779f014a43 Mon Sep 17 00:00:00 2001
From: Paschalis Mpeis 
Date: Mon, 22 Jan 2024 15:59:23 +
Subject: [PATCH 2/2] Add targets to tests that call addLTOOptions

Tests that do not call addLTOOptions were removed.
---
 clang/test/Driver/fveclib.c | 10 ++
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/clang/test/Driver/fveclib.c b/clang/test/Driver/fveclib.c
index ffe6937bd22ccc3..7b5d189609c9293 100644
--- a/clang/test/Driver/fveclib.c
+++ b/clang/test/Driver/fveclib.c
@@ -35,13 +35,10 @@
 
 /* Verify that the correct vector library is passed to LTO flags. */
 
-// RUN: %clang -### -fveclib=Accelerate -flto %s -v 2>&1 | FileCheck 
-check-prefix CHECK-LTO-ACCELERATE %s
-// CHECK-LTO-ACCELERATE: "-plugin-opt=-vector-library=Accelerate"
-
-// RUN: %clang -### --target=x86_64-unknown-linux-gnu  -fveclib=LIBMVEC -flto 
%s -v 2>&1 | FileCheck -check-prefix CHECK-LTO-LIBMVEC %s
+// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fveclib=L

[clang] [LTO] Fix Veclib flags correctly pass to LTO flags (PR #78749)

2024-01-22 Thread Paschalis Mpeis via cfe-commits


@@ -31,3 +31,27 @@
 
 // RUN: %clang -fveclib=Accelerate %s -nodefaultlibs -target 
arm64-apple-ios8.0.0 -### 2>&1 | FileCheck 
--check-prefix=CHECK-LINK-NODEFAULTLIBS %s
 // CHECK-LINK-NODEFAULTLIBS-NOT: "-framework" "Accelerate"
+
+
+/* Verify that the correct vector library is passed to LTO flags. */
+
+// RUN: %clang -### -fveclib=Accelerate -flto %s -v 2>&1 | FileCheck 
-check-prefix CHECK-LTO-ACCELERATE %s

paschalis-mpeis wrote:

Actually it turns out that some of the veclibs (like Accelerate in this case) 
do not have any target/toolchain that would call `addLTOOptions`. So I removed 
those.

The ones that remain, all specify a target.

https://github.com/llvm/llvm-project/pull/78749
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [LV][LAA] Vectorize math lib calls with mem write-only attribute (PR #78432)

2024-01-22 Thread Paschalis Mpeis via cfe-commits

https://github.com/paschalis-mpeis converted_to_draft 
https://github.com/llvm/llvm-project/pull/78432
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [LTO] Fix Veclib flags correctly pass to LTO flags (PR #78749)

2024-01-23 Thread Paschalis Mpeis via cfe-commits

https://github.com/paschalis-mpeis updated 
https://github.com/llvm/llvm-project/pull/78749

>From f664beed712de47796759586a171d86d73fb9790 Mon Sep 17 00:00:00 2001
From: Paschalis Mpeis 
Date: Fri, 19 Jan 2024 16:27:20 +
Subject: [PATCH 1/3] [LTO] Fix Veclib flags correctly pass to LTO flags

Flags `-fveclib=name` were not passed to LTO flags.
This pass fixes that by converting the `-fveclib` flags to their
relevant names for opt's `-vector-lib=name` flags.

For example:
`-fveclib=SLEEF` would become `-vector-library=sleefgnuabi` and passed
through the -plugin-opt` flag.
---
 clang/lib/Driver/ToolChains/CommonArgs.cpp | 22 
 clang/test/Driver/fveclib.c| 24 ++
 2 files changed, 46 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index fadaf3e60c6616a..9f1dddc47e3e053 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -783,6 +783,28 @@ void tools::addLTOOptions(const ToolChain &ToolChain, 
const ArgList &Args,
  "-generate-arange-section"));
   }
 
+  // Pass vector library arguments to LTO.
+  Arg *ArgVecLib = Args.getLastArg(options::OPT_fveclib);
+  if (ArgVecLib && ArgVecLib->getNumValues() == 1) {
+// Map the vector library names from clang front-end to opt front-end. The
+// values are taken from the TargetLibraryInfo class command line options.
+std::optional OptVal =
+llvm::StringSwitch>(ArgVecLib->getValue())
+.Case("Accelerate", "Accelerate")
+.Case("LIBMVEC", "LIBMVEC-X86")
+.Case("MASSV", "MASSV")
+.Case("SVML", "SVML")
+.Case("SLEEF", "sleefgnuabi")
+.Case("Darwin_libsystem_m", "Darwin_libsystem_m")
+.Case("ArmPL", "ArmPL")
+.Case("none", "none")
+.Default(std::nullopt);
+
+if (OptVal)
+  CmdArgs.push_back(Args.MakeArgString(
+  Twine(PluginOptPrefix) + "-vector-library=" + OptVal.value()));
+  }
+
   // Try to pass driver level flags relevant to LTO code generation down to
   // the plugin.
 
diff --git a/clang/test/Driver/fveclib.c b/clang/test/Driver/fveclib.c
index e2a7619e9b89f7f..ffe6937bd22ccc3 100644
--- a/clang/test/Driver/fveclib.c
+++ b/clang/test/Driver/fveclib.c
@@ -31,3 +31,27 @@
 
 // RUN: %clang -fveclib=Accelerate %s -nodefaultlibs -target 
arm64-apple-ios8.0.0 -### 2>&1 | FileCheck 
--check-prefix=CHECK-LINK-NODEFAULTLIBS %s
 // CHECK-LINK-NODEFAULTLIBS-NOT: "-framework" "Accelerate"
+
+
+/* Verify that the correct vector library is passed to LTO flags. */
+
+// RUN: %clang -### -fveclib=Accelerate -flto %s -v 2>&1 | FileCheck 
-check-prefix CHECK-LTO-ACCELERATE %s
+// CHECK-LTO-ACCELERATE: "-plugin-opt=-vector-library=Accelerate"
+
+// RUN: %clang -### --target=x86_64-unknown-linux-gnu  -fveclib=LIBMVEC -flto 
%s -v 2>&1 | FileCheck -check-prefix CHECK-LTO-LIBMVEC %s
+// CHECK-LTO-LIBMVEC: "-plugin-opt=-vector-library=LIBMVEC-X86"
+
+// RUN: %clang -### -fveclib=MASSV -flto %s -v 2>&1 | FileCheck -check-prefix 
CHECK-LTO-MASSV %s
+// CHECK-LTO-MASSV: "-plugin-opt=-vector-library=MASSV"
+
+// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fveclib=SVML -flto %s 
-v 2>&1 | FileCheck -check-prefix CHECK-LTO-SVML %s
+// CHECK-LTO-SVML: "-plugin-opt=-vector-library=SVML"
+
+// RUN: %clang -### --target=aarch64-linux-gnu -fveclib=SLEEF -flto %s -v 2>&1 
| FileCheck -check-prefix CHECK-LTO-SLEEF %s
+// CHECK-LTO-SLEEF: "-plugin-opt=-vector-library=sleefgnuabi"
+
+// RUN: %clang -### -fveclib=Darwin_libsystem_m -flto %s -v 2>&1 | FileCheck 
-check-prefix CHECK-LTO-DARWIN %s
+// CHECK-LTO-DARWIN: "-plugin-opt=-vector-library=Darwin_libsystem_m"
+
+// RUN: %clang -### --target=aarch64-linux-gnu -fveclib=ArmPL -flto %s -v 2>&1 
| FileCheck -check-prefix CHECK-LTO-ARMPL %s
+// CHECK-LTO-ARMPL: "-plugin-opt=-vector-library=ArmPL"

>From f1baf76580f331064ddee83751f77af77b985ba2 Mon Sep 17 00:00:00 2001
From: Paschalis Mpeis 
Date: Mon, 22 Jan 2024 15:59:23 +
Subject: [PATCH 2/3] Add targets to tests that call addLTOOptions

Tests that do not call addLTOOptions were removed.
---
 clang/test/Driver/fveclib.c | 10 ++
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/clang/test/Driver/fveclib.c b/clang/test/Driver/fveclib.c
index ffe6937bd22ccc3..7b5d189609c9293 100644
--- a/clang/test/Driver/fveclib.c
+++ b/clang/test/Driver/fveclib.c
@@ -35,13 +35,10 @@
 
 /* Verify that the correct vector library is passed to LTO flags. */
 
-// RUN: %clang -### -fveclib=Accelerate -flto %s -v 2>&1 | FileCheck 
-check-prefix CHECK-LTO-ACCELERATE %s
-// CHECK-LTO-ACCELERATE: "-plugin-opt=-vector-library=Accelerate"
-
-// RUN: %clang -### --target=x86_64-unknown-linux-gnu  -fveclib=LIBMVEC -flto 
%s -v 2>&1 | FileCheck -check-prefix CHECK-LTO-LIBMVEC %s
+// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fveclib=L

[clang] [llvm] [LV][LAA] Vectorize math lib calls with mem write-only attribute (PR #78432)

2024-01-23 Thread Paschalis Mpeis via cfe-commits

https://github.com/paschalis-mpeis updated 
https://github.com/llvm/llvm-project/pull/78432

>From 9e6020071d90decae5d61eced320a3f114b9d2a1 Mon Sep 17 00:00:00 2001
From: Paschalis Mpeis 
Date: Tue, 16 Jan 2024 10:53:09 +
Subject: [PATCH 1/4] LAA cannot vectorize lib calls like modf/modff

Functions like modf/modff are math lib calls that set memory write-only
attribute. Given that a target has vectorized mappings, LAA should allow
vectorization.
---
 ...arch64-veclib-function-calls-linear-ptrs.c | 57 +++
 1 file changed, 57 insertions(+)
 create mode 100644 
clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c

diff --git a/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c 
b/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c
new file mode 100644
index 000..a449fac147058ae
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c
@@ -0,0 +1,57 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --filter "call.*(frexp|modf)" --version 4
+// RUN: %clang --target=aarch64-linux-gnu -march=armv8-a+sve -O3 -mllvm 
-vector-library=ArmPL -mllvm -force-vector-interleave=1 -mllvm 
-prefer-predicate-over-epilogue=predicate-dont-vectorize -emit-llvm -S -o - %s 
| FileCheck %s
+
+// REQUIRES: aarch64-registered-target
+
+/*
+Testing vectorization of math functions that have the attribute write-only to
+memory set. Given they have vectorized counterparts, they should be able to
+vectorize.
+*/
+
+// The following define is required to access some math functions.
+#define _GNU_SOURCE
+#include 
+
+// frexp/frexpf have no TLI mappings yet.
+
+// CHECK-LABEL: define dso_local void @frexp_f64(
+// CHECK-SAME: ptr nocapture noundef readonly [[IN:%.*]], ptr nocapture 
noundef writeonly [[OUT1:%.*]], ptr nocapture noundef writeonly [[OUT2:%.*]], 
i32 noundef [[N:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK:[[CALL:%.*]] = tail call double @frexp(double noundef 
[[TMP0:%.*]], ptr noundef [[ADD_PTR:%.*]]) #[[ATTR2:[0-9]+]]
+//
+void frexp_f64(double *in, double *out1, int *out2, int N) {
+  for (int i = 0; i < N; ++i)
+*out1 = frexp(in[i], out2+i);
+}
+
+// CHECK-LABEL: define dso_local void @frexp_f32(
+// CHECK-SAME: ptr nocapture noundef readonly [[IN:%.*]], ptr nocapture 
noundef writeonly [[OUT1:%.*]], ptr nocapture noundef writeonly [[OUT2:%.*]], 
i32 noundef [[N:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK:[[CALL:%.*]] = tail call float @frexpf(float noundef 
[[TMP0:%.*]], ptr noundef [[ADD_PTR:%.*]]) #[[ATTR2]]
+//
+void frexp_f32(float *in, float *out1, int *out2, int N) {
+  for (int i = 0; i < N; ++i)
+*out1 = frexpf(in[i], out2+i);
+}
+
+
+// TODO: LAA must allow vectorization.
+
+// CHECK-LABEL: define dso_local void @modf_f64(
+// CHECK-SAME: ptr nocapture noundef readonly [[IN:%.*]], ptr nocapture 
noundef writeonly [[OUT1:%.*]], ptr nocapture noundef writeonly [[OUT2:%.*]], 
i32 noundef [[N:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK:[[CALL:%.*]] = tail call double @modf(double noundef 
[[TMP0:%.*]], ptr noundef [[ADD_PTR:%.*]]) #[[ATTR3:[0-9]+]]
+//
+void modf_f64(double *in, double *out1, double *out2, int N) {
+  for (int i = 0; i < N; ++i)
+  out1[i] = modf(in[i], out2+i);
+}
+
+// TODO: LAA must allow vectorization.
+
+// CHECK-LABEL: define dso_local void @modf_f32(
+// CHECK-SAME: ptr nocapture noundef readonly [[IN:%.*]], ptr nocapture 
noundef writeonly [[OUT1:%.*]], ptr nocapture noundef writeonly [[OUT2:%.*]], 
i32 noundef [[N:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK:[[CALL:%.*]] = tail call float @modff(float noundef [[TMP0:%.*]], 
ptr noundef [[ADD_PTR:%.*]]) #[[ATTR4:[0-9]+]]
+//
+void modf_f32(float *in, float *out1, float *out2, int N) {
+  for (int i = 0; i < N; ++i)
+  out1[i] = modff(in[i], out2+i);
+}

>From 97ebe120a9971903ed2aacd03db3fccd35452a30 Mon Sep 17 00:00:00 2001
From: Paschalis Mpeis 
Date: Wed, 17 Jan 2024 09:44:45 +
Subject: [PATCH 2/4] [LV][LAA] Vectorize math lib calls with mem write-only
 attribute

Teach LAA to consider safe specific math lib calls which are known to
have set the memory write-only attribute. Those attributes are set to
calls by inferNonMandatoryLibFuncAttrs, in BuildLibCalls.cpp, and the
current ones are modf/modff and frexp/frexpf.

This happens only when the calls are found through TLI to have
vectorized counterparts.
---
 ...arch64-veclib-function-calls-linear-ptrs.c | 15 ++-
 llvm/lib/Analysis/LoopAccessAnalysis.cpp  | 19 +++
 2 files changed, 25 insertions(+), 9 deletions(-)

diff --git a/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c 
b/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c
index a449fac147058ae..957b3f5cb235d31 100644
--- a/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c
+++ b/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c
@@ -17,7 +17,7 @@ vectorize.
 
 //

[clang] [llvm] [LV][LAA] Vectorize math lib calls with mem write-only attribute (PR #78432)

2024-02-22 Thread Paschalis Mpeis via cfe-commits

https://github.com/paschalis-mpeis updated 
https://github.com/llvm/llvm-project/pull/78432

>From 869079fa57b3a8da9b9f9ea541f7d542be1bb8bc Mon Sep 17 00:00:00 2001
From: Paschalis Mpeis 
Date: Tue, 16 Jan 2024 10:53:09 +
Subject: [PATCH 1/5] LAA cannot vectorize lib calls like modf/modff

Functions like modf/modff are math lib calls that set memory write-only
attribute. Given that a target has vectorized mappings, LAA should allow
vectorization.
---
 ...arch64-veclib-function-calls-linear-ptrs.c | 57 +++
 1 file changed, 57 insertions(+)
 create mode 100644 
clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c

diff --git a/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c 
b/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c
new file mode 100644
index 00..a449fac147058a
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c
@@ -0,0 +1,57 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --filter "call.*(frexp|modf)" --version 4
+// RUN: %clang --target=aarch64-linux-gnu -march=armv8-a+sve -O3 -mllvm 
-vector-library=ArmPL -mllvm -force-vector-interleave=1 -mllvm 
-prefer-predicate-over-epilogue=predicate-dont-vectorize -emit-llvm -S -o - %s 
| FileCheck %s
+
+// REQUIRES: aarch64-registered-target
+
+/*
+Testing vectorization of math functions that have the attribute write-only to
+memory set. Given they have vectorized counterparts, they should be able to
+vectorize.
+*/
+
+// The following define is required to access some math functions.
+#define _GNU_SOURCE
+#include 
+
+// frexp/frexpf have no TLI mappings yet.
+
+// CHECK-LABEL: define dso_local void @frexp_f64(
+// CHECK-SAME: ptr nocapture noundef readonly [[IN:%.*]], ptr nocapture 
noundef writeonly [[OUT1:%.*]], ptr nocapture noundef writeonly [[OUT2:%.*]], 
i32 noundef [[N:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK:[[CALL:%.*]] = tail call double @frexp(double noundef 
[[TMP0:%.*]], ptr noundef [[ADD_PTR:%.*]]) #[[ATTR2:[0-9]+]]
+//
+void frexp_f64(double *in, double *out1, int *out2, int N) {
+  for (int i = 0; i < N; ++i)
+*out1 = frexp(in[i], out2+i);
+}
+
+// CHECK-LABEL: define dso_local void @frexp_f32(
+// CHECK-SAME: ptr nocapture noundef readonly [[IN:%.*]], ptr nocapture 
noundef writeonly [[OUT1:%.*]], ptr nocapture noundef writeonly [[OUT2:%.*]], 
i32 noundef [[N:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK:[[CALL:%.*]] = tail call float @frexpf(float noundef 
[[TMP0:%.*]], ptr noundef [[ADD_PTR:%.*]]) #[[ATTR2]]
+//
+void frexp_f32(float *in, float *out1, int *out2, int N) {
+  for (int i = 0; i < N; ++i)
+*out1 = frexpf(in[i], out2+i);
+}
+
+
+// TODO: LAA must allow vectorization.
+
+// CHECK-LABEL: define dso_local void @modf_f64(
+// CHECK-SAME: ptr nocapture noundef readonly [[IN:%.*]], ptr nocapture 
noundef writeonly [[OUT1:%.*]], ptr nocapture noundef writeonly [[OUT2:%.*]], 
i32 noundef [[N:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK:[[CALL:%.*]] = tail call double @modf(double noundef 
[[TMP0:%.*]], ptr noundef [[ADD_PTR:%.*]]) #[[ATTR3:[0-9]+]]
+//
+void modf_f64(double *in, double *out1, double *out2, int N) {
+  for (int i = 0; i < N; ++i)
+  out1[i] = modf(in[i], out2+i);
+}
+
+// TODO: LAA must allow vectorization.
+
+// CHECK-LABEL: define dso_local void @modf_f32(
+// CHECK-SAME: ptr nocapture noundef readonly [[IN:%.*]], ptr nocapture 
noundef writeonly [[OUT1:%.*]], ptr nocapture noundef writeonly [[OUT2:%.*]], 
i32 noundef [[N:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK:[[CALL:%.*]] = tail call float @modff(float noundef [[TMP0:%.*]], 
ptr noundef [[ADD_PTR:%.*]]) #[[ATTR4:[0-9]+]]
+//
+void modf_f32(float *in, float *out1, float *out2, int N) {
+  for (int i = 0; i < N; ++i)
+  out1[i] = modff(in[i], out2+i);
+}

>From 32d2b4581dd19e289f5b21de6de931b4f6268612 Mon Sep 17 00:00:00 2001
From: Paschalis Mpeis 
Date: Wed, 17 Jan 2024 09:44:45 +
Subject: [PATCH 2/5] [LV][LAA] Vectorize math lib calls with mem write-only
 attribute

Teach LAA to consider safe specific math lib calls which are known to
have set the memory write-only attribute. Those attributes are set to
calls by inferNonMandatoryLibFuncAttrs, in BuildLibCalls.cpp, and the
current ones are modf/modff and frexp/frexpf.

This happens only when the calls are found through TLI to have
vectorized counterparts.
---
 ...arch64-veclib-function-calls-linear-ptrs.c | 15 ++-
 llvm/lib/Analysis/LoopAccessAnalysis.cpp  | 19 +++
 2 files changed, 25 insertions(+), 9 deletions(-)

diff --git a/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c 
b/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c
index a449fac147058a..957b3f5cb235d3 100644
--- a/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c
+++ b/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c
@@ -17,7 +17,7 @@ vectorize.
 
 // CHE

[clang] [llvm] [LV][LAA] Vectorize math lib calls with mem write-only attribute (PR #78432)

2024-02-22 Thread Paschalis Mpeis via cfe-commits

paschalis-mpeis wrote:

Rebased to main after a couple of weeks of inactivity.

Note: windows x64 build failure seems unrelated; more likely a wide problem, 
failing at cmake configure.

https://github.com/llvm/llvm-project/pull/78432
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [LV][LAA] Vectorize math lib calls with mem write-only attribute (PR #78432)

2024-02-22 Thread Paschalis Mpeis via cfe-commits


@@ -0,0 +1,52 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --filter "call.*(frexp|modf)" --version 4
+// RUN: %clang --target=aarch64-linux-gnu -march=armv8-a+sve -O3 -isystem 
%S/../Headers/Inputs/include -mllvm -vector-library=ArmPL -mllvm 
-force-vector-interleave=1 -mllvm 
-prefer-predicate-over-epilogue=predicate-dont-vectorize -emit-llvm -S -o - %s 
| FileCheck %s
+
+// REQUIRES: aarch64-registered-target
+
+/*
+Testing vectorization of math functions that have the attribute write-only to
+memory set. Given they have vectorized counterparts, they should be able to
+vectorize.
+*/
+
+// The following define is required to access some math functions.
+#define _GNU_SOURCE
+#include 
+
+// frexp/frexpf have no TLI mappings yet.
+
+// CHECK-LABEL: define dso_local void @frexp_f64(
+// CHECK-SAME: ptr nocapture noundef readonly [[IN:%.*]], ptr nocapture 
noundef writeonly [[OUT1:%.*]], ptr nocapture noundef writeonly [[OUT2:%.*]], 
i32 noundef [[N:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK:[[CALL:%.*]] = tail call double @frexp(double noundef 
[[TMP0:%.*]], ptr noundef [[ADD_PTR:%.*]]) #[[ATTR2:[0-9]+]]
+//
+void frexp_f64(double *in, double *out1, int *out2, int N) {
+  for (int i = 0; i < N; ++i)
+*out1 = frexp(in[i], out2+i);
+}
+
+// CHECK-LABEL: define dso_local void @frexp_f32(
+// CHECK-SAME: ptr nocapture noundef readonly [[IN:%.*]], ptr nocapture 
noundef writeonly [[OUT1:%.*]], ptr nocapture noundef writeonly [[OUT2:%.*]], 
i32 noundef [[N:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK:[[CALL:%.*]] = tail call float @frexpf(float noundef 
[[TMP0:%.*]], ptr noundef [[ADD_PTR:%.*]]) #[[ATTR2]]
+//
+void frexp_f32(float *in, float *out1, int *out2, int N) {
+  for (int i = 0; i < N; ++i)
+*out1 = frexpf(in[i], out2+i);
+}
+
+// CHECK-LABEL: define dso_local void @modf_f64(
+// CHECK-SAME: ptr nocapture noundef readonly [[IN:%.*]], ptr nocapture 
noundef writeonly [[OUT1:%.*]], ptr nocapture noundef writeonly [[OUT2:%.*]], 
i32 noundef [[N:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK:[[CALL:%.*]] = tail call double @modf(double noundef 
[[TMP0:%.*]], ptr noundef [[ADD_PTR:%.*]]) #[[ATTR3:[0-9]+]]
+//
+void modf_f64(double *in, double *out1, double *out2, int N) {
+  for (int i = 0; i < N; ++i)
+  out1[i] = modf(in[i], out2+i);
+}
+
+// CHECK-LABEL: define dso_local void @modf_f32(
+// CHECK-SAME: ptr nocapture noundef readonly [[IN:%.*]], ptr nocapture 
noundef writeonly [[OUT1:%.*]], ptr nocapture noundef writeonly [[OUT2:%.*]], 
i32 noundef [[N:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK:[[CALL:%.*]] = tail call float @modff(float noundef [[TMP0:%.*]], 
ptr noundef [[ADD_PTR:%.*]]) #[[ATTR4:[0-9]+]]
+//
+void modf_f32(float *in, float *out1, float *out2, int N) {
+  for (int i = 0; i < N; ++i)
+  out1[i] = modff(in[i], out2+i);
+}

paschalis-mpeis wrote:

> This test needs to be in either llvm/test/Transforms/LoopVectorize or 
> llvm/test/Analysis/LoopAccessAnalysis, depending on what exactly you want to 
> test.

I've used a C test, hence the placement. You'd prefer an LLVM IR test?

> I don't really get what this test is checking for though, it doesn't look 
> like anything was actually vectorized?

Actually, the below patch removed modf/modff TLI mappings since this one was 
opened, due to some errors that were discovered. I'm converting this patch to a 
draft until those mappings are back again.
- #80296





https://github.com/llvm/llvm-project/pull/78432
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [LV][LAA] Vectorize math lib calls with mem write-only attribute (PR #78432)

2024-02-22 Thread Paschalis Mpeis via cfe-commits

https://github.com/paschalis-mpeis converted_to_draft 
https://github.com/llvm/llvm-project/pull/78432
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [LV][LAA] Vectorize math lib calls with mem write-only attribute (PR #78432)

2024-04-11 Thread Paschalis Mpeis via cfe-commits

https://github.com/paschalis-mpeis edited 
https://github.com/llvm/llvm-project/pull/78432
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [LV][LAA] Vectorize math lib calls with mem write-only attribute (PR #78432)

2024-04-11 Thread Paschalis Mpeis via cfe-commits

https://github.com/paschalis-mpeis edited 
https://github.com/llvm/llvm-project/pull/78432
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [LV][LAA] Vectorize math lib calls with mem write-only attribute (PR #78432)

2024-04-11 Thread Paschalis Mpeis via cfe-commits

https://github.com/paschalis-mpeis ready_for_review 
https://github.com/llvm/llvm-project/pull/78432
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [LV][LAA] Vectorize math lib calls with mem write-only attribute (PR #78432)

2024-04-11 Thread Paschalis Mpeis via cfe-commits

paschalis-mpeis wrote:

Rebased to main after #80296 was merged:
- #80296

https://github.com/llvm/llvm-project/pull/78432
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [LV][LAA] Vectorize math lib calls with mem write-only attribute (PR #78432)

2024-04-30 Thread Paschalis Mpeis via cfe-commits


@@ -0,0 +1,117 @@
+; RUN: opt < %s -mattr=+sve -vector-library=ArmPL 
-passes=inject-tli-mappings,loop-vectorize -debug-only=loop-accesses 
-disable-output 2>&1 | FileCheck %s
+
+; REQUIRES: asserts
+
+target triple = "aarch64-unknown-linux-gnu"
+
+; TODO: add mappings for frexp/frexpf

paschalis-mpeis wrote:


It turns out without the mappings LV Legality does not let it vectorize earlier 
([here](https://github.com/llvm/llvm-project/blob/eaf0d82529f30fd53b453886676821d67ccfe9af/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp#L900)):
> LV: Not vectorizing: Found a non-intrinsic callsite   %call = tail call float 
> @frexpf(float noundef %0, ptr noundef %add.ptr)
> ..
>LV: Not vectorizing: Cannot prove legality

I will keep the those LAA frexp/frexpf tests, but I'll convert TODO's in a 
similar fashion with the [next 
comment](https://github.com/llvm/llvm-project/pull/78432#discussion_r1581031468).


https://github.com/llvm/llvm-project/pull/78432
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [LV][LAA] Vectorize math lib calls with mem write-only attribute (PR #78432)

2024-04-30 Thread Paschalis Mpeis via cfe-commits

https://github.com/paschalis-mpeis converted_to_draft 
https://github.com/llvm/llvm-project/pull/78432
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [LV][LAA] Vectorize math lib calls with mem write-only attribute (PR #78432)

2024-04-30 Thread Paschalis Mpeis via cfe-commits

https://github.com/paschalis-mpeis updated 
https://github.com/llvm/llvm-project/pull/78432

>From d3ca209a7690d9ecbe188d8a2145177f43ed1951 Mon Sep 17 00:00:00 2001
From: Paschalis Mpeis 
Date: Tue, 16 Jan 2024 10:53:09 +
Subject: [PATCH 1/7] LAA cannot vectorize lib calls like modf/modff

Functions like modf/modff are math lib calls that set memory write-only
attribute. Given that a target has vectorized mappings, LAA should allow
vectorization.
---
 ...arch64-veclib-function-calls-linear-ptrs.c | 57 +++
 1 file changed, 57 insertions(+)
 create mode 100644 
clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c

diff --git a/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c 
b/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c
new file mode 100644
index 00..a449fac147058a
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c
@@ -0,0 +1,57 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --filter "call.*(frexp|modf)" --version 4
+// RUN: %clang --target=aarch64-linux-gnu -march=armv8-a+sve -O3 -mllvm 
-vector-library=ArmPL -mllvm -force-vector-interleave=1 -mllvm 
-prefer-predicate-over-epilogue=predicate-dont-vectorize -emit-llvm -S -o - %s 
| FileCheck %s
+
+// REQUIRES: aarch64-registered-target
+
+/*
+Testing vectorization of math functions that have the attribute write-only to
+memory set. Given they have vectorized counterparts, they should be able to
+vectorize.
+*/
+
+// The following define is required to access some math functions.
+#define _GNU_SOURCE
+#include 
+
+// frexp/frexpf have no TLI mappings yet.
+
+// CHECK-LABEL: define dso_local void @frexp_f64(
+// CHECK-SAME: ptr nocapture noundef readonly [[IN:%.*]], ptr nocapture 
noundef writeonly [[OUT1:%.*]], ptr nocapture noundef writeonly [[OUT2:%.*]], 
i32 noundef [[N:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK:[[CALL:%.*]] = tail call double @frexp(double noundef 
[[TMP0:%.*]], ptr noundef [[ADD_PTR:%.*]]) #[[ATTR2:[0-9]+]]
+//
+void frexp_f64(double *in, double *out1, int *out2, int N) {
+  for (int i = 0; i < N; ++i)
+*out1 = frexp(in[i], out2+i);
+}
+
+// CHECK-LABEL: define dso_local void @frexp_f32(
+// CHECK-SAME: ptr nocapture noundef readonly [[IN:%.*]], ptr nocapture 
noundef writeonly [[OUT1:%.*]], ptr nocapture noundef writeonly [[OUT2:%.*]], 
i32 noundef [[N:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK:[[CALL:%.*]] = tail call float @frexpf(float noundef 
[[TMP0:%.*]], ptr noundef [[ADD_PTR:%.*]]) #[[ATTR2]]
+//
+void frexp_f32(float *in, float *out1, int *out2, int N) {
+  for (int i = 0; i < N; ++i)
+*out1 = frexpf(in[i], out2+i);
+}
+
+
+// TODO: LAA must allow vectorization.
+
+// CHECK-LABEL: define dso_local void @modf_f64(
+// CHECK-SAME: ptr nocapture noundef readonly [[IN:%.*]], ptr nocapture 
noundef writeonly [[OUT1:%.*]], ptr nocapture noundef writeonly [[OUT2:%.*]], 
i32 noundef [[N:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK:[[CALL:%.*]] = tail call double @modf(double noundef 
[[TMP0:%.*]], ptr noundef [[ADD_PTR:%.*]]) #[[ATTR3:[0-9]+]]
+//
+void modf_f64(double *in, double *out1, double *out2, int N) {
+  for (int i = 0; i < N; ++i)
+  out1[i] = modf(in[i], out2+i);
+}
+
+// TODO: LAA must allow vectorization.
+
+// CHECK-LABEL: define dso_local void @modf_f32(
+// CHECK-SAME: ptr nocapture noundef readonly [[IN:%.*]], ptr nocapture 
noundef writeonly [[OUT1:%.*]], ptr nocapture noundef writeonly [[OUT2:%.*]], 
i32 noundef [[N:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK:[[CALL:%.*]] = tail call float @modff(float noundef [[TMP0:%.*]], 
ptr noundef [[ADD_PTR:%.*]]) #[[ATTR4:[0-9]+]]
+//
+void modf_f32(float *in, float *out1, float *out2, int N) {
+  for (int i = 0; i < N; ++i)
+  out1[i] = modff(in[i], out2+i);
+}

>From 1dc1b5cb8e52761027d85edcd057ef57710d2699 Mon Sep 17 00:00:00 2001
From: Paschalis Mpeis 
Date: Wed, 17 Jan 2024 09:44:45 +
Subject: [PATCH 2/7] [LV][LAA] Vectorize math lib calls with mem write-only
 attribute

Teach LAA to consider safe specific math lib calls which are known to
have set the memory write-only attribute. Those attributes are set to
calls by inferNonMandatoryLibFuncAttrs, in BuildLibCalls.cpp, and the
current ones are modf/modff and frexp/frexpf.

This happens only when the calls are found through TLI to have
vectorized counterparts.
---
 ...arch64-veclib-function-calls-linear-ptrs.c | 15 ++-
 llvm/lib/Analysis/LoopAccessAnalysis.cpp  | 19 +++
 2 files changed, 25 insertions(+), 9 deletions(-)

diff --git a/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c 
b/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c
index a449fac147058a..957b3f5cb235d3 100644
--- a/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c
+++ b/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c
@@ -17,7 +17,7 @@ vectorize.
 
 // CHE

[clang] [llvm] [LV][LAA] Vectorize math lib calls with mem write-only attribute (PR #78432)

2024-04-30 Thread Paschalis Mpeis via cfe-commits

https://github.com/paschalis-mpeis ready_for_review 
https://github.com/llvm/llvm-project/pull/78432
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [LV][LAA] Vectorize math lib calls with mem write-only attribute (PR #78432)

2024-04-30 Thread Paschalis Mpeis via cfe-commits


@@ -0,0 +1,117 @@
+; RUN: opt < %s -mattr=+sve -vector-library=ArmPL 
-passes=inject-tli-mappings,loop-vectorize -debug-only=loop-accesses 
-disable-output 2>&1 | FileCheck %s

paschalis-mpeis wrote:

Indeed, using `-passes='print'` is a better option here:
- it allows running LAA on the code regardless of LV's Legality result
- this would allow checking for `frexp` methods in a target agnostic manner.

Great suggestion, thanks!

https://github.com/llvm/llvm-project/pull/78432
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [LV][LAA] Vectorize math lib calls with mem write-only attribute (PR #78432)

2024-04-30 Thread Paschalis Mpeis via cfe-commits

https://github.com/paschalis-mpeis edited 
https://github.com/llvm/llvm-project/pull/78432
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [LV][LAA] Vectorize math lib calls with mem write-only attribute (PR #78432)

2024-04-30 Thread Paschalis Mpeis via cfe-commits

https://github.com/paschalis-mpeis updated 
https://github.com/llvm/llvm-project/pull/78432

>From d3ca209a7690d9ecbe188d8a2145177f43ed1951 Mon Sep 17 00:00:00 2001
From: Paschalis Mpeis 
Date: Tue, 16 Jan 2024 10:53:09 +
Subject: [PATCH 1/7] LAA cannot vectorize lib calls like modf/modff

Functions like modf/modff are math lib calls that set memory write-only
attribute. Given that a target has vectorized mappings, LAA should allow
vectorization.
---
 ...arch64-veclib-function-calls-linear-ptrs.c | 57 +++
 1 file changed, 57 insertions(+)
 create mode 100644 
clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c

diff --git a/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c 
b/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c
new file mode 100644
index 00..a449fac147058a
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c
@@ -0,0 +1,57 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --filter "call.*(frexp|modf)" --version 4
+// RUN: %clang --target=aarch64-linux-gnu -march=armv8-a+sve -O3 -mllvm 
-vector-library=ArmPL -mllvm -force-vector-interleave=1 -mllvm 
-prefer-predicate-over-epilogue=predicate-dont-vectorize -emit-llvm -S -o - %s 
| FileCheck %s
+
+// REQUIRES: aarch64-registered-target
+
+/*
+Testing vectorization of math functions that have the attribute write-only to
+memory set. Given they have vectorized counterparts, they should be able to
+vectorize.
+*/
+
+// The following define is required to access some math functions.
+#define _GNU_SOURCE
+#include 
+
+// frexp/frexpf have no TLI mappings yet.
+
+// CHECK-LABEL: define dso_local void @frexp_f64(
+// CHECK-SAME: ptr nocapture noundef readonly [[IN:%.*]], ptr nocapture 
noundef writeonly [[OUT1:%.*]], ptr nocapture noundef writeonly [[OUT2:%.*]], 
i32 noundef [[N:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK:[[CALL:%.*]] = tail call double @frexp(double noundef 
[[TMP0:%.*]], ptr noundef [[ADD_PTR:%.*]]) #[[ATTR2:[0-9]+]]
+//
+void frexp_f64(double *in, double *out1, int *out2, int N) {
+  for (int i = 0; i < N; ++i)
+*out1 = frexp(in[i], out2+i);
+}
+
+// CHECK-LABEL: define dso_local void @frexp_f32(
+// CHECK-SAME: ptr nocapture noundef readonly [[IN:%.*]], ptr nocapture 
noundef writeonly [[OUT1:%.*]], ptr nocapture noundef writeonly [[OUT2:%.*]], 
i32 noundef [[N:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK:[[CALL:%.*]] = tail call float @frexpf(float noundef 
[[TMP0:%.*]], ptr noundef [[ADD_PTR:%.*]]) #[[ATTR2]]
+//
+void frexp_f32(float *in, float *out1, int *out2, int N) {
+  for (int i = 0; i < N; ++i)
+*out1 = frexpf(in[i], out2+i);
+}
+
+
+// TODO: LAA must allow vectorization.
+
+// CHECK-LABEL: define dso_local void @modf_f64(
+// CHECK-SAME: ptr nocapture noundef readonly [[IN:%.*]], ptr nocapture 
noundef writeonly [[OUT1:%.*]], ptr nocapture noundef writeonly [[OUT2:%.*]], 
i32 noundef [[N:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK:[[CALL:%.*]] = tail call double @modf(double noundef 
[[TMP0:%.*]], ptr noundef [[ADD_PTR:%.*]]) #[[ATTR3:[0-9]+]]
+//
+void modf_f64(double *in, double *out1, double *out2, int N) {
+  for (int i = 0; i < N; ++i)
+  out1[i] = modf(in[i], out2+i);
+}
+
+// TODO: LAA must allow vectorization.
+
+// CHECK-LABEL: define dso_local void @modf_f32(
+// CHECK-SAME: ptr nocapture noundef readonly [[IN:%.*]], ptr nocapture 
noundef writeonly [[OUT1:%.*]], ptr nocapture noundef writeonly [[OUT2:%.*]], 
i32 noundef [[N:%.*]]) local_unnamed_addr #[[ATTR0]] {
+// CHECK:[[CALL:%.*]] = tail call float @modff(float noundef [[TMP0:%.*]], 
ptr noundef [[ADD_PTR:%.*]]) #[[ATTR4:[0-9]+]]
+//
+void modf_f32(float *in, float *out1, float *out2, int N) {
+  for (int i = 0; i < N; ++i)
+  out1[i] = modff(in[i], out2+i);
+}

>From 1dc1b5cb8e52761027d85edcd057ef57710d2699 Mon Sep 17 00:00:00 2001
From: Paschalis Mpeis 
Date: Wed, 17 Jan 2024 09:44:45 +
Subject: [PATCH 2/7] [LV][LAA] Vectorize math lib calls with mem write-only
 attribute

Teach LAA to consider safe specific math lib calls which are known to
have set the memory write-only attribute. Those attributes are set to
calls by inferNonMandatoryLibFuncAttrs, in BuildLibCalls.cpp, and the
current ones are modf/modff and frexp/frexpf.

This happens only when the calls are found through TLI to have
vectorized counterparts.
---
 ...arch64-veclib-function-calls-linear-ptrs.c | 15 ++-
 llvm/lib/Analysis/LoopAccessAnalysis.cpp  | 19 +++
 2 files changed, 25 insertions(+), 9 deletions(-)

diff --git a/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c 
b/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c
index a449fac147058a..957b3f5cb235d3 100644
--- a/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c
+++ b/clang/test/CodeGen/aarch64-veclib-function-calls-linear-ptrs.c
@@ -17,7 +17,7 @@ vectorize.
 
 // CHE

[clang] [llvm] [LV][LAA] Vectorize math lib calls with mem write-only attribute (PR #78432)

2024-04-30 Thread Paschalis Mpeis via cfe-commits

https://github.com/paschalis-mpeis edited 
https://github.com/llvm/llvm-project/pull/78432
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [LV][LAA] Vectorize math lib calls with mem write-only attribute (PR #78432)

2024-04-30 Thread Paschalis Mpeis via cfe-commits

https://github.com/paschalis-mpeis edited 
https://github.com/llvm/llvm-project/pull/78432
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [LV][LAA] Vectorize math lib calls with mem write-only attribute (PR #78432)

2024-04-30 Thread Paschalis Mpeis via cfe-commits


@@ -0,0 +1,117 @@
+; RUN: opt < %s -mattr=+sve -vector-library=ArmPL 
-passes=inject-tli-mappings,loop-vectorize -debug-only=loop-accesses 
-disable-output 2>&1 | FileCheck %s
+
+; REQUIRES: asserts
+
+target triple = "aarch64-unknown-linux-gnu"
+
+; TODO: add mappings for frexp/frexpf

paschalis-mpeis wrote:

Short answer: Not needed.

---

**Longer answer:**
Using `-passes='print'` (as per @mgabka suggestion), LAA pass can 
run regardless of vecLib existence, TLI mappings, and/or even SVE support.

Previously, in the LAA test 
[attr-mem-write-only.ll](https://github.com/llvm/llvm-project/pull/78432/commits/c3aa63c98627c2edf16420c5a4aa53ba233d544c#diff-6e65eaeb2e328f78d3620c102adaa22dd2a4e6bd0e677208ecb32e772c21089c)
 I had:
- `-mattr=+sve -vector-library=ArmPL -passes=inject-tli-mappings,loop-vectorize`

and yet, I couldn't check for the fexpr calls, as `LoopVectorizationLegality` 
would not allow vectorization.

With the latest patch, however, LAA runs regardless, so I'm able to do such 
checks already 
([here](https://github.com/llvm/llvm-project/pull/78432/commits/c3aa63c98627c2edf16420c5a4aa53ba233d544c#diff-6e65eaeb2e328f78d3620c102adaa22dd2a4e6bd0e677208ecb32e772c21089cR7)
 and 
[here](https://github.com/llvm/llvm-project/pull/78432/commits/c3aa63c98627c2edf16420c5a4aa53ba233d544c#diff-6e65eaeb2e328f78d3620c102adaa22dd2a4e6bd0e677208ecb32e772c21089cR34)).

In the future, when the mappings for frexp are added, only the LV tests would 
need to be updated 
([AArch64/veclib-function-calls-linear-ptrs.ll](https://github.com/llvm/llvm-project/pull/78432/commits/c3aa63c98627c2edf16420c5a4aa53ba233d544c#diff-7dd871d3ed08b76c541f7abb3a1d170800dab9d90dd16c4795ad747c94a17e65)).

https://github.com/llvm/llvm-project/pull/78432
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [LV][LAA] Vectorize math lib calls with mem write-only attribute (PR #78432)

2024-04-30 Thread Paschalis Mpeis via cfe-commits

https://github.com/paschalis-mpeis edited 
https://github.com/llvm/llvm-project/pull/78432
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [LV][LAA] Vectorize math lib calls with mem write-only attribute (PR #78432)

2024-05-09 Thread Paschalis Mpeis via cfe-commits

paschalis-mpeis wrote:

### Rebased to:
1. Update to latest main
2. Amend commits for doing tests in veclib-function-calls.ll.

For (2), the commit history were modified as follows:
- The initial commit (that showcases what was missing) was amended to  add the 
tests in veclib-function-calls.ll.
- Then, subsequent commits were similarly amended to include the updates that 
allow vectorization.
- This currently latest commit simply dropped the no longer needed tests  
(veclib-function-calls-linear-ptrs.ll)

https://github.com/llvm/llvm-project/pull/78432
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [LV][LAA] Vectorize math lib calls with mem write-only attribute (PR #78432)

2024-06-25 Thread Paschalis Mpeis via cfe-commits

https://github.com/paschalis-mpeis converted_to_draft 
https://github.com/llvm/llvm-project/pull/78432
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits