[clang] [clang] Lower non-builtin sincos[f|l] calls to llvm.sincos.* when -fno-math-errno is set (PR #121763)

2025-02-19 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`sanitizer-aarch64-linux-bootstrap-hwasan` running on `sanitizer-buildbot12` 
while building `clang` at step 2 "annotate".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/55/builds/7267


Here is the relevant piece of the build log for the reference

```
Step 2 (annotate) failure: 'python 
../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py'
 (failure)
...
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using lld-link: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build2_hwasan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using ld64.lld: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build2_hwasan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using wasm-ld: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build2_hwasan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using ld.lld: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build2_hwasan/bin/ld.lld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using lld-link: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build2_hwasan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using ld64.lld: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build2_hwasan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using wasm-ld: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build2_hwasan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/lit/lit/main.py:72:
 note: The test suite configuration requested an individual test timeout of 0 
seconds but a timeout of 900 seconds was requested on the command line. Forcing 
timeout to be 900 seconds.
-- Testing: 83666 tests, 72 workers --
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90..
FAIL: lld :: ELF/ppc64-toc-call-to-pcrel-long-jump.s (82727 of 83666)
 TEST 'lld :: ELF/ppc64-toc-call-to-pcrel-long-jump.s' 
FAILED 
Exit Code: 139

Command Output (stderr):
--
RUN: at line 2: split-file 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/lld/test/ELF/ppc64-toc-call-to-pcrel-long-jump.s
 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build2_hwasan/tools/lld/test/ELF/Output/ppc64-toc-call-to-pcrel-long-jump.s.tmp
+ split-file 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/lld/test/ELF/ppc64-toc-call-to-pcrel-long-jump.s
 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build2_hwasan/tools/lld/test/ELF/Output/ppc64-toc-call-to-pcrel-long-jump.s.tmp
RUN: at line 4: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build2_hwasan/bin/llvm-mc
 -filetype=obj -triple=powerpc64le 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build2_hwasan/tools/lld/test/ELF/Output/ppc64-toc-call-to-pcrel-long-jump.s.tmp/asm
 -o 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build2_hwasan/tools/lld/test/ELF/Output/ppc64-toc-call-to-pcrel-long-jump.s.tmp.o
+ 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build2_hwasan/bin/llvm-mc
 -filetype=obj -triple=powerpc64le 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build2_hwasan/tools/lld/test/ELF/Output/ppc64-toc-call-to-pcrel-long-jump.s.tmp/asm
 -o 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build2_hwasan/tools/lld/test/ELF/Output/ppc64-toc-call-to-pcrel-long-jump.s.tmp.o
RUN: at line 5: 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build2_hwasan/bin/ld.lld
 -T 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build2_hwasan/tools/lld/test/ELF/Output/ppc64-toc-call-to-pcrel-long-jump.s.tmp/lts
 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build2_hwasan/tools/lld/test/ELF/Output/ppc64-toc-call-to-pcrel-long-jump.s.tmp.o
 -o 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build2_hwasan/tools/lld/test/ELF/Output/ppc64-toc-call-to-pcrel-long-jump.s.tmp_le
+ 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build2_hwasan/bin/ld.lld
 -T 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build2_hwasan/tools/lld/test/ELF/Output/ppc64-toc-call-to-pcrel-long-jump.s.tmp/lts
 
/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build2_hwasan/tools/lld/test/ELF/Output/ppc64-toc-ca

[clang] [clang] Lower non-builtin sincos[f|l] calls to llvm.sincos.* when -fno-math-errno is set (PR #121763)

2025-02-19 Thread Benjamin Maxwell via cfe-commits

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


[clang] [clang] Lower non-builtin sincos[f|l] calls to llvm.sincos.* when -fno-math-errno is set (PR #121763)

2025-02-18 Thread Benjamin Maxwell via cfe-commits

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


[clang] [clang] Lower non-builtin sincos[f|l] calls to llvm.sincos.* when -fno-math-errno is set (PR #121763)

2025-02-18 Thread Matt Arsenault via cfe-commits

https://github.com/arsenm approved this pull request.


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


[clang] [clang] Lower non-builtin sincos[f|l] calls to llvm.sincos.* when -fno-math-errno is set (PR #121763)

2025-02-18 Thread Benjamin Maxwell via cfe-commits

MacDue wrote:

> I'm a hard no on making this a target dependent option. Just enable it 
> unconditionally and take the regression

Fine, I don't mind the regression as it does not affect targets I work on, I 
just wanted to make the changes needed for AArch64 without knowingly slightly 
regressing other targets. 

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


[clang] [clang] Lower non-builtin sincos[f|l] calls to llvm.sincos.* when -fno-math-errno is set (PR #121763)

2025-02-18 Thread Benjamin Maxwell via cfe-commits

https://github.com/MacDue updated 
https://github.com/llvm/llvm-project/pull/121763

>From 42b096396f36adc6f1ad34de263a80dd7e4e0960 Mon Sep 17 00:00:00 2001
From: Benjamin Maxwell 
Date: Mon, 6 Jan 2025 11:49:48 +
Subject: [PATCH 1/5] [clang] Lower non-builtin sincos[f|l] calls to
 llvm.sincos.* when -fno-math-errno is set

This will allow vectorizing these calls (after a few more patches). This
should not change the codegen for targets that enable the use of AA
during the codegen (in `TargetSubtargetInfo::useAA()`). This includes
targets such as AArch64. This notably does not include x86 but can be
worked around by passing `-mllvm -combiner-global-alias-analysis=true`
to clang.
---
 clang/lib/CodeGen/CGBuiltin.cpp |  3 +++
 clang/test/CodeGen/AArch64/sincos.c | 24 +++-
 2 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index d57f491a20c8e..d3f41563aed9d 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3377,6 +3377,9 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   return RValue::get(emitUnaryMaybeConstrainedFPBuiltin(
   *this, E, Intrinsic::sinh, 
Intrinsic::experimental_constrained_sinh));
 
+case Builtin::BIsincos:
+case Builtin::BIsincosf:
+case Builtin::BIsincosl:
 case Builtin::BI__builtin_sincos:
 case Builtin::BI__builtin_sincosf:
 case Builtin::BI__builtin_sincosf16:
diff --git a/clang/test/CodeGen/AArch64/sincos.c 
b/clang/test/CodeGen/AArch64/sincos.c
index b77d98ceab486..fde277716 100644
--- a/clang/test/CodeGen/AArch64/sincos.c
+++ b/clang/test/CodeGen/AArch64/sincos.c
@@ -1,5 +1,19 @@
-// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -O1 %s -o - | 
FileCheck --check-prefix=NO-MATH-ERRNO %s
-// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -fmath-errno %s -o - | 
FileCheck --check-prefix=MATH-ERRNO %s
+// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -O1 %s -o - 
-DUSE_BUILTIN | FileCheck --check-prefix=NO-MATH-ERRNO %s
+// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -fmath-errno %s -o - 
-DUSE_BUILTIN | FileCheck --check-prefix=MATH-ERRNO %s
+// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -O1 %s -o - 
-DUSE_C_DECL | FileCheck --check-prefix=NO-MATH-ERRNO %s
+// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -fmath-errno %s -o - 
-DUSE_C_DECL | FileCheck --check-prefix=MATH-ERRNO %s
+
+#if defined(USE_BUILTIN)
+  #define sincos __builtin_sincos
+  #define sincosf __builtin_sincosf
+  #define sincosl __builtin_sincosl
+#elif defined(USE_C_DECL)
+  void sincos(double, double*, double*);
+  void sincosf(float, float*, float*);
+  void sincosl(long double, long double*, long double*);
+#else
+#error Expected USE_BUILTIN or USE_C_DECL to be defined.
+#endif
 
 // NO-MATH-ERRNO-LABEL: @sincos_f32
 //  NO-MATH-ERRNO:[[SINCOS:%.*]] = tail call { float, float } 
@llvm.sincos.f32(float {{.*}})
@@ -12,7 +26,7 @@
 //  MATH-ERRNO:call void @sincosf(
 //
 void sincos_f32(float x, float* fp0, float* fp1) {
-  __builtin_sincosf(x, fp0, fp1);
+  sincosf(x, fp0, fp1);
 }
 
 // NO-MATH-ERRNO-LABEL: @sincos_f64
@@ -26,7 +40,7 @@ void sincos_f32(float x, float* fp0, float* fp1) {
 //  MATH-ERRNO:call void @sincos(
 //
 void sincos_f64(double x, double* dp0, double* dp1) {
-  __builtin_sincos(x, dp0, dp1);
+  sincos(x, dp0, dp1);
 }
 
 // NO-MATH-ERRNO-LABEL: @sincos_f128
@@ -40,5 +54,5 @@ void sincos_f64(double x, double* dp0, double* dp1) {
 //  MATH-ERRNO:call void @sincosl(
 //
 void sincos_f128(long double x, long double* ldp0, long double* ldp1) {
-  __builtin_sincosl(x, ldp0, ldp1);
+  sincosl(x, ldp0, ldp1);
 }

>From 35de429ac0e259998121d911706454377a2d6d24 Mon Sep 17 00:00:00 2001
From: Benjamin Maxwell 
Date: Mon, 6 Jan 2025 17:06:01 +
Subject: [PATCH 2/5] Tweak tests

---
 clang/test/CodeGen/AArch64/sincos.c | 62 ++---
 1 file changed, 47 insertions(+), 15 deletions(-)

diff --git a/clang/test/CodeGen/AArch64/sincos.c 
b/clang/test/CodeGen/AArch64/sincos.c
index fde277716..736c0892ed741 100644
--- a/clang/test/CodeGen/AArch64/sincos.c
+++ b/clang/test/CodeGen/AArch64/sincos.c
@@ -1,19 +1,9 @@
-// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -O1 %s -o - 
-DUSE_BUILTIN | FileCheck --check-prefix=NO-MATH-ERRNO %s
-// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -fmath-errno %s -o - 
-DUSE_BUILTIN | FileCheck --check-prefix=MATH-ERRNO %s
-// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -O1 %s -o - 
-DUSE_C_DECL | FileCheck --check-prefix=NO-MATH-ERRNO %s
-// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -fmath-errno %s -o - 
-DUSE_C_DECL | FileCheck --check-prefix=MATH-ERRNO %s
+// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -O1 %s -o - | 
FileCheck --check-prefix=NO-MATH-ERRNO %s
+// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-ll

[clang] [clang] Lower non-builtin sincos[f|l] calls to llvm.sincos.* when -fno-math-errno is set (PR #121763)

2025-02-18 Thread Benjamin Maxwell via cfe-commits

https://github.com/MacDue updated 
https://github.com/llvm/llvm-project/pull/121763

>From 42b096396f36adc6f1ad34de263a80dd7e4e0960 Mon Sep 17 00:00:00 2001
From: Benjamin Maxwell 
Date: Mon, 6 Jan 2025 11:49:48 +
Subject: [PATCH 1/4] [clang] Lower non-builtin sincos[f|l] calls to
 llvm.sincos.* when -fno-math-errno is set

This will allow vectorizing these calls (after a few more patches). This
should not change the codegen for targets that enable the use of AA
during the codegen (in `TargetSubtargetInfo::useAA()`). This includes
targets such as AArch64. This notably does not include x86 but can be
worked around by passing `-mllvm -combiner-global-alias-analysis=true`
to clang.
---
 clang/lib/CodeGen/CGBuiltin.cpp |  3 +++
 clang/test/CodeGen/AArch64/sincos.c | 24 +++-
 2 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index d57f491a20c8e..d3f41563aed9d 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3377,6 +3377,9 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   return RValue::get(emitUnaryMaybeConstrainedFPBuiltin(
   *this, E, Intrinsic::sinh, 
Intrinsic::experimental_constrained_sinh));
 
+case Builtin::BIsincos:
+case Builtin::BIsincosf:
+case Builtin::BIsincosl:
 case Builtin::BI__builtin_sincos:
 case Builtin::BI__builtin_sincosf:
 case Builtin::BI__builtin_sincosf16:
diff --git a/clang/test/CodeGen/AArch64/sincos.c 
b/clang/test/CodeGen/AArch64/sincos.c
index b77d98ceab486..fde277716 100644
--- a/clang/test/CodeGen/AArch64/sincos.c
+++ b/clang/test/CodeGen/AArch64/sincos.c
@@ -1,5 +1,19 @@
-// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -O1 %s -o - | 
FileCheck --check-prefix=NO-MATH-ERRNO %s
-// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -fmath-errno %s -o - | 
FileCheck --check-prefix=MATH-ERRNO %s
+// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -O1 %s -o - 
-DUSE_BUILTIN | FileCheck --check-prefix=NO-MATH-ERRNO %s
+// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -fmath-errno %s -o - 
-DUSE_BUILTIN | FileCheck --check-prefix=MATH-ERRNO %s
+// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -O1 %s -o - 
-DUSE_C_DECL | FileCheck --check-prefix=NO-MATH-ERRNO %s
+// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -fmath-errno %s -o - 
-DUSE_C_DECL | FileCheck --check-prefix=MATH-ERRNO %s
+
+#if defined(USE_BUILTIN)
+  #define sincos __builtin_sincos
+  #define sincosf __builtin_sincosf
+  #define sincosl __builtin_sincosl
+#elif defined(USE_C_DECL)
+  void sincos(double, double*, double*);
+  void sincosf(float, float*, float*);
+  void sincosl(long double, long double*, long double*);
+#else
+#error Expected USE_BUILTIN or USE_C_DECL to be defined.
+#endif
 
 // NO-MATH-ERRNO-LABEL: @sincos_f32
 //  NO-MATH-ERRNO:[[SINCOS:%.*]] = tail call { float, float } 
@llvm.sincos.f32(float {{.*}})
@@ -12,7 +26,7 @@
 //  MATH-ERRNO:call void @sincosf(
 //
 void sincos_f32(float x, float* fp0, float* fp1) {
-  __builtin_sincosf(x, fp0, fp1);
+  sincosf(x, fp0, fp1);
 }
 
 // NO-MATH-ERRNO-LABEL: @sincos_f64
@@ -26,7 +40,7 @@ void sincos_f32(float x, float* fp0, float* fp1) {
 //  MATH-ERRNO:call void @sincos(
 //
 void sincos_f64(double x, double* dp0, double* dp1) {
-  __builtin_sincos(x, dp0, dp1);
+  sincos(x, dp0, dp1);
 }
 
 // NO-MATH-ERRNO-LABEL: @sincos_f128
@@ -40,5 +54,5 @@ void sincos_f64(double x, double* dp0, double* dp1) {
 //  MATH-ERRNO:call void @sincosl(
 //
 void sincos_f128(long double x, long double* ldp0, long double* ldp1) {
-  __builtin_sincosl(x, ldp0, ldp1);
+  sincosl(x, ldp0, ldp1);
 }

>From 35de429ac0e259998121d911706454377a2d6d24 Mon Sep 17 00:00:00 2001
From: Benjamin Maxwell 
Date: Mon, 6 Jan 2025 17:06:01 +
Subject: [PATCH 2/4] Tweak tests

---
 clang/test/CodeGen/AArch64/sincos.c | 62 ++---
 1 file changed, 47 insertions(+), 15 deletions(-)

diff --git a/clang/test/CodeGen/AArch64/sincos.c 
b/clang/test/CodeGen/AArch64/sincos.c
index fde277716..736c0892ed741 100644
--- a/clang/test/CodeGen/AArch64/sincos.c
+++ b/clang/test/CodeGen/AArch64/sincos.c
@@ -1,19 +1,9 @@
-// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -O1 %s -o - 
-DUSE_BUILTIN | FileCheck --check-prefix=NO-MATH-ERRNO %s
-// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -fmath-errno %s -o - 
-DUSE_BUILTIN | FileCheck --check-prefix=MATH-ERRNO %s
-// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -O1 %s -o - 
-DUSE_C_DECL | FileCheck --check-prefix=NO-MATH-ERRNO %s
-// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -fmath-errno %s -o - 
-DUSE_C_DECL | FileCheck --check-prefix=MATH-ERRNO %s
+// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -O1 %s -o - | 
FileCheck --check-prefix=NO-MATH-ERRNO %s
+// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-ll

[clang] [clang] Lower non-builtin sincos[f|l] calls to llvm.sincos.* when -fno-math-errno is set (PR #121763)

2025-02-18 Thread Matt Arsenault via cfe-commits

https://github.com/arsenm requested changes to this pull request.

I'm a hard no on making this a target dependent option. Just enable it 
unconditionally and take the regression 

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


[clang] [clang] Lower non-builtin sincos[f|l] calls to llvm.sincos.* when -fno-math-errno is set (PR #121763)

2025-02-18 Thread Benjamin Maxwell via cfe-commits

MacDue wrote:

I've pushed a change to restrict this to AArch64 (other targets could enable it 
too) given no reply above, or progress on 
https://github.com/llvm/llvm-project/pull/123787.

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


[clang] [clang] Lower non-builtin sincos[f|l] calls to llvm.sincos.* when -fno-math-errno is set (PR #121763)

2025-02-18 Thread Benjamin Maxwell via cfe-commits

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


[clang] [clang] Lower non-builtin sincos[f|l] calls to llvm.sincos.* when -fno-math-errno is set (PR #121763)

2025-02-18 Thread Benjamin Maxwell via cfe-commits

https://github.com/MacDue updated 
https://github.com/llvm/llvm-project/pull/121763

>From 42b096396f36adc6f1ad34de263a80dd7e4e0960 Mon Sep 17 00:00:00 2001
From: Benjamin Maxwell 
Date: Mon, 6 Jan 2025 11:49:48 +
Subject: [PATCH 1/3] [clang] Lower non-builtin sincos[f|l] calls to
 llvm.sincos.* when -fno-math-errno is set

This will allow vectorizing these calls (after a few more patches). This
should not change the codegen for targets that enable the use of AA
during the codegen (in `TargetSubtargetInfo::useAA()`). This includes
targets such as AArch64. This notably does not include x86 but can be
worked around by passing `-mllvm -combiner-global-alias-analysis=true`
to clang.
---
 clang/lib/CodeGen/CGBuiltin.cpp |  3 +++
 clang/test/CodeGen/AArch64/sincos.c | 24 +++-
 2 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index d57f491a20c8e..d3f41563aed9d 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3377,6 +3377,9 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   return RValue::get(emitUnaryMaybeConstrainedFPBuiltin(
   *this, E, Intrinsic::sinh, 
Intrinsic::experimental_constrained_sinh));
 
+case Builtin::BIsincos:
+case Builtin::BIsincosf:
+case Builtin::BIsincosl:
 case Builtin::BI__builtin_sincos:
 case Builtin::BI__builtin_sincosf:
 case Builtin::BI__builtin_sincosf16:
diff --git a/clang/test/CodeGen/AArch64/sincos.c 
b/clang/test/CodeGen/AArch64/sincos.c
index b77d98ceab486..fde277716 100644
--- a/clang/test/CodeGen/AArch64/sincos.c
+++ b/clang/test/CodeGen/AArch64/sincos.c
@@ -1,5 +1,19 @@
-// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -O1 %s -o - | 
FileCheck --check-prefix=NO-MATH-ERRNO %s
-// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -fmath-errno %s -o - | 
FileCheck --check-prefix=MATH-ERRNO %s
+// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -O1 %s -o - 
-DUSE_BUILTIN | FileCheck --check-prefix=NO-MATH-ERRNO %s
+// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -fmath-errno %s -o - 
-DUSE_BUILTIN | FileCheck --check-prefix=MATH-ERRNO %s
+// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -O1 %s -o - 
-DUSE_C_DECL | FileCheck --check-prefix=NO-MATH-ERRNO %s
+// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -fmath-errno %s -o - 
-DUSE_C_DECL | FileCheck --check-prefix=MATH-ERRNO %s
+
+#if defined(USE_BUILTIN)
+  #define sincos __builtin_sincos
+  #define sincosf __builtin_sincosf
+  #define sincosl __builtin_sincosl
+#elif defined(USE_C_DECL)
+  void sincos(double, double*, double*);
+  void sincosf(float, float*, float*);
+  void sincosl(long double, long double*, long double*);
+#else
+#error Expected USE_BUILTIN or USE_C_DECL to be defined.
+#endif
 
 // NO-MATH-ERRNO-LABEL: @sincos_f32
 //  NO-MATH-ERRNO:[[SINCOS:%.*]] = tail call { float, float } 
@llvm.sincos.f32(float {{.*}})
@@ -12,7 +26,7 @@
 //  MATH-ERRNO:call void @sincosf(
 //
 void sincos_f32(float x, float* fp0, float* fp1) {
-  __builtin_sincosf(x, fp0, fp1);
+  sincosf(x, fp0, fp1);
 }
 
 // NO-MATH-ERRNO-LABEL: @sincos_f64
@@ -26,7 +40,7 @@ void sincos_f32(float x, float* fp0, float* fp1) {
 //  MATH-ERRNO:call void @sincos(
 //
 void sincos_f64(double x, double* dp0, double* dp1) {
-  __builtin_sincos(x, dp0, dp1);
+  sincos(x, dp0, dp1);
 }
 
 // NO-MATH-ERRNO-LABEL: @sincos_f128
@@ -40,5 +54,5 @@ void sincos_f64(double x, double* dp0, double* dp1) {
 //  MATH-ERRNO:call void @sincosl(
 //
 void sincos_f128(long double x, long double* ldp0, long double* ldp1) {
-  __builtin_sincosl(x, ldp0, ldp1);
+  sincosl(x, ldp0, ldp1);
 }

>From 35de429ac0e259998121d911706454377a2d6d24 Mon Sep 17 00:00:00 2001
From: Benjamin Maxwell 
Date: Mon, 6 Jan 2025 17:06:01 +
Subject: [PATCH 2/3] Tweak tests

---
 clang/test/CodeGen/AArch64/sincos.c | 62 ++---
 1 file changed, 47 insertions(+), 15 deletions(-)

diff --git a/clang/test/CodeGen/AArch64/sincos.c 
b/clang/test/CodeGen/AArch64/sincos.c
index fde277716..736c0892ed741 100644
--- a/clang/test/CodeGen/AArch64/sincos.c
+++ b/clang/test/CodeGen/AArch64/sincos.c
@@ -1,19 +1,9 @@
-// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -O1 %s -o - 
-DUSE_BUILTIN | FileCheck --check-prefix=NO-MATH-ERRNO %s
-// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -fmath-errno %s -o - 
-DUSE_BUILTIN | FileCheck --check-prefix=MATH-ERRNO %s
-// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -O1 %s -o - 
-DUSE_C_DECL | FileCheck --check-prefix=NO-MATH-ERRNO %s
-// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -fmath-errno %s -o - 
-DUSE_C_DECL | FileCheck --check-prefix=MATH-ERRNO %s
+// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -O1 %s -o - | 
FileCheck --check-prefix=NO-MATH-ERRNO %s
+// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-ll

[clang] [clang] Lower non-builtin sincos[f|l] calls to llvm.sincos.* when -fno-math-errno is set (PR #121763)

2025-02-07 Thread Benjamin Maxwell via cfe-commits

MacDue wrote:

Given it looks like #123787 won't be accepted (due to compile time 
regressions), I think we should restrict this lowering to AArch64 (and other 
supported targets) until there's a solution for targets without AA in codegen 
too. Does that seem reasonable?  

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


[clang] [clang] Lower non-builtin sincos[f|l] calls to llvm.sincos.* when -fno-math-errno is set (PR #121763)

2025-01-21 Thread Chang Lin via cfe-commits

clin111 wrote:

Looks like it was never enabled --- or tested on X86 --- since UseAA was 
introduced in https://reviews.llvm.org/D67266. Eventually the dead option was 
removed with c266776. Would advise some caution with regards to register 
pressure and compile time.

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


[clang] [clang] Lower non-builtin sincos[f|l] calls to llvm.sincos.* when -fno-math-errno is set (PR #121763)

2025-01-21 Thread Benjamin Maxwell via cfe-commits

MacDue wrote:

> > > > @RKSimon do you know if there is a reason CodeGen AA is not enabled for 
> > > > x86?
> > > > I'd otherwise be happy to approve this patch, lowering to the intrinsic 
> > > > seems like the right thing to do.
> > > 
> > > 
> > > I don't remember any reason for alias analysis to not be enabled on x86 - 
> > > @phoebewang @topperc do you know?
> > 
> > 
> > I don't remember either.
> 
> Me neither. @clin111 do you happen to know it?

I've created a patch enabling it here: 
https://github.com/llvm/llvm-project/pull/123787 (maybe you'll spot why it's 
disabled there :sweat_smile:). I've updated the generated tests, and gone over 
the handwritten ones more carefully, and updated them myself.

The handwritten tests that changed were:
```
llvm/test/CodeGen/X86/cfguard-x86-vectorcall.ll
llvm/test/CodeGen/X86/fixup-bw-inst.ll
llvm/test/CodeGen/X86/misched-matrix.ll
llvm/test/CodeGen/X86/regalloc-advanced-split-cost.ll
llvm/test/CodeGen/X86/vectorcall.ll
llvm/test/CodeGen/X86/win32-eh.ll
``` 

Someone more experienced with x86(_64) should double check the changes make 
sense. I am fairly confident the underlying transforms should be correct though 
as this feature is enabled for other targets (at least AArch64, RISC-V, off the 
top of my head).

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


[clang] [clang] Lower non-builtin sincos[f|l] calls to llvm.sincos.* when -fno-math-errno is set (PR #121763)

2025-01-21 Thread Phoebe Wang via cfe-commits

phoebewang wrote:

> > > @RKSimon do you know if there is a reason CodeGen AA is not enabled for 
> > > x86?
> > > I'd otherwise be happy to approve this patch, lowering to the intrinsic 
> > > seems like the right thing to do.
> > 
> > 
> > I don't remember any reason for alias analysis to not be enabled on x86 - 
> > @phoebewang @topperc do you know?
> 
> I don't remember either.

Me neither. @clin111 do you happen to know it?

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


[clang] [clang] Lower non-builtin sincos[f|l] calls to llvm.sincos.* when -fno-math-errno is set (PR #121763)

2025-01-20 Thread Craig Topper via cfe-commits

topperc wrote:

> > @RKSimon do you know if there is a reason CodeGen AA is not enabled for x86?
> > I'd otherwise be happy to approve this patch, lowering to the intrinsic 
> > seems like the right thing to do.
> 
> I don't remember any reason for alias analysis to not be enabled on x86 - 
> @phoebewang @topperc do you know?

I don't remember either.

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


[clang] [clang] Lower non-builtin sincos[f|l] calls to llvm.sincos.* when -fno-math-errno is set (PR #121763)

2025-01-20 Thread Simon Pilgrim via cfe-commits

RKSimon wrote:

> @RKSimon do you know if there is a reason CodeGen AA is not enabled for x86?
> 
> I'd otherwise be happy to approve this patch, lowering to the intrinsic seems 
> like the right thing to do.

I don't remember any reason for alias analysis to not be enabled on x86 - 
@phoebewang @topperc do you know?

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


[clang] [clang] Lower non-builtin sincos[f|l] calls to llvm.sincos.* when -fno-math-errno is set (PR #121763)

2025-01-20 Thread Sander de Smalen via cfe-commits

https://github.com/sdesmalen-arm commented:

@RKSimon do you know if there is a reason CodeGen AA is not enabled for x86?

I'd otherwise be happy to approve this patch, lowering to the intrinsic seems 
like the right thing to do.

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


[clang] [clang] Lower non-builtin sincos[f|l] calls to llvm.sincos.* when -fno-math-errno is set (PR #121763)

2025-01-06 Thread Benjamin Maxwell via cfe-commits


@@ -1,5 +1,19 @@
-// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -O1 %s -o - | 
FileCheck --check-prefix=NO-MATH-ERRNO %s
-// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -fmath-errno %s -o - | 
FileCheck --check-prefix=MATH-ERRNO %s
+// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -O1 %s -o - 
-DUSE_BUILTIN | FileCheck --check-prefix=NO-MATH-ERRNO %s
+// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -fmath-errno %s -o - 
-DUSE_BUILTIN | FileCheck --check-prefix=MATH-ERRNO %s
+// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -O1 %s -o - 
-DUSE_C_DECL | FileCheck --check-prefix=NO-MATH-ERRNO %s
+// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -fmath-errno %s -o - 
-DUSE_C_DECL | FileCheck --check-prefix=MATH-ERRNO %s
+
+#if defined(USE_BUILTIN)

MacDue wrote:

Sure, done :+1: 

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


[clang] [clang] Lower non-builtin sincos[f|l] calls to llvm.sincos.* when -fno-math-errno is set (PR #121763)

2025-01-06 Thread Benjamin Maxwell via cfe-commits

https://github.com/MacDue updated 
https://github.com/llvm/llvm-project/pull/121763

>From 2cadacae4359f8d67bdff850738441fba455a8bc Mon Sep 17 00:00:00 2001
From: Benjamin Maxwell 
Date: Mon, 6 Jan 2025 11:49:48 +
Subject: [PATCH 1/2] [clang] Lower non-builtin sincos[f|l] calls to
 llvm.sincos.* when -fno-math-errno is set

This will allow vectorizing these calls (after a few more patches). This
should not change the codegen for targets that enable the use of AA
during the codegen (in `TargetSubtargetInfo::useAA()`). This includes
targets such as AArch64. This notably does not include x86 but can be
worked around by passing `-mllvm -combiner-global-alias-analysis=true`
to clang.
---
 clang/lib/CodeGen/CGBuiltin.cpp |  3 +++
 clang/test/CodeGen/AArch64/sincos.c | 24 +++-
 2 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index c419fb0cc055e0..9a859e7a22f5e3 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3264,6 +3264,9 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   return RValue::get(emitUnaryMaybeConstrainedFPBuiltin(
   *this, E, Intrinsic::sinh, 
Intrinsic::experimental_constrained_sinh));
 
+case Builtin::BIsincos:
+case Builtin::BIsincosf:
+case Builtin::BIsincosl:
 case Builtin::BI__builtin_sincos:
 case Builtin::BI__builtin_sincosf:
 case Builtin::BI__builtin_sincosf16:
diff --git a/clang/test/CodeGen/AArch64/sincos.c 
b/clang/test/CodeGen/AArch64/sincos.c
index b77d98ceab4869..fde277716b 100644
--- a/clang/test/CodeGen/AArch64/sincos.c
+++ b/clang/test/CodeGen/AArch64/sincos.c
@@ -1,5 +1,19 @@
-// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -O1 %s -o - | 
FileCheck --check-prefix=NO-MATH-ERRNO %s
-// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -fmath-errno %s -o - | 
FileCheck --check-prefix=MATH-ERRNO %s
+// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -O1 %s -o - 
-DUSE_BUILTIN | FileCheck --check-prefix=NO-MATH-ERRNO %s
+// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -fmath-errno %s -o - 
-DUSE_BUILTIN | FileCheck --check-prefix=MATH-ERRNO %s
+// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -O1 %s -o - 
-DUSE_C_DECL | FileCheck --check-prefix=NO-MATH-ERRNO %s
+// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -fmath-errno %s -o - 
-DUSE_C_DECL | FileCheck --check-prefix=MATH-ERRNO %s
+
+#if defined(USE_BUILTIN)
+  #define sincos __builtin_sincos
+  #define sincosf __builtin_sincosf
+  #define sincosl __builtin_sincosl
+#elif defined(USE_C_DECL)
+  void sincos(double, double*, double*);
+  void sincosf(float, float*, float*);
+  void sincosl(long double, long double*, long double*);
+#else
+#error Expected USE_BUILTIN or USE_C_DECL to be defined.
+#endif
 
 // NO-MATH-ERRNO-LABEL: @sincos_f32
 //  NO-MATH-ERRNO:[[SINCOS:%.*]] = tail call { float, float } 
@llvm.sincos.f32(float {{.*}})
@@ -12,7 +26,7 @@
 //  MATH-ERRNO:call void @sincosf(
 //
 void sincos_f32(float x, float* fp0, float* fp1) {
-  __builtin_sincosf(x, fp0, fp1);
+  sincosf(x, fp0, fp1);
 }
 
 // NO-MATH-ERRNO-LABEL: @sincos_f64
@@ -26,7 +40,7 @@ void sincos_f32(float x, float* fp0, float* fp1) {
 //  MATH-ERRNO:call void @sincos(
 //
 void sincos_f64(double x, double* dp0, double* dp1) {
-  __builtin_sincos(x, dp0, dp1);
+  sincos(x, dp0, dp1);
 }
 
 // NO-MATH-ERRNO-LABEL: @sincos_f128
@@ -40,5 +54,5 @@ void sincos_f64(double x, double* dp0, double* dp1) {
 //  MATH-ERRNO:call void @sincosl(
 //
 void sincos_f128(long double x, long double* ldp0, long double* ldp1) {
-  __builtin_sincosl(x, ldp0, ldp1);
+  sincosl(x, ldp0, ldp1);
 }

>From 46aa023e76f9cd86f6753fb306f6e26a95c98357 Mon Sep 17 00:00:00 2001
From: Benjamin Maxwell 
Date: Mon, 6 Jan 2025 17:06:01 +
Subject: [PATCH 2/2] Tweak tests

---
 clang/test/CodeGen/AArch64/sincos.c | 62 ++---
 1 file changed, 47 insertions(+), 15 deletions(-)

diff --git a/clang/test/CodeGen/AArch64/sincos.c 
b/clang/test/CodeGen/AArch64/sincos.c
index fde277716b..736c0892ed7418 100644
--- a/clang/test/CodeGen/AArch64/sincos.c
+++ b/clang/test/CodeGen/AArch64/sincos.c
@@ -1,19 +1,9 @@
-// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -O1 %s -o - 
-DUSE_BUILTIN | FileCheck --check-prefix=NO-MATH-ERRNO %s
-// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -fmath-errno %s -o - 
-DUSE_BUILTIN | FileCheck --check-prefix=MATH-ERRNO %s
-// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -O1 %s -o - 
-DUSE_C_DECL | FileCheck --check-prefix=NO-MATH-ERRNO %s
-// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -fmath-errno %s -o - 
-DUSE_C_DECL | FileCheck --check-prefix=MATH-ERRNO %s
+// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -O1 %s -o - | 
FileCheck --check-prefix=NO-MATH-ERRNO %s
+// RUN: %clang_cc1 -triple=aarch64-gnu-linux -e

[clang] [clang] Lower non-builtin sincos[f|l] calls to llvm.sincos.* when -fno-math-errno is set (PR #121763)

2025-01-06 Thread Matt Arsenault via cfe-commits


@@ -1,5 +1,19 @@
-// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -O1 %s -o - | 
FileCheck --check-prefix=NO-MATH-ERRNO %s
-// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -fmath-errno %s -o - | 
FileCheck --check-prefix=MATH-ERRNO %s
+// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -O1 %s -o - 
-DUSE_BUILTIN | FileCheck --check-prefix=NO-MATH-ERRNO %s
+// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -fmath-errno %s -o - 
-DUSE_BUILTIN | FileCheck --check-prefix=MATH-ERRNO %s
+// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -O1 %s -o - 
-DUSE_C_DECL | FileCheck --check-prefix=NO-MATH-ERRNO %s
+// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -fmath-errno %s -o - 
-DUSE_C_DECL | FileCheck --check-prefix=MATH-ERRNO %s
+
+#if defined(USE_BUILTIN)

arsenm wrote:

Can you just duplicate the test functions into builtin and non-builtin forms? 
This is much harder to follow 

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


[clang] [clang] Lower non-builtin sincos[f|l] calls to llvm.sincos.* when -fno-math-errno is set (PR #121763)

2025-01-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Benjamin Maxwell (MacDue)


Changes

This will allow vectorizing these calls (after a few more patches). This should 
not change the codegen for targets that enable the use of AA during the codegen 
(in `TargetSubtargetInfo::useAA()`). This includes targets such as AArch64. 
This notably does not include x86 but can be worked around by passing `-mllvm 
-combiner-global-alias-analysis=true` to clang.

Follow up to #114086.

---
Full diff: https://github.com/llvm/llvm-project/pull/121763.diff


2 Files Affected:

- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+3) 
- (modified) clang/test/CodeGen/AArch64/sincos.c (+19-5) 


``diff
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index c419fb0cc055e0..9a859e7a22f5e3 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3264,6 +3264,9 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   return RValue::get(emitUnaryMaybeConstrainedFPBuiltin(
   *this, E, Intrinsic::sinh, 
Intrinsic::experimental_constrained_sinh));
 
+case Builtin::BIsincos:
+case Builtin::BIsincosf:
+case Builtin::BIsincosl:
 case Builtin::BI__builtin_sincos:
 case Builtin::BI__builtin_sincosf:
 case Builtin::BI__builtin_sincosf16:
diff --git a/clang/test/CodeGen/AArch64/sincos.c 
b/clang/test/CodeGen/AArch64/sincos.c
index b77d98ceab4869..fde277716b 100644
--- a/clang/test/CodeGen/AArch64/sincos.c
+++ b/clang/test/CodeGen/AArch64/sincos.c
@@ -1,5 +1,19 @@
-// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -O1 %s -o - | 
FileCheck --check-prefix=NO-MATH-ERRNO %s
-// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -fmath-errno %s -o - | 
FileCheck --check-prefix=MATH-ERRNO %s
+// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -O1 %s -o - 
-DUSE_BUILTIN | FileCheck --check-prefix=NO-MATH-ERRNO %s
+// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -fmath-errno %s -o - 
-DUSE_BUILTIN | FileCheck --check-prefix=MATH-ERRNO %s
+// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -O1 %s -o - 
-DUSE_C_DECL | FileCheck --check-prefix=NO-MATH-ERRNO %s
+// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -fmath-errno %s -o - 
-DUSE_C_DECL | FileCheck --check-prefix=MATH-ERRNO %s
+
+#if defined(USE_BUILTIN)
+  #define sincos __builtin_sincos
+  #define sincosf __builtin_sincosf
+  #define sincosl __builtin_sincosl
+#elif defined(USE_C_DECL)
+  void sincos(double, double*, double*);
+  void sincosf(float, float*, float*);
+  void sincosl(long double, long double*, long double*);
+#else
+#error Expected USE_BUILTIN or USE_C_DECL to be defined.
+#endif
 
 // NO-MATH-ERRNO-LABEL: @sincos_f32
 //  NO-MATH-ERRNO:[[SINCOS:%.*]] = tail call { float, float } 
@llvm.sincos.f32(float {{.*}})
@@ -12,7 +26,7 @@
 //  MATH-ERRNO:call void @sincosf(
 //
 void sincos_f32(float x, float* fp0, float* fp1) {
-  __builtin_sincosf(x, fp0, fp1);
+  sincosf(x, fp0, fp1);
 }
 
 // NO-MATH-ERRNO-LABEL: @sincos_f64
@@ -26,7 +40,7 @@ void sincos_f32(float x, float* fp0, float* fp1) {
 //  MATH-ERRNO:call void @sincos(
 //
 void sincos_f64(double x, double* dp0, double* dp1) {
-  __builtin_sincos(x, dp0, dp1);
+  sincos(x, dp0, dp1);
 }
 
 // NO-MATH-ERRNO-LABEL: @sincos_f128
@@ -40,5 +54,5 @@ void sincos_f64(double x, double* dp0, double* dp1) {
 //  MATH-ERRNO:call void @sincosl(
 //
 void sincos_f128(long double x, long double* ldp0, long double* ldp1) {
-  __builtin_sincosl(x, ldp0, ldp1);
+  sincosl(x, ldp0, ldp1);
 }

``




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


[clang] [clang] Lower non-builtin sincos[f|l] calls to llvm.sincos.* when -fno-math-errno is set (PR #121763)

2025-01-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Benjamin Maxwell (MacDue)


Changes

This will allow vectorizing these calls (after a few more patches). This should 
not change the codegen for targets that enable the use of AA during the codegen 
(in `TargetSubtargetInfo::useAA()`). This includes targets such as AArch64. 
This notably does not include x86 but can be worked around by passing `-mllvm 
-combiner-global-alias-analysis=true` to clang.

Follow up to #114086.

---
Full diff: https://github.com/llvm/llvm-project/pull/121763.diff


2 Files Affected:

- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+3) 
- (modified) clang/test/CodeGen/AArch64/sincos.c (+19-5) 


``diff
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index c419fb0cc055e0..9a859e7a22f5e3 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3264,6 +3264,9 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   return RValue::get(emitUnaryMaybeConstrainedFPBuiltin(
   *this, E, Intrinsic::sinh, 
Intrinsic::experimental_constrained_sinh));
 
+case Builtin::BIsincos:
+case Builtin::BIsincosf:
+case Builtin::BIsincosl:
 case Builtin::BI__builtin_sincos:
 case Builtin::BI__builtin_sincosf:
 case Builtin::BI__builtin_sincosf16:
diff --git a/clang/test/CodeGen/AArch64/sincos.c 
b/clang/test/CodeGen/AArch64/sincos.c
index b77d98ceab4869..fde277716b 100644
--- a/clang/test/CodeGen/AArch64/sincos.c
+++ b/clang/test/CodeGen/AArch64/sincos.c
@@ -1,5 +1,19 @@
-// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -O1 %s -o - | 
FileCheck --check-prefix=NO-MATH-ERRNO %s
-// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -fmath-errno %s -o - | 
FileCheck --check-prefix=MATH-ERRNO %s
+// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -O1 %s -o - 
-DUSE_BUILTIN | FileCheck --check-prefix=NO-MATH-ERRNO %s
+// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -fmath-errno %s -o - 
-DUSE_BUILTIN | FileCheck --check-prefix=MATH-ERRNO %s
+// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -O1 %s -o - 
-DUSE_C_DECL | FileCheck --check-prefix=NO-MATH-ERRNO %s
+// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -fmath-errno %s -o - 
-DUSE_C_DECL | FileCheck --check-prefix=MATH-ERRNO %s
+
+#if defined(USE_BUILTIN)
+  #define sincos __builtin_sincos
+  #define sincosf __builtin_sincosf
+  #define sincosl __builtin_sincosl
+#elif defined(USE_C_DECL)
+  void sincos(double, double*, double*);
+  void sincosf(float, float*, float*);
+  void sincosl(long double, long double*, long double*);
+#else
+#error Expected USE_BUILTIN or USE_C_DECL to be defined.
+#endif
 
 // NO-MATH-ERRNO-LABEL: @sincos_f32
 //  NO-MATH-ERRNO:[[SINCOS:%.*]] = tail call { float, float } 
@llvm.sincos.f32(float {{.*}})
@@ -12,7 +26,7 @@
 //  MATH-ERRNO:call void @sincosf(
 //
 void sincos_f32(float x, float* fp0, float* fp1) {
-  __builtin_sincosf(x, fp0, fp1);
+  sincosf(x, fp0, fp1);
 }
 
 // NO-MATH-ERRNO-LABEL: @sincos_f64
@@ -26,7 +40,7 @@ void sincos_f32(float x, float* fp0, float* fp1) {
 //  MATH-ERRNO:call void @sincos(
 //
 void sincos_f64(double x, double* dp0, double* dp1) {
-  __builtin_sincos(x, dp0, dp1);
+  sincos(x, dp0, dp1);
 }
 
 // NO-MATH-ERRNO-LABEL: @sincos_f128
@@ -40,5 +54,5 @@ void sincos_f64(double x, double* dp0, double* dp1) {
 //  MATH-ERRNO:call void @sincosl(
 //
 void sincos_f128(long double x, long double* ldp0, long double* ldp1) {
-  __builtin_sincosl(x, ldp0, ldp1);
+  sincosl(x, ldp0, ldp1);
 }

``




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


[clang] [clang] Lower non-builtin sincos[f|l] calls to llvm.sincos.* when -fno-math-errno is set (PR #121763)

2025-01-06 Thread Benjamin Maxwell via cfe-commits

https://github.com/MacDue created 
https://github.com/llvm/llvm-project/pull/121763

This will allow vectorizing these calls (after a few more patches). This should 
not change the codegen for targets that enable the use of AA during the codegen 
(in `TargetSubtargetInfo::useAA()`). This includes targets such as AArch64. 
This notably does not include x86 but can be worked around by passing `-mllvm 
-combiner-global-alias-analysis=true` to clang.

Follow up to #114086.

>From 2cadacae4359f8d67bdff850738441fba455a8bc Mon Sep 17 00:00:00 2001
From: Benjamin Maxwell 
Date: Mon, 6 Jan 2025 11:49:48 +
Subject: [PATCH] [clang] Lower non-builtin sincos[f|l] calls to llvm.sincos.*
 when -fno-math-errno is set

This will allow vectorizing these calls (after a few more patches). This
should not change the codegen for targets that enable the use of AA
during the codegen (in `TargetSubtargetInfo::useAA()`). This includes
targets such as AArch64. This notably does not include x86 but can be
worked around by passing `-mllvm -combiner-global-alias-analysis=true`
to clang.
---
 clang/lib/CodeGen/CGBuiltin.cpp |  3 +++
 clang/test/CodeGen/AArch64/sincos.c | 24 +++-
 2 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index c419fb0cc055e0..9a859e7a22f5e3 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3264,6 +3264,9 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   return RValue::get(emitUnaryMaybeConstrainedFPBuiltin(
   *this, E, Intrinsic::sinh, 
Intrinsic::experimental_constrained_sinh));
 
+case Builtin::BIsincos:
+case Builtin::BIsincosf:
+case Builtin::BIsincosl:
 case Builtin::BI__builtin_sincos:
 case Builtin::BI__builtin_sincosf:
 case Builtin::BI__builtin_sincosf16:
diff --git a/clang/test/CodeGen/AArch64/sincos.c 
b/clang/test/CodeGen/AArch64/sincos.c
index b77d98ceab4869..fde277716b 100644
--- a/clang/test/CodeGen/AArch64/sincos.c
+++ b/clang/test/CodeGen/AArch64/sincos.c
@@ -1,5 +1,19 @@
-// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -O1 %s -o - | 
FileCheck --check-prefix=NO-MATH-ERRNO %s
-// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -fmath-errno %s -o - | 
FileCheck --check-prefix=MATH-ERRNO %s
+// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -O1 %s -o - 
-DUSE_BUILTIN | FileCheck --check-prefix=NO-MATH-ERRNO %s
+// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -fmath-errno %s -o - 
-DUSE_BUILTIN | FileCheck --check-prefix=MATH-ERRNO %s
+// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -O1 %s -o - 
-DUSE_C_DECL | FileCheck --check-prefix=NO-MATH-ERRNO %s
+// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -fmath-errno %s -o - 
-DUSE_C_DECL | FileCheck --check-prefix=MATH-ERRNO %s
+
+#if defined(USE_BUILTIN)
+  #define sincos __builtin_sincos
+  #define sincosf __builtin_sincosf
+  #define sincosl __builtin_sincosl
+#elif defined(USE_C_DECL)
+  void sincos(double, double*, double*);
+  void sincosf(float, float*, float*);
+  void sincosl(long double, long double*, long double*);
+#else
+#error Expected USE_BUILTIN or USE_C_DECL to be defined.
+#endif
 
 // NO-MATH-ERRNO-LABEL: @sincos_f32
 //  NO-MATH-ERRNO:[[SINCOS:%.*]] = tail call { float, float } 
@llvm.sincos.f32(float {{.*}})
@@ -12,7 +26,7 @@
 //  MATH-ERRNO:call void @sincosf(
 //
 void sincos_f32(float x, float* fp0, float* fp1) {
-  __builtin_sincosf(x, fp0, fp1);
+  sincosf(x, fp0, fp1);
 }
 
 // NO-MATH-ERRNO-LABEL: @sincos_f64
@@ -26,7 +40,7 @@ void sincos_f32(float x, float* fp0, float* fp1) {
 //  MATH-ERRNO:call void @sincos(
 //
 void sincos_f64(double x, double* dp0, double* dp1) {
-  __builtin_sincos(x, dp0, dp1);
+  sincos(x, dp0, dp1);
 }
 
 // NO-MATH-ERRNO-LABEL: @sincos_f128
@@ -40,5 +54,5 @@ void sincos_f64(double x, double* dp0, double* dp1) {
 //  MATH-ERRNO:call void @sincosl(
 //
 void sincos_f128(long double x, long double* ldp0, long double* ldp1) {
-  __builtin_sincosl(x, ldp0, ldp1);
+  sincosl(x, ldp0, ldp1);
 }

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