[clang] [Clang][LoongArch] Comply with the lp64d ABI to pass vector arguments (PR #74990)

2023-12-10 Thread Lu Weining via cfe-commits

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


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


[clang] [Driver] Support -mcmodel= for LoongArch (PR #72514)

2023-11-16 Thread Lu Weining via cfe-commits

https://github.com/SixWeining created 
https://github.com/llvm/llvm-project/pull/72514

7e42545 rejects unsupported mcmodel options, but small/medium/large should be 
supported models for LoongArch. In addition, to be compatible with gcc, mapping 
some of their values to clang's.

The mapping is:
```
 gcc  vs clang
   "normal""small"
   "medium""medium"
   "extreme"   "large"
```

And AFAIK, gcc side doesn't plan to implement the "large" code model.

Link: https://gcc.gnu.org/onlinedocs/gcc/LoongArch-Options.html
Link: https://reviews.llvm.org/D150522

>From 8dd5bebcd4681e5e7849743aba0ce90c2959ee23 Mon Sep 17 00:00:00 2001
From: Weining Lu 
Date: Thu, 16 Nov 2023 21:57:03 +0800
Subject: [PATCH] [Driver] Support -mcmodel= for LoongArch

7e42545 rejects unsupported mcmodel options, but small/medium/large
should be supported models for LoongArch. In addition, to be compatible
with gcc, mapping some of their values to clang's.

The mapping is:
 gcc[1] vs clang[2]
   "normal""small"
   "medium""medium"
   "extreme"   "large"

And AFAIK, gcc side doesn't plan to implement the "large" code model.

[1]: https://gcc.gnu.org/onlinedocs/gcc/LoongArch-Options.html
[2]: https://reviews.llvm.org/D150522
---
 clang/lib/Driver/ToolChains/Clang.cpp | 10 ++
 clang/test/Driver/mcmodel.c   | 13 +
 2 files changed, 23 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index b462f5a44057d94..3a7e56f37259cb8 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5739,6 +5739,16 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
   if (CM == "large" && RelocationModel != llvm::Reloc::Static)
 D.Diag(diag::err_drv_argument_only_allowed_with)
 << A->getAsString(Args) << "-fno-pic";
+} else if (Triple.isLoongArch()) {
+  CM = llvm::StringSwitch(CM)
+   .Case("normal", "small")
+   .Case("extreme", "large")
+   .Default(CM);
+  if (CM == "large" &&
+  Args.hasFlag(options::OPT_fplt, options::OPT_fno_plt, false))
+D.Diag(diag::err_drv_argument_not_allowed_with)
+<< A->getAsString(Args) << "-fplt";
+  Ok = CM == "small" || CM == "medium" || CM == "large";
 } else if (Triple.isPPC64() || Triple.isOSAIX()) {
   Ok = CM == "small" || CM == "medium" || CM == "large";
 } else if (Triple.isRISCV()) {
diff --git a/clang/test/Driver/mcmodel.c b/clang/test/Driver/mcmodel.c
index d8a41b0f5abd9aa..72be740216a81b3 100644
--- a/clang/test/Driver/mcmodel.c
+++ b/clang/test/Driver/mcmodel.c
@@ -15,6 +15,15 @@
 // RUN: not %clang -### -c --target=aarch64 -mcmodel=medium %s 2>&1 | 
FileCheck --check-prefix=ERR-MEDIUM %s
 // RUN: not %clang -### -c --target=aarch64 -mcmodel=kernel %s 2>&1 | 
FileCheck --check-prefix=ERR-KERNEL %s
 // RUN: not %clang --target=aarch64_32-linux -### -S -mcmodel=small %s 2>&1 | 
FileCheck --check-prefix=ERR-AARCH64_32 %s
+// RUN: %clang --target=loongarch64 -### -S -mcmodel=small %s 2>&1 | FileCheck 
--check-prefix=SMALL %s
+// RUN: %clang --target=loongarch64 -### -S -mcmodel=normal %s 2>&1 | 
FileCheck --check-prefix=SMALL %s
+// RUN: %clang --target=loongarch64 -### -S -mcmodel=medium %s 2>&1 | 
FileCheck --check-prefix=MEDIUM %s
+// RUN: %clang --target=loongarch64 -### -S -mcmodel=large %s 2>&1 | FileCheck 
--check-prefix=LARGE %s
+// RUN: %clang --target=loongarch64 -### -S -mcmodel=extreme %s 2>&1 | 
FileCheck --check-prefix=LARGE %s
+// RUN: not %clang --target=loongarch64 -### -S -mcmodel=tiny %s 2>&1 | 
FileCheck --check-prefix=ERR-TINY %s
+// RUN: not %clang --target=loongarch64 -### -S -mcmodel=kernel %s 2>&1 | 
FileCheck --check-prefix=ERR-KERNEL %s
+// RUN: not %clang --target=loongarch64 -### -S -mcmodel=large -fplt %s 2>&1 | 
FileCheck --check-prefix=ERR-LOONGARCH64-PLT-LARGE %s
+// RUN: not %clang --target=loongarch64 -### -S -mcmodel=extreme -fplt %s 2>&1 
| FileCheck --check-prefix=ERR-LOONGARCH64-PLT-EXTREME %s
 
 // TINY: "-mcmodel=tiny"
 // SMALL: "-mcmodel=small"
@@ -25,9 +34,13 @@
 
 // INVALID: error: unsupported argument 'lager' to option '-mcmodel=' for 
target '{{.*}}'
 
+// ERR-TINY: error: unsupported argument 'tiny' to option '-mcmodel=' for 
target '{{.*}}'
 // ERR-MEDIUM: error: unsupported argument 'medium' to option '-mcmodel=' for 
target '{{.*}}'
 // ERR-KERNEL: error: unsupported argument 'kernel' to option '-mcmodel=' for 
target '{{.*}}'
 // ERR-LARGE:  error: unsupported argument 'large' to option '-mcmodel=' for 
target '{{.*}}'
 
 // AARCH64-PIC-LARGE: error: invalid argument '-mcmodel=large' only allowed 
with '-fno-pic'
 // ERR-AARCH64_32: error: unsupported argument 'small' to option '-mcmodel=' 
for target 'aarch64_32-unknown-linux'
+
+// ERR-LOONGARCH64-PLT-LARGE: error: invalid argument '-mcmodel=large' not 
allowed with '-fplt'
+

[clang] [Driver] Support -mcmodel= for LoongArch (PR #72514)

2023-11-16 Thread Lu Weining via cfe-commits

SixWeining wrote:

cc @xen0n @xry111 

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


[clang] [Driver] Support -mcmodel= for LoongArch (PR #72514)

2023-11-16 Thread Lu Weining via cfe-commits

SixWeining wrote:

> > And AFAIK, gcc side doesn't plan to implement the "large" code model.
> 
> Why did we distinguish "large" and "extreme" in the first place? If we don't 
> need a different "large" code model then I guess we should make it an alias 
> of "extreme" for GCC too.

@ChenghuaXu @chenglulu326 What do you think?

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


[llvm] [clang-tools-extra] [clang] [Clang][LoongArch] Support builtin functions for LSX and LASX (PR #69313)

2023-10-30 Thread Lu Weining via cfe-commits

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

LGTM.

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


[clang] [clang-tools-extra] [llvm] [Clang][LoongArch] Support builtin functions for LSX and LASX (PR #69313)

2023-10-31 Thread Lu Weining via cfe-commits

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


[clang] [llvm] [clang-tools-extra] [Clang][LoongArch] Support builtin functions for LSX and LASX (PR #69313)

2023-10-31 Thread Lu Weining via cfe-commits

SixWeining wrote:

To keep original 6 commits I have manually merged into trunk. Now close this PR.

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


[clang] [LoongArch] Fix ABI mismatch with gcc/g++ about empty structs passing (PR #70320)

2023-10-31 Thread Lu Weining via cfe-commits

SixWeining wrote:

> LGTM. I've no permission to make a formal ("GitHub style") approval.

Thanks. You can request to join the llvm organization via 
https://llvm.org/docs/DeveloperPolicy.html#obtaining-commit-access firstly. 
Then you can make formal ("Github style") approval.

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


[clang] [LoongArch] Fix ABI mismatch with gcc/g++ about empty structs passing (PR #70320)

2023-10-31 Thread Lu Weining via cfe-commits

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


[clang] [LoongArch] Fix ABI mismatch with g++ when handling empty unions (PR #71025)

2023-11-01 Thread Lu Weining via cfe-commits

https://github.com/SixWeining created 
https://github.com/llvm/llvm-project/pull/71025

In g++, empty unions are not ignored like empty structs when flattening structs 
to examine whether the structs can be passed via FARs in C++. This patch aligns 
clang++ with g++.

Fix https://github.com/llvm/llvm-project/issues/70890.

>From 6ead0f23b5f3f3bfba7446bc4bf723d8020700e7 Mon Sep 17 00:00:00 2001
From: Weining Lu 
Date: Thu, 2 Nov 2023 11:13:29 +0800
Subject: [PATCH] [LoongArch] Fix ABI mismatch with g++ when handling empty
 unions

In g++, empty unions are not ignored like empty structs when flattening
structs to examine whether the structs can be passed via FARs in C++.
This patch aligns clang++ with g++.

Fix https://github.com/llvm/llvm-project/issues/70890.
---
 clang/lib/CodeGen/Targets/LoongArch.cpp| 7 ---
 clang/test/CodeGen/LoongArch/abi-lp64d-empty-structs.c | 2 +-
 clang/test/CodeGen/LoongArch/abi-lp64d-empty-unions.c  | 3 +--
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/clang/lib/CodeGen/Targets/LoongArch.cpp 
b/clang/lib/CodeGen/Targets/LoongArch.cpp
index c4d886eb40725f8..7b2c31139b0b2a3 100644
--- a/clang/lib/CodeGen/Targets/LoongArch.cpp
+++ b/clang/lib/CodeGen/Targets/LoongArch.cpp
@@ -170,10 +170,11 @@ bool LoongArchABIInfo::detectFARsEligibleStructHelper(
 // copy constructor are not eligible for the FP calling convention.
 if (getRecordArgABI(Ty, CGT.getCXXABI()))
   return false;
-if (isEmptyRecord(getContext(), Ty, true, true))
-  return true;
 const RecordDecl *RD = RTy->getDecl();
-// Unions aren't eligible unless they're empty (which is caught above).
+if (isEmptyRecord(getContext(), Ty, true, true) &&
+(!RD->isUnion() || !isa(RD)))
+  return true;
+// Unions aren't eligible unless they're empty in C (which is caught 
above).
 if (RD->isUnion())
   return false;
 const ASTRecordLayout &Layout = getContext().getASTRecordLayout(RD);
diff --git a/clang/test/CodeGen/LoongArch/abi-lp64d-empty-structs.c 
b/clang/test/CodeGen/LoongArch/abi-lp64d-empty-structs.c
index 281b7b15841a999..2f7596f0ebdc8be 100644
--- a/clang/test/CodeGen/LoongArch/abi-lp64d-empty-structs.c
+++ b/clang/test/CodeGen/LoongArch/abi-lp64d-empty-structs.c
@@ -3,7 +3,7 @@
 // RUN: %clang_cc1 -triple loongarch64 -target-feature +f -target-feature +d 
-target-abi lp64d -emit-llvm %s -o - -x c++ | \
 // RUN:   FileCheck --check-prefix=CHECK-CXX %s
 
-// Fields containing empty structs or unions are ignored when flattening
+// Fields containing empty structs are ignored when flattening
 // structs to examine whether the structs can be passed via FARs, even in C++.
 // But there is an exception that non-zero-length array of empty structures are
 // not ignored in C++. These rules are not documented in psABI 

diff --git a/clang/test/CodeGen/LoongArch/abi-lp64d-empty-unions.c 
b/clang/test/CodeGen/LoongArch/abi-lp64d-empty-unions.c
index b0607425336e285..363e37efb64691e 100644
--- a/clang/test/CodeGen/LoongArch/abi-lp64d-empty-unions.c
+++ b/clang/test/CodeGen/LoongArch/abi-lp64d-empty-unions.c
@@ -19,8 +19,7 @@ struct s1 {
 };
 
 // CHECK-C: define{{.*}} { i32, float } @test2(i32{{[^,]*}}, float{{[^,]*}})
-/// FIXME: This doesn't match g++.
-// CHECK-CXX: define{{.*}} { i32, float } @_Z5test22s1(i32{{[^,]*}}, 
float{{[^,]*}})
+// CHECK-CXX: define{{.*}} [2 x i64] @_Z5test22s1([2 x i64]{{[^,]*}})
 struct s1 test2(struct s1 a) {
   return a;
 }

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


[clang] [LoongArch] Fix ABI mismatch with g++ when handling empty unions (PR #71025)

2023-11-01 Thread Lu Weining via cfe-commits

SixWeining wrote:

Hi @xen0n @xry111, please help to review this. Thanks.

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


[clang] [LoongArch] Fix ABI mismatch with g++ when handling empty unions (PR #71025)

2023-11-03 Thread Lu Weining via cfe-commits

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


[clang] [Driver] Support -mcmodel= for LoongArch (PR #72514)

2023-11-23 Thread Lu Weining via cfe-commits

SixWeining wrote:

> [gcc.gnu.org/onlinedocs/gcc/LoongArch-Options.html](https://gcc.gnu.org/onlinedocs/gcc/LoongArch-Options.html)
>  says
> 
> ‘large (Not implemented yet)’ ‘extreme’ This mode does not limit the size of 
> the code segment and data segment. The -mcmodel=extreme option is 
> incompatible with -fplt, and it requires -mexplicit-relocs=always.
> 
> Is there a psABI defining 'extreme' or 'large'?

Currently there is no definition in psABI except in gcc doc: 
https://gcc.gnu.org/onlinedocs/gcc/LoongArch-Options.html. Maybe we can define 
them in next psABI version.

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


[clang] [Driver] Support -mcmodel= for LoongArch (PR #72514)

2023-11-23 Thread Lu Weining via cfe-commits

https://github.com/SixWeining updated 
https://github.com/llvm/llvm-project/pull/72514

>From 8dd5bebcd4681e5e7849743aba0ce90c2959ee23 Mon Sep 17 00:00:00 2001
From: Weining Lu 
Date: Thu, 16 Nov 2023 21:57:03 +0800
Subject: [PATCH 1/2] [Driver] Support -mcmodel= for LoongArch

7e42545 rejects unsupported mcmodel options, but small/medium/large
should be supported models for LoongArch. In addition, to be compatible
with gcc, mapping some of their values to clang's.

The mapping is:
 gcc[1] vs clang[2]
   "normal""small"
   "medium""medium"
   "extreme"   "large"

And AFAIK, gcc side doesn't plan to implement the "large" code model.

[1]: https://gcc.gnu.org/onlinedocs/gcc/LoongArch-Options.html
[2]: https://reviews.llvm.org/D150522
---
 clang/lib/Driver/ToolChains/Clang.cpp | 10 ++
 clang/test/Driver/mcmodel.c   | 13 +
 2 files changed, 23 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index b462f5a44057d94..3a7e56f37259cb8 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5739,6 +5739,16 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
   if (CM == "large" && RelocationModel != llvm::Reloc::Static)
 D.Diag(diag::err_drv_argument_only_allowed_with)
 << A->getAsString(Args) << "-fno-pic";
+} else if (Triple.isLoongArch()) {
+  CM = llvm::StringSwitch(CM)
+   .Case("normal", "small")
+   .Case("extreme", "large")
+   .Default(CM);
+  if (CM == "large" &&
+  Args.hasFlag(options::OPT_fplt, options::OPT_fno_plt, false))
+D.Diag(diag::err_drv_argument_not_allowed_with)
+<< A->getAsString(Args) << "-fplt";
+  Ok = CM == "small" || CM == "medium" || CM == "large";
 } else if (Triple.isPPC64() || Triple.isOSAIX()) {
   Ok = CM == "small" || CM == "medium" || CM == "large";
 } else if (Triple.isRISCV()) {
diff --git a/clang/test/Driver/mcmodel.c b/clang/test/Driver/mcmodel.c
index d8a41b0f5abd9aa..72be740216a81b3 100644
--- a/clang/test/Driver/mcmodel.c
+++ b/clang/test/Driver/mcmodel.c
@@ -15,6 +15,15 @@
 // RUN: not %clang -### -c --target=aarch64 -mcmodel=medium %s 2>&1 | 
FileCheck --check-prefix=ERR-MEDIUM %s
 // RUN: not %clang -### -c --target=aarch64 -mcmodel=kernel %s 2>&1 | 
FileCheck --check-prefix=ERR-KERNEL %s
 // RUN: not %clang --target=aarch64_32-linux -### -S -mcmodel=small %s 2>&1 | 
FileCheck --check-prefix=ERR-AARCH64_32 %s
+// RUN: %clang --target=loongarch64 -### -S -mcmodel=small %s 2>&1 | FileCheck 
--check-prefix=SMALL %s
+// RUN: %clang --target=loongarch64 -### -S -mcmodel=normal %s 2>&1 | 
FileCheck --check-prefix=SMALL %s
+// RUN: %clang --target=loongarch64 -### -S -mcmodel=medium %s 2>&1 | 
FileCheck --check-prefix=MEDIUM %s
+// RUN: %clang --target=loongarch64 -### -S -mcmodel=large %s 2>&1 | FileCheck 
--check-prefix=LARGE %s
+// RUN: %clang --target=loongarch64 -### -S -mcmodel=extreme %s 2>&1 | 
FileCheck --check-prefix=LARGE %s
+// RUN: not %clang --target=loongarch64 -### -S -mcmodel=tiny %s 2>&1 | 
FileCheck --check-prefix=ERR-TINY %s
+// RUN: not %clang --target=loongarch64 -### -S -mcmodel=kernel %s 2>&1 | 
FileCheck --check-prefix=ERR-KERNEL %s
+// RUN: not %clang --target=loongarch64 -### -S -mcmodel=large -fplt %s 2>&1 | 
FileCheck --check-prefix=ERR-LOONGARCH64-PLT-LARGE %s
+// RUN: not %clang --target=loongarch64 -### -S -mcmodel=extreme -fplt %s 2>&1 
| FileCheck --check-prefix=ERR-LOONGARCH64-PLT-EXTREME %s
 
 // TINY: "-mcmodel=tiny"
 // SMALL: "-mcmodel=small"
@@ -25,9 +34,13 @@
 
 // INVALID: error: unsupported argument 'lager' to option '-mcmodel=' for 
target '{{.*}}'
 
+// ERR-TINY: error: unsupported argument 'tiny' to option '-mcmodel=' for 
target '{{.*}}'
 // ERR-MEDIUM: error: unsupported argument 'medium' to option '-mcmodel=' for 
target '{{.*}}'
 // ERR-KERNEL: error: unsupported argument 'kernel' to option '-mcmodel=' for 
target '{{.*}}'
 // ERR-LARGE:  error: unsupported argument 'large' to option '-mcmodel=' for 
target '{{.*}}'
 
 // AARCH64-PIC-LARGE: error: invalid argument '-mcmodel=large' only allowed 
with '-fno-pic'
 // ERR-AARCH64_32: error: unsupported argument 'small' to option '-mcmodel=' 
for target 'aarch64_32-unknown-linux'
+
+// ERR-LOONGARCH64-PLT-LARGE: error: invalid argument '-mcmodel=large' not 
allowed with '-fplt'
+// ERR-LOONGARCH64-PLT-EXTREME: error: invalid argument '-mcmodel=extreme' not 
allowed with '-fplt'

>From 240149f7196c88d418d9c39c60b478b5c3aeb11c Mon Sep 17 00:00:00 2001
From: Weining Lu 
Date: Fri, 24 Nov 2023 13:56:28 +0800
Subject: [PATCH 2/2] Reject small and large. Only accept normal, medium and
 extreme

---
 clang/lib/Driver/ToolChains/Clang.cpp | 16 +---
 clang/test/Driver/mcmodel.c   |  8 
 2 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/clang/lib/Drive

[clang] [Driver] Support -mcmodel= for LoongArch (PR #72514)

2023-11-24 Thread Lu Weining via cfe-commits

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


[clang] [Driver] Support -mcmodel= for LoongArch (PR #72514)

2023-11-29 Thread Lu Weining via cfe-commits

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


[clang] [clang][AVR] Restrict range of assembly constraint 'G' (PR #76561)

2024-01-01 Thread Lu Weining via cfe-commits

SixWeining wrote:

LGTM. I have checked with 
https://gcc.gnu.org/onlinedocs/gccint/Machine-Constraints.html. 'G' stands for 
"A floating point constant 0.0". But I'd like to wait others' opinion.

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


[clang] [Clang][LoongArch] Do not pass vector arguments via vector registers (PR #74990)

2024-01-01 Thread Lu Weining via cfe-commits

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


[clang] [Clang][LoongArch] Do not pass vector arguments via vector registers (PR #74990)

2024-01-01 Thread Lu Weining via cfe-commits

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


[clang] [Clang][LoongArch] Do not pass vector arguments via vector registers (PR #74990)

2024-01-01 Thread Lu Weining via cfe-commits

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


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


[clang] [Clang][LoongArch] Do not pass vector arguments via vector registers (PR #74990)

2024-01-01 Thread Lu Weining via cfe-commits

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


[clang] [Driver] Don't alias -mstrict-align to -mno-unaligned-access (PR #85350)

2024-03-14 Thread Lu Weining via cfe-commits

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

LGTM from LoongArch side as GCC only have `-m[no-]strict-align`.
BTW, should clang release notes be updated for this change?

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


[clang] [Clang][LoongArch] Fix wrong return value type of __iocsrrd_h (PR #84100)

2024-03-05 Thread Lu Weining via cfe-commits

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


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


[clang] [Clang][LoongArch] Fix wrong return value type of __iocsrrd_h (PR #84100)

2024-03-05 Thread Lu Weining via cfe-commits

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


[clang] [clang] Better bitfield access units (PR #65742)

2024-02-25 Thread Lu Weining via cfe-commits


@@ -132,6 +132,7 @@ class LLVM_LIBRARY_VISIBILITY LoongArch64TargetInfo
   : LoongArchTargetInfo(Triple, Opts) {
 LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
 IntMaxType = Int64Type = SignedLong;
+HasCheapUnalignedBitfieldAccess = true;

SixWeining wrote:

> you say set to true when -mno-unaligned-access, but I think you mean set to 
> false in that case?

Yes, I think it should be `false`. @wzssyqa 

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


[llvm] [clang] [clang-tools-extra] [LoongArch] Insert nops and emit align reloc when handle alignment directive (PR #72962)

2024-01-23 Thread Lu Weining via cfe-commits

https://github.com/SixWeining updated 
https://github.com/llvm/llvm-project/pull/72962

>From 4985669d2de986d595c791c04a42e84c1f080c01 Mon Sep 17 00:00:00 2001
From: Jinyang He 
Date: Tue, 9 Jan 2024 15:35:17 +0800
Subject: [PATCH 1/2] [LoongArch] Insert nops and emit align reloc when handle
 alignment directive

Refer to RISCV, we will fix up the alignment if linker relaxation changes
code size and breaks alignment. Insert enough Nops and emit R_LARCH_ALIGN
relocation type so that linker could satisfy the alignment by removing Nops.
It does so only in sections with the SHF_EXECINSTR flag.

In LoongArch psABI v2.30, R_LARCH_ALIGN requires symbol index. The
lowest 8 bits of addend represent alignment and the other bits of
addend represent the maximum number of bytes to emit.
---
 .../MCTargetDesc/LoongArchAsmBackend.cpp  | 69 +++
 .../MCTargetDesc/LoongArchAsmBackend.h| 15 
 .../MCTargetDesc/LoongArchFixupKinds.h|  2 +
 .../Relocations/align-non-executable.s| 22 ++
 .../MC/LoongArch/Relocations/relax-addsub.s   | 15 +++-
 .../MC/LoongArch/Relocations/relax-align.s| 53 ++
 6 files changed, 174 insertions(+), 2 deletions(-)
 create mode 100644 llvm/test/MC/LoongArch/Relocations/align-non-executable.s
 create mode 100644 llvm/test/MC/LoongArch/Relocations/relax-align.s

diff --git a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp 
b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
index 518f6b10edabe8..0f686643622891 100644
--- a/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
+++ b/llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchAsmBackend.cpp
@@ -16,8 +16,11 @@
 #include "llvm/MC/MCAssembler.h"
 #include "llvm/MC/MCContext.h"
 #include "llvm/MC/MCELFObjectWriter.h"
+#include "llvm/MC/MCExpr.h"
+#include "llvm/MC/MCSection.h"
 #include "llvm/MC/MCValue.h"
 #include "llvm/Support/EndianStream.h"
+#include "llvm/Support/MathExtras.h"
 
 #define DEBUG_TYPE "loongarch-asmbackend"
 
@@ -174,6 +177,72 @@ void LoongArchAsmBackend::applyFixup(const MCAssembler 
&Asm,
   }
 }
 
+// Linker relaxation may change code size. We have to insert Nops
+// for .align directive when linker relaxation enabled. So then Linker
+// could satisfy alignment by removing Nops.
+// The function returns the total Nops Size we need to insert.
+bool LoongArchAsmBackend::shouldInsertExtraNopBytesForCodeAlign(
+const MCAlignFragment &AF, unsigned &Size) {
+  // Calculate Nops Size only when linker relaxation enabled.
+  const MCSubtargetInfo *STI = AF.getSubtargetInfo();
+  if (!STI->hasFeature(LoongArch::FeatureRelax))
+return false;
+
+  // Ignore alignment if the minimum Nop size is less than the MaxBytesToEmit.
+  const unsigned MinNopLen = 4;
+  if (AF.getMaxBytesToEmit() < MinNopLen)
+return false;
+  Size = AF.getAlignment().value() - MinNopLen;
+  return AF.getAlignment() > MinNopLen;
+}
+
+// We need to insert R_LARCH_ALIGN relocation type to indicate the
+// position of Nops and the total bytes of the Nops have been inserted
+// when linker relaxation enabled.
+// The function inserts fixup_loongarch_align fixup which eventually will
+// transfer to R_LARCH_ALIGN relocation type.
+// The improved R_LARCH_ALIGN requires symbol index. The lowest 8 bits of
+// addend represent alignment and the other bits of addend represent the
+// maximum number of bytes to emit. The maximum number of bytes is zero
+// means ignore the emit limit.
+bool LoongArchAsmBackend::shouldInsertFixupForCodeAlign(
+MCAssembler &Asm, const MCAsmLayout &Layout, MCAlignFragment &AF) {
+  // Insert the fixup only when linker relaxation enabled.
+  const MCSubtargetInfo *STI = AF.getSubtargetInfo();
+  if (!STI->hasFeature(LoongArch::FeatureRelax))
+return false;
+
+  // Calculate total Nops we need to insert. If there are none to insert
+  // then simply return.
+  unsigned Count;
+  if (!shouldInsertExtraNopBytesForCodeAlign(AF, Count))
+return false;
+
+  MCSection *Sec = AF.getParent();
+  MCContext &Ctx = Asm.getContext();
+  const MCExpr *Dummy = MCConstantExpr::create(0, Ctx);
+  // Create fixup_loongarch_align fixup.
+  MCFixup Fixup =
+  MCFixup::create(0, Dummy, MCFixupKind(LoongArch::fixup_loongarch_align));
+  const MCSymbolRefExpr *MCSym = getSecToAlignSym()[Sec];
+  if (MCSym == nullptr) {
+// Create a symbol and make the value of symbol is zero.
+MCSymbol *Sym = Ctx.createTempSymbol(".Lla-relax-align", false);
+Sym->setFragment(&*Sec->getBeginSymbol()->getFragment());
+Asm.registerSymbol(*Sym);
+MCSym = MCSymbolRefExpr::create(Sym, Ctx);
+getSecToAlignSym()[Sec] = MCSym;
+  }
+
+  uint64_t FixedValue = 0;
+  unsigned Lo = Log2_64(Count) + 1;
+  unsigned Hi = AF.getMaxBytesToEmit() >= Count ? 0 : AF.getMaxBytesToEmit();
+  MCValue Value = MCValue::get(MCSym, nullptr, Hi << 8 | Lo);
+  Asm.getWriter().recordRelocation(Asm, Layout, &AF, Fixup, Value, FixedValue);
+
+  return true;
+}
+
 boo

[llvm] [clang] [clang-tools-extra] [LoongArch] Insert nops and emit align reloc when handle alignment directive (PR #72962)

2024-01-23 Thread Lu Weining via cfe-commits

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


[clang] [clang-tools-extra] [llvm] [LoongArch] Insert nops and emit align reloc when handle alignment directive (PR #72962)

2024-01-23 Thread Lu Weining via cfe-commits

SixWeining wrote:

Should be fixed by baba7e4175b6.

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


[clang] Check lsx/lasx features when running builtin tests (PR #79250)

2024-01-23 Thread Lu Weining via cfe-commits

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


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


[clang] [LoongArch][test] Add tests reporting error if lsx/lasx feature is missing when lsx/lasx builtins are called (PR #79250)

2024-01-23 Thread Lu Weining via cfe-commits

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


[clang] [LoongArch][test] Add tests reporting error if lsx/lasx feature is missing when lsx/lasx builtins are called (PR #79250)

2024-01-23 Thread Lu Weining via cfe-commits

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


[llvm] [clang] [docs] Add llvm and clang release notes for the global-var code model attribute (PR #78664)

2024-01-18 Thread Lu Weining via cfe-commits

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

LGTM. Thanks.

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


[llvm] [clang] [LoongArch] Add definitions and feature 'frecipe' for FP approximation intrinsics/builtins (PR #78962)

2024-01-22 Thread Lu Weining via cfe-commits

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

LGTM if the conflicting were resolved.

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


[llvm] [clang] [LoongArch] Add definitions and feature 'frecipe' for FP approximation intrinsics/builtins (PR #78962)

2024-01-22 Thread Lu Weining via cfe-commits

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


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


[llvm] [clang] [LoongArch] Add definitions and feature 'frecipe' for FP approximation intrinsics/builtins (PR #78962)

2024-01-22 Thread Lu Weining via cfe-commits

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


[clang] [llvm] [docs] Add llvm & clang release notes for LoongArch (PR #79097)

2024-01-22 Thread Lu Weining via cfe-commits

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


[clang] [Clang][LoongArch] Support builtin functions for LSX and LASX (PR #69313)

2023-10-22 Thread Lu Weining via cfe-commits

SixWeining wrote:

> Given you've already split your changes into several smaller commits, it's 
> probably better to file them as separate PRs, so each one is smaller than the 
> current 3+-line diff, and become more reviewable that way.

I'm not sure seperate PRs are appropriate since some of these 6 commits depend 
on the others. If creating 6 PRs, we will see:
PR1 consists of 1 commit
PR2 consists of 2 commits
...
PR6 consists of 6 commits

In fact, we can review each of these 6 commits in one PR by clicking the 
`Changes from all commits` button and `Select commit` in the `Files changed` 
tab.





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


[clang] [Clang][LoongArch] Support builtin functions for LSX and LASX (PR #69313)

2023-10-22 Thread Lu Weining via cfe-commits

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

- For the commits `[LoongArch][CodeGen][clang] Add builtin functions test cases 
for LASX` and `[LoongArch][CodeGen][clang] Add builtin functions test cases for 
LSX`, `Change-Id`s can be removed.
- Please fix the test failure.

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


[clang] [LoongArch] Fix ABI mismatch with gcc/g++ about empty structs passing (PR #70320)

2023-10-26 Thread Lu Weining via cfe-commits

https://github.com/SixWeining created 
https://github.com/llvm/llvm-project/pull/70320

How empty structs (not as fields of container struct) are passed in C++ is not 
explicitly documented in psABI. However, this patch fixes the mismatch with g++.

Note that the unnamed bitfield case `struct { int : 1; }` in C is also fixed. 
Previously clang regards it as an empty struct and then ignores it when 
passing. Now size of the struct is counted; since it's size is not 0, clang 
will not ignore it even in C.

While https://reviews.llvm.org/D156116 fixed the handling of empty struct when 
considering eligibility of the container struct for the FP calling convention 
('flattening'), this patch fixes the handling of passing the empty struct 
itself.

Fix https://github.com/llvm/llvm-project/issues/70319

>From 3ed0605126e2cfd94e58dd38c2f58764e32e2057 Mon Sep 17 00:00:00 2001
From: Weining Lu 
Date: Thu, 26 Oct 2023 13:40:27 +0800
Subject: [PATCH] [LoongArch] Fix ABI mismatch with gcc/g++ about empty structs
 passing

How empty structs (not as fields of container struct) are passed in C++
is not explicitly documented in psABI. However, this patch fixes the
mismatch with g++.

Note that the unnamed bitfield case `struct { int : 1; }` in C is also
fixed. Previously clang regards it as an empty struct and then ignores
it when passing. Now size of the struct is counted; since it's size is
not 0, clang will not ignore it even in C.

While https://reviews.llvm.org/D156116 fixed the handling of empty
struct when considering eligibility of the container struct for the FP
calling convention ('flattening'), this patch fixes the handling of
passing the empty struct itself.

Fix https://github.com/llvm/llvm-project/issues/70319
---
 clang/lib/CodeGen/Targets/LoongArch.cpp| 10 ++
 clang/test/CodeGen/LoongArch/abi-lp64d-empty-structs.c |  8 
 2 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/clang/lib/CodeGen/Targets/LoongArch.cpp 
b/clang/lib/CodeGen/Targets/LoongArch.cpp
index 7483bf6d6d1e8e2..bc508a99da9cedf 100644
--- a/clang/lib/CodeGen/Targets/LoongArch.cpp
+++ b/clang/lib/CodeGen/Targets/LoongArch.cpp
@@ -308,12 +308,14 @@ ABIArgInfo 
LoongArchABIInfo::classifyArgumentType(QualType Ty, bool IsFixed,
CGCXXABI::RAA_DirectInMemory);
   }
 
-  // Ignore empty structs/unions.
-  if (isEmptyRecord(getContext(), Ty, true))
-return ABIArgInfo::getIgnore();
-
   uint64_t Size = getContext().getTypeSize(Ty);
 
+  // Ignore empty struct or union whose size is zero, e.g. `struct { }` in C or
+  // `struct { int a[0]; }` in C++. In C++, `struct { }` is empty but it's size
+  // is 1 byte and g++ doesn't ignore it; clang++ matches this behaviour.
+  if (isEmptyRecord(getContext(), Ty, true) && Size == 0)
+return ABIArgInfo::getIgnore();
+
   // Pass floating point values via FARs if possible.
   if (IsFixed && Ty->isFloatingType() && !Ty->isComplexType() &&
   FRLen >= Size && FARsLeft) {
diff --git a/clang/test/CodeGen/LoongArch/abi-lp64d-empty-structs.c 
b/clang/test/CodeGen/LoongArch/abi-lp64d-empty-structs.c
index d0daafac336ec0c..281b7b15841a999 100644
--- a/clang/test/CodeGen/LoongArch/abi-lp64d-empty-structs.c
+++ b/clang/test/CodeGen/LoongArch/abi-lp64d-empty-structs.c
@@ -93,7 +93,7 @@ struct s9 test_s9(struct s9 a) {
 }
 
 // CHECK-C: define{{.*}} void @test_s10()
-// CHECK-CXX: define{{.*}} void @_Z8test_s103s10()
+// CHECK-CXX: define{{.*}} i64 @_Z8test_s103s10(i64 {{.*}})
 struct s10 { };
 struct s10 test_s10(struct s10 a) {
   return a;
@@ -128,14 +128,14 @@ struct s14 test_s14(struct s14 a) {
 }
 
 // CHECK-C: define{{.*}} void @test_s15()
-// CHECK-CXX: define{{.*}} void @_Z8test_s153s15()
+// CHECK-CXX: define{{.*}} i64 @_Z8test_s153s15(i64 {{.*}})
 struct s15 { int : 0; };
 struct s15 test_s15(struct s15 a) {
   return a;
 }
 
-// CHECK-C: define{{.*}} void @test_s16()
-// CHECK-CXX: define{{.*}} void @_Z8test_s163s16()
+// CHECK-C: define{{.*}} i64 @test_s16(i64 {{.*}})
+// CHECK-CXX: define{{.*}} i64 @_Z8test_s163s16(i64 {{.*}})
 struct s16 { int : 1; };
 struct s16 test_s16(struct s16 a) {
   return a;

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


[clang] [LoongArch] Fix ABI mismatch with gcc/g++ about empty structs passing (PR #70320)

2023-10-26 Thread Lu Weining via cfe-commits

SixWeining wrote:

Hi @xen0n @xry111, what do you think about this change? If it is ok, I'd like 
to checrry-pick to release/17.x (hope it's not too late...).

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


[clang] [Clang][LoongArch] Generate _mcount instead of mcount (PR #65657)

2023-09-07 Thread Lu Weining via cfe-commits

SixWeining wrote:

> also cc @SixWeining (BTW we want to have a GitHub team set up for 
> notifications and assignments apparently)

There is one:
https://github.com/orgs/llvm/teams/pr-subscribers-loongarch

I will invite you to join this team and others interested in could also request 
to join.



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


[clang] [Clang][LoongArch] Generate _mcount instead of mcount (PR #65657)

2023-09-07 Thread Lu Weining via cfe-commits

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

I have checked that glibc/sysdeps/loongarch/machine-gmon.h defines `_mcount`.

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


[clang] [clang] Better bitfield access units (PR #65742)

2024-02-21 Thread Lu Weining via cfe-commits

SixWeining wrote:

> For GCC, we have `-mno-unalgined-access`. We need also add this option to 
> clang.

`-mno-unalgined-access` has been added since clang17: 
https://reviews.llvm.org/D149946

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


[clang] [clang] Better bitfield access units (PR #65742)

2024-02-21 Thread Lu Weining via cfe-commits


@@ -132,6 +132,7 @@ class LLVM_LIBRARY_VISIBILITY LoongArch64TargetInfo
   : LoongArchTargetInfo(Triple, Opts) {
 LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
 IntMaxType = Int64Type = SignedLong;
+HasCheapUnalignedBitfieldAccess = true;

SixWeining wrote:

> Only set it to true when -mno-unaligned-access.

In `LoongArchTargetInfo::handleTargetFeatures()`, we can handle the feature 
`-ual`.

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


[clang] [LoongArch][clang] Add support for option `-msimd=` and macro `__loongarch_simd_width`. (PR #97984)

2024-07-07 Thread Lu Weining via cfe-commits

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


[clang] [LoongArch][clang] Add support for option `-msimd=` and macro `__loongarch_simd_width`. (PR #97984)

2024-07-07 Thread Lu Weining via cfe-commits

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

LGTM

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


[clang] [llvm] [llvm][Triple] Add `Environment` members and parsing for glibc/musl parity. (PR #107664)

2024-09-06 Thread Lu Weining via cfe-commits

SixWeining wrote:

cc @xen0n @xry111 

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


[clang] [llvm] [llvm][Triple] Add `Environment` members and parsing for glibc/musl parity. (PR #107664)

2024-09-09 Thread Lu Weining via cfe-commits

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

The LoongArch bits LGTM. Thanks.

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


[clang] [llvm] [LoongArch] Adjust LA64 data layout by using n32:64 in layout string (PR #93814)

2024-06-05 Thread Lu Weining via cfe-commits

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


[clang] [llvm] [LoongArch] Adjust LA64 data layout by using n32:64 in layout string (PR #93814)

2024-06-05 Thread Lu Weining via cfe-commits

https://github.com/SixWeining commented:

@wangleiat What do you think?

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


[clang] [llvm] [LoongArch] Adjust LA64 data layout by using n32:64 in layout string (PR #93814)

2024-06-05 Thread Lu Weining via cfe-commits


@@ -5368,8 +5368,8 @@ std::string llvm::UpgradeDataLayoutString(StringRef DL, 
StringRef TT) {
 return DL.empty() ? std::string("G1") : (DL + "-G1").str();
   }
 
-  if (T.isRISCV64()) {
-// Make i32 a native type for 64-bit RISC-V.
+  if (T.isRISCV64() || T.isLoongArch64()) {

SixWeining wrote:

Better to sort alphabetically.

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


[clang] [clang][LoongArch] Enable -fasynchronous-unwind-tables by default on Linux (PR #94711)

2024-06-06 Thread Lu Weining via cfe-commits




SixWeining wrote:

We already have `loongarch-default-features.c`.

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


[clang] [clang][LoongArch] Enable -fasynchronous-unwind-tables by default on Linux (PR #94711)

2024-06-06 Thread Lu Weining via cfe-commits




SixWeining wrote:

I just rename it in f2441b0297501610b59527f93e3174c814d63941.

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


[clang] [LoongArch] Enable 128-bits vector by default (PR #100056)

2024-07-22 Thread Lu Weining via cfe-commits

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


[clang] [llvm] [LoongArch] Support -march=la64v1.0 and -march=la64v1.1 (PR #100057)

2024-07-22 Thread Lu Weining via cfe-commits

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


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


[clang] [llvm] [LoongArch] Support -march=la64v1.0 and -march=la64v1.1 (PR #100057)

2024-07-22 Thread Lu Weining via cfe-commits

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


[clang] [llvm] [LoongArch] Support la664 (PR #100068)

2024-07-22 Thread Lu Weining via cfe-commits

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


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


[clang] [llvm] [LoongArch] Support la664 (PR #100068)

2024-07-23 Thread Lu Weining via cfe-commits

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


[clang] [LoongArch][clang] Add support for option `-msimd=` and macro `__loongarch_simd_width`. (PR #97984)

2024-07-08 Thread Lu Weining via cfe-commits

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


[clang] [LoongArch][clang] Modify `loongarch-msimd.c` to avoid `grep -o`. NFC (PR #98442)

2024-07-11 Thread Lu Weining via cfe-commits

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


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


[clang] [LoongArch][clang] Modify `loongarch-msimd.c` to avoid `grep -o`. NFC (PR #98442)

2024-07-11 Thread Lu Weining via cfe-commits

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


[clang] [llvm] [clang] Introduce target-specific `Sema` components (PR #93179)

2024-05-23 Thread Lu Weining via cfe-commits

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

LGTM from the LoongArch side. Thanks!

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


[clang] [llvm] [LoongArch] Add options for annotate tablejump (PR #102411)

2024-10-12 Thread Lu Weining via cfe-commits


@@ -5340,6 +5340,10 @@ def mno_lasx : Flag<["-"], "mno-lasx">, 
Group,
 def msimd_EQ : Joined<["-"], "msimd=">, Group,
   Flags<[TargetSpecific]>,
   HelpText<"Select the SIMD extension(s) to be enabled in LoongArch either 
'none', 'lsx', 'lasx'.">;
+def mannotate_tablejump : Flag<["-"], "mannotate-tablejump">, 
Group,
+  HelpText<"Enable annotate table jump instruction to correlate it with the 
jump table.">;

SixWeining wrote:

Is it necessary to add the TargetSpecific flag?

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


[clang] [llvm] [LoongArch] Add options for annotate tablejump (PR #102411)

2024-10-12 Thread Lu Weining via cfe-commits

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


[clang] [lld] [lld][LoongArch] Enable relaxation when --relax option is passed (PR #111488)

2024-10-13 Thread Lu Weining via cfe-commits


@@ -1462,6 +1462,8 @@ template  void 
Writer::finalizeAddressDependentContent() {
   for (;;) {
 bool changed = ctx.target->needsThunks
? tc.createThunks(pass, ctx.outputSections)
+   : ctx.arg.emachine == EM_LOONGARCH && !ctx.arg.relax

SixWeining wrote:

> ctx.arg.relax is used here because we want to determine whether or not to 
> apply relaxation based on the parameters passed at the time of linking.

I don't think so. R_LARCH_ALIGN should be handled unconditionally, otherwise 
the code may be unaligned.

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


[clang] [lld] [lld][LoongArch] Enable relaxation when --relax option is passed (PR #111488)

2024-10-14 Thread Lu Weining via cfe-commits

SixWeining wrote:

The title should also be updated.

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


[clang] [lld] [Driver] Default enable LoongArch linker relaxation (PR #111488)

2024-10-15 Thread Lu Weining via cfe-commits

SixWeining wrote:

I think that's OK.

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


[clang] [llvm] [LoongArch] [CodeGen] Add options for Clang to generate LoongArch-specific frecipe & frsqrte instructions (PR #109917)

2024-10-15 Thread Lu Weining via cfe-commits


@@ -0,0 +1,30 @@
+/// Test -m[no]frecipe options.
+
+// RUN: %clang --target=loongarch64 -mfrecipe -fsyntax-only %s -### 2>&1 | \
+// RUN: FileCheck %s --check-prefix=CC1-FRECIPE
+// RUN: %clang --target=loongarch64 -mno-frecipe -fsyntax-only %s -### 2>&1 | \
+// RUN: FileCheck %s --check-prefix=CC1-NO-FRECIPE
+// RUN: %clang --target=loongarch64 -mno-frecipe -mfrecipe -fsyntax-only %s 
-### 2>&1 | \
+// RUN: FileCheck %s --check-prefix=CC1-FRECIPE
+// RUN: %clang --target=loongarch64  -mfrecipe -mno-frecipe -fsyntax-only %s 
-### 2>&1 | \
+// RUN: FileCheck %s --check-prefix=CC1-NO-FRECIPE
+
+// RUN: %clang --target=loongarch64 -mfrecipe -S -emit-llvm %s -o - | \
+// RUN: FileCheck %s --check-prefix=IR-FRECIPE
+// RUN: %clang --target=loongarch64 -mno-frecipe -S -emit-llvm %s -o - | \
+// RUN: FileCheck %s --check-prefix=IR-NO-FRECIPE
+// RUN: %clang --target=loongarch64 -mno-frecipe -mfrecipe -S -emit-llvm %s -o 
- | \
+// RUN: FileCheck %s --check-prefix=IR-FRECIPE
+// RUN: %clang --target=loongarch64 -mfrecipe -mno-frecipe -S -emit-llvm %s -o 
- | \
+// RUN: FileCheck %s --check-prefix=IR-NO-FRECIPE
+
+
+// CC1-FRECIPE: "-target-feature" "+frecipe"
+// CC1-NO-FRECIPE: "-target-feature" "-frecipe"
+
+// IR-FRECIPE: attributes #[[#]] 
={{.*}}"target-features"="{{(.*,)?}}+frecipe{{(,.*)?}}"
+// IR-NO-FRECIPE: attributes #[[#]] 
={{.*}}"target-features"="{{(.*,)?}}-frecipe{{(,.*)?}}"
+
+int foo(void) {
+return  42;

SixWeining wrote:

```suggestion
  return 42;
```

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


[clang] [llvm] [LoongArch] [CodeGen] Add options for Clang to generate LoongArch-specific frecipe & frsqrte instructions (PR #109917)

2024-10-15 Thread Lu Weining via cfe-commits

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

LGTM except a nit.

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


[clang] [llvm] [LoongArch] [CodeGen] Add options for Clang to generate LoongArch-specific frecipe & frsqrte instructions (PR #109917)

2024-10-15 Thread Lu Weining via cfe-commits

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


[clang] [llvm] [LoongArch] [CodeGen] Add options for Clang to generate LoongArch-specific frecipe & frsqrte instructions (PR #109917)

2024-10-10 Thread Lu Weining via cfe-commits


@@ -251,6 +251,16 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
 } else /*-mno-lasx*/
   Features.push_back("-lasx");
   }
+
+  // Select frecipe feature determined by -m[no-]frecipe.
+  if (const Arg *A =
+  Args.getLastArg(options::OPT_mfrecipe, options::OPT_mno_frecipe)) {
+// -mno-frecipe conflicts with -mfrecipe.

SixWeining wrote:

-mno-frecipe doesn't conflict with -mfrecipe. They can appear together but the 
last one wins. You can remove this comment.

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


[clang] [llvm] [LoongArch] [CodeGen] Add options for Clang to generate LoongArch-specific frecipe & frsqrte instructions (PR #109917)

2024-10-10 Thread Lu Weining via cfe-commits


@@ -5902,6 +5914,92 @@ Register 
LoongArchTargetLowering::getExceptionSelectorRegister(
   return LoongArch::R5;
 }
 
+//===--===//
+// Target Optimization Hooks
+//===--===//
+
+static int getEstimateRefinementSteps(EVT VT,
+  const LoongArchSubtarget &Subtarget) {
+  // Feature FRECIPE instrucions relative accuracy is 2^-14.
+  // IEEE float has 23 digits and double has 52 digits.
+  int RefinementSteps = VT.getScalarType() == MVT::f64 ? 2 : 1;
+  return RefinementSteps;
+}
+
+SDValue LoongArchTargetLowering::getSqrtEstimate(SDValue Operand,
+ SelectionDAG &DAG, int 
Enabled,
+ int &RefinementSteps,
+ bool &UseOneConstNR,
+ bool Reciprocal) const {
+  if (Subtarget.hasFrecipe()) {
+SDLoc DL(Operand);
+EVT VT = Operand.getValueType();
+unsigned Opcode;
+
+if (VT == MVT::f32) {
+  Opcode = LoongArchISD::FRSQRTE_S;
+} else if (VT == MVT::f64 && Subtarget.hasBasicD()) {
+  Opcode = LoongArchISD::FRSQRTE_D;
+} else if (VT == MVT::v4f32 && Subtarget.hasExtLSX()) {
+  Opcode = LoongArchISD::VFRSQRTE_S;
+} else if (VT == MVT::v2f64 && Subtarget.hasExtLSX()) {
+  Opcode = LoongArchISD::VFRSQRTE_D;
+} else if (VT == MVT::v8f32 && Subtarget.hasExtLASX()) {
+  Opcode = LoongArchISD::XVFRSQRTE_S;
+} else if (VT == MVT::v4f64 && Subtarget.hasExtLASX()) {
+  Opcode = LoongArchISD::XVFRSQRTE_D;
+} else {
+  return SDValue();
+}
+
+UseOneConstNR = false;
+if (RefinementSteps == ReciprocalEstimate::Unspecified)
+  RefinementSteps = getEstimateRefinementSteps(VT, Subtarget);
+
+SDValue Estimate = DAG.getNode(Opcode, DL, VT, Operand);
+if (Reciprocal) {

SixWeining wrote:

Useless `{}`.

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


[clang] [llvm] [LoongArch] [CodeGen] Add options for Clang to generate LoongArch-specific frecipe & frsqrte instructions (PR #109917)

2024-10-10 Thread Lu Weining via cfe-commits


@@ -141,6 +141,22 @@ enum NodeType : unsigned {
   VALL_NONZERO,
   VANY_NONZERO,
 
+  // Floating point approximate reciprocal operation
+  FRECIPE_S,

SixWeining wrote:

Can we only define two generic nodes (FRECIPE / FRSQRTE)?

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


[clang] [llvm] [LoongArch] [CodeGen] Add options for Clang to generate LoongArch-specific frecipe & frsqrte instructions (PR #109917)

2024-10-10 Thread Lu Weining via cfe-commits


@@ -251,6 +251,16 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
 } else /*-mno-lasx*/
   Features.push_back("-lasx");
   }
+
+  // Select frecipe feature determined by -m[no-]frecipe.
+  if (const Arg *A =
+  Args.getLastArg(options::OPT_mfrecipe, options::OPT_mno_frecipe)) {
+// -mno-frecipe conflicts with -mfrecipe.
+if (A->getOption().matches(options::OPT_mfrecipe)) {
+  Features.push_back("+frecipe");
+} else /*-mnofrecipe*/

SixWeining wrote:

Unnecessary comment.

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


[clang] [llvm] [LoongArch] [CodeGen] Add options for Clang to generate LoongArch-specific frecipe & frsqrte instructions (PR #109917)

2024-10-10 Thread Lu Weining via cfe-commits


@@ -19,12 +19,15 @@ def SDT_LoongArchMOVGR2FR_W_LA64
 def SDT_LoongArchMOVFR2GR_S_LA64
 : SDTypeProfile<1, 1, [SDTCisVT<0, i64>, SDTCisVT<1, f32>]>;
 def SDT_LoongArchFTINT : SDTypeProfile<1, 1, [SDTCisFP<0>, SDTCisFP<1>]>;
+def SDT_LoongArchFRECIPE : SDTypeProfile<1, 1, [SDTCisFP<0>, SDTCisFP<1>]>;
 
 def loongarch_movgr2fr_w_la64
 : SDNode<"LoongArchISD::MOVGR2FR_W_LA64", SDT_LoongArchMOVGR2FR_W_LA64>;
 def loongarch_movfr2gr_s_la64
 : SDNode<"LoongArchISD::MOVFR2GR_S_LA64", SDT_LoongArchMOVFR2GR_S_LA64>;
 def loongarch_ftint : SDNode<"LoongArchISD::FTINT", SDT_LoongArchFTINT>;
+def loongarch_frecipe_s : SDNode<"LoongArchISD::FRECIPE_S", 
SDT_LoongArchFRECIPE>;
+def loongarch_frsqrte_s : SDNode<"LoongArchISD::FRSQRTE_S", 
SDT_LoongArchFRECIPE>;

SixWeining wrote:

Use a different type.

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


[clang] [llvm] [LoongArch] [CodeGen] Add options for Clang to generate LoongArch-specific frecipe & frsqrte instructions (PR #109917)

2024-10-10 Thread Lu Weining via cfe-commits


@@ -5902,6 +5914,92 @@ Register 
LoongArchTargetLowering::getExceptionSelectorRegister(
   return LoongArch::R5;
 }
 
+//===--===//
+// Target Optimization Hooks
+//===--===//
+
+static int getEstimateRefinementSteps(EVT VT,
+  const LoongArchSubtarget &Subtarget) {
+  // Feature FRECIPE instrucions relative accuracy is 2^-14.
+  // IEEE float has 23 digits and double has 52 digits.
+  int RefinementSteps = VT.getScalarType() == MVT::f64 ? 2 : 1;
+  return RefinementSteps;
+}
+
+SDValue LoongArchTargetLowering::getSqrtEstimate(SDValue Operand,
+ SelectionDAG &DAG, int 
Enabled,
+ int &RefinementSteps,
+ bool &UseOneConstNR,
+ bool Reciprocal) const {
+  if (Subtarget.hasFrecipe()) {
+SDLoc DL(Operand);
+EVT VT = Operand.getValueType();
+unsigned Opcode;
+
+if (VT == MVT::f32) {

SixWeining wrote:

Useless `{}`.

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


[clang] [llvm] [LoongArch] [CodeGen] Add options for Clang to generate LoongArch-specific frecipe & frsqrte instructions (PR #109917)

2024-10-10 Thread Lu Weining via cfe-commits


@@ -0,0 +1,396 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc --mtriple=loongarch32 --mattr=+f,-d,-frecipe < %s | FileCheck %s 
--check-prefix=LA32F
+; RUN: llc --mtriple=loongarch32 --mattr=+f,-d,+frecipe < %s | FileCheck %s 
--check-prefix=LA32F-FRECIPE
+; RUN: llc --mtriple=loongarch64 --mattr=+d,-frecipe < %s | FileCheck %s 
--check-prefix=LA64D
+; RUN: llc --mtriple=loongarch64 --mattr=+d,+frecipe < %s | FileCheck %s 
--check-prefix=LA64D-FRECIPE
+
+
+declare float @llvm.sqrt.f32(float)
+declare double @llvm.sqrt.f64(double)
+
+define float @frsqrt_f32(float %a) nounwind {
+; LA32F-LABEL: frsqrt_f32:
+; LA32F:   # %bb.0:
+; LA32F-NEXT:frsqrt.s $fa0, $fa0
+; LA32F-NEXT:ret
+;
+; LA32F-FRECIPE-LABEL: frsqrt_f32:
+; LA32F-FRECIPE:   # %bb.0:
+; LA32F-FRECIPE-NEXT:frsqrte.s $fa1, $fa0
+; LA32F-FRECIPE-NEXT:pcalau12i $a0, %pc_hi20(.LCPI0_0)
+; LA32F-FRECIPE-NEXT:fld.s $fa2, $a0, %pc_lo12(.LCPI0_0)
+; LA32F-FRECIPE-NEXT:pcalau12i $a0, %pc_hi20(.LCPI0_1)
+; LA32F-FRECIPE-NEXT:fld.s $fa3, $a0, %pc_lo12(.LCPI0_1)
+; LA32F-FRECIPE-NEXT:fmul.s$fa1, $fa0, $fa1
+; LA32F-FRECIPE-NEXT:fmul.s$fa0, $fa0, $fa1
+; LA32F-FRECIPE-NEXT:fmadd.s   $fa0, $fa0, $fa1, $fa2
+; LA32F-FRECIPE-NEXT:fmul.s$fa1, $fa1, $fa3
+; LA32F-FRECIPE-NEXT:fmul.s$fa0, $fa1, $fa0
+; LA32F-FRECIPE-NEXT:ret
+;
+; LA64D-LABEL: frsqrt_f32:
+; LA64D:   # %bb.0:
+; LA64D-NEXT:frsqrt.s $fa0, $fa0
+; LA64D-NEXT:ret
+;
+; LA64D-FRECIPE-LABEL: frsqrt_f32:
+; LA64D-FRECIPE:   # %bb.0:
+; LA64D-FRECIPE-NEXT:frsqrte.s $fa1, $fa0
+; LA64D-FRECIPE-NEXT:pcalau12i $a0, %pc_hi20(.LCPI0_0)
+; LA64D-FRECIPE-NEXT:fld.s $fa2, $a0, %pc_lo12(.LCPI0_0)
+; LA64D-FRECIPE-NEXT:pcalau12i $a0, %pc_hi20(.LCPI0_1)
+; LA64D-FRECIPE-NEXT:fld.s $fa3, $a0, %pc_lo12(.LCPI0_1)
+; LA64D-FRECIPE-NEXT:fmul.s$fa1, $fa0, $fa1
+; LA64D-FRECIPE-NEXT:fmul.s$fa0, $fa0, $fa1
+; LA64D-FRECIPE-NEXT:fmadd.s   $fa0, $fa0, $fa1, $fa2
+; LA64D-FRECIPE-NEXT:fmul.s$fa1, $fa1, $fa3
+; LA64D-FRECIPE-NEXT:fmul.s$fa0, $fa1, $fa0
+; LA64D-FRECIPE-NEXT:ret
+
+  %1 = call fast float @llvm.sqrt.f32(float %a)
+  %2 = fdiv fast float 1.0, %1
+  ret float %2
+}
+
+define double @frsqrt_f64(double %a) nounwind {
+; LA32F-LABEL: frsqrt_f64:
+; LA32F:   # %bb.0:
+; LA32F-NEXT:addi.w$sp, $sp, -16
+; LA32F-NEXT:st.w  $ra, $sp, 12 
+; LA32F-NEXT:bl%plt(sqrt)
+; LA32F-NEXT:move  $a2, $a0
+; LA32F-NEXT:move  $a3, $a1
+; LA32F-NEXT:lu12i.w   $a1, 261888
+; LA32F-NEXT:move  $a0, $zero
+; LA32F-NEXT:bl%plt(__divdf3)
+; LA32F-NEXT:ld.w  $ra, $sp, 12  
+; LA32F-NEXT:addi.w$sp, $sp, 16
+; LA32F-NEXT:ret
+;
+; LA32F-FRECIPE-LABEL: frsqrt_f64:
+; LA32F-FRECIPE:   # %bb.0:
+; LA32F-FRECIPE-NEXT:addi.w$sp, $sp, -16
+; LA32F-FRECIPE-NEXT:st.w  $ra, $sp, 12# 4-byte Folded 
Spill
+; LA32F-FRECIPE-NEXT:bl%plt(sqrt)
+; LA32F-FRECIPE-NEXT:move  $a2, $a0
+; LA32F-FRECIPE-NEXT:move  $a3, $a1
+; LA32F-FRECIPE-NEXT:lu12i.w   $a1, 261888
+; LA32F-FRECIPE-NEXT:move  $a0, $zero
+; LA32F-FRECIPE-NEXT:bl%plt(__divdf3)
+; LA32F-FRECIPE-NEXT:ld.w  $ra, $sp, 12# 4-byte Folded 
Reload
+; LA32F-FRECIPE-NEXT:addi.w$sp, $sp, 16
+; LA32F-FRECIPE-NEXT:ret
+;
+; LA64D-LABEL: frsqrt_f64:
+; LA64D:   # %bb.0:
+; LA64D-NEXT:frsqrt.d $fa0, $fa0
+; LA64D-NEXT:ret
+;
+; LA64D-FRECIPE-LABEL: frsqrt_f64:
+; LA64D-FRECIPE:   # %bb.0:
+; LA64D-FRECIPE-NEXT:frsqrte.d $fa1, $fa0
+; LA64D-FRECIPE-NEXT:pcalau12i $a0, %pc_hi20(.LCPI1_0)
+; LA64D-FRECIPE-NEXT:fld.d $fa2, $a0, %pc_lo12(.LCPI1_0)
+; LA64D-FRECIPE-NEXT:pcalau12i $a0, %pc_hi20(.LCPI1_1)
+; LA64D-FRECIPE-NEXT:fld.d $fa3, $a0, %pc_lo12(.LCPI1_1)
+; LA64D-FRECIPE-NEXT:fmul.d$fa1, $fa0, $fa1
+; LA64D-FRECIPE-NEXT:fmul.d$fa4, $fa0, $fa1
+; LA64D-FRECIPE-NEXT:fmadd.d   $fa4, $fa4, $fa1, $fa2
+; LA64D-FRECIPE-NEXT:fmul.d$fa1, $fa1, $fa3
+; LA64D-FRECIPE-NEXT:fmul.d$fa1, $fa1, $fa4
+; LA64D-FRECIPE-NEXT:fmul.d$fa0, $fa0, $fa1
+; LA64D-FRECIPE-NEXT:fmadd.d   $fa0, $fa0, $fa1, $fa2
+; LA64D-FRECIPE-NEXT:fmul.d$fa1, $fa1, $fa3
+; LA64D-FRECIPE-NEXT:fmul.d$fa0, $fa1, $fa0
+; LA64D-FRECIPE-NEXT:ret
+  %1 = call fast double @llvm.sqrt.f64(double %a)
+  %2 = fdiv fast double 1.0, %1
+  ret double %2
+}
+
+define double @sqrt_simplify_before_recip_3_uses_f64(double %x, ptr %p1, ptr 
%p2) nounwind {
+; LA64D-LABEL: sqrt_simplify_before_recip_3_uses_f64:
+; LA64D:   # %bb.0:
+; LA64D-NEXT:pcalau12i $a2, %pc_hi20(.LCPI2_0)
+; LA64D-NEXT:fld.d $fa2, $a2, %pc_lo12(.LCPI2_0)
+; LA64D-NEXT:fsqrt.d

[clang] [llvm] [LoongArch] [CodeGen] Add options for Clang to generate LoongArch-specific frecipe & frsqrte instructions (PR #109917)

2024-10-11 Thread Lu Weining via cfe-commits


@@ -141,6 +141,22 @@ enum NodeType : unsigned {
   VALL_NONZERO,
   VANY_NONZERO,
 
+  // Floating point approximate reciprocal operation
+  FRECIPE_S,

SixWeining wrote:

They are not the same. The iocsrrd_* instructions have same operand type `GPR` 
but frecipe_* instructions have different types: FPR32/FPR64/v8f32/...

Is it right? @wangleiat 

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


[clang] [llvm] [LoongArch] [CodeGen] Support LoongArch-specific amswap[__db].{b/h} and amadd[__db].{b/h} instructions. (PR #113255)

2024-10-22 Thread Lu Weining via cfe-commits


@@ -205,7 +205,7 @@ void LoongArchTargetInfo::getTargetDefines(const 
LangOptions &Opts,
   // TODO: As more features of the V1.1 ISA are supported, a unified "v1.1"
   // arch feature set will be used to include all sub-features belonging to
   // the V1.1 ISA version.
-  if (HasFeatureFrecipe)
+  if (HasFeatureFrecipe || HasFeatureLAM_BH)

SixWeining wrote:

`||` should be `&&`. cc @Ami-zhang

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


[clang] [llvm] [LoongArch] [CodeGen] Support LoongArch-specific amswap[__db].{b/h} and amadd[__db].{b/h} instructions. (PR #113255)

2024-10-22 Thread Lu Weining via cfe-commits


@@ -0,0 +1,1674 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc --mtriple=loongarch32 --mattr=+d,-lam-bh < %s | FileCheck %s 
--check-prefix=LA32
+; RUN: llc --mtriple=loongarch32 --mattr=+d,+lam-bh < %s | FileCheck %s 
--check-prefix=LA32-LAM-BH

SixWeining wrote:

You may directly use `LA32` if its output is them same as `LA32-LAM-BH`. And 
add a comment explaining why they are the same.

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


[clang] [llvm] [LoongArch] [CodeGen] Support LoongArch-specific amswap[__db].{b/h} and amadd[__db].{b/h} instructions. (PR #113255)

2024-10-22 Thread Lu Weining via cfe-commits


@@ -2088,8 +2088,26 @@ multiclass binary_atomic_op_wd {
 (!cast(inst#"__DB_D"#signed) GPR:$rk, GPR:$rj)>;
 }
 
+// Atomic operation for byte and half word
+multiclass binary_atomic_op_bh {
+  def : Pat<(!cast(op#"_i8_monotonic") GPR:$rj, GPR:$rk),
+(!cast(inst#"_B") GPR:$rk, GPR:$rj)>;
+  def : Pat<(!cast(op#"_i16_monotonic") GPR:$rj, GPR:$rk),
+(!cast(inst#"_H") GPR:$rk, GPR:$rj)>;
+
+  def : Pat<(!cast(op#"_i8") GPR:$rj, GPR:$rk),
+(!cast(inst#"__DB_B") GPR:$rk, GPR:$rj)>;
+  def : Pat<(!cast(op#"_i16") GPR:$rj, GPR:$rk),
+(!cast(inst#"__DB_H") GPR:$rk, GPR:$rj)>;
+}
+
 let Predicates = [IsLA64] in {
 
+let Predicates = [ HasLAM_BH ] in {
+defm : binary_atomic_op_bh<"AMSWAP", "atomic_swap">;
+defm : binary_atomic_op_bh<"AMADD", "atomic_load_add">;
+}
+

SixWeining wrote:

How about `atomic_load_sub_i8/i16`?

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


[clang] [llvm] [LoongArch] [CodeGen] Support LoongArch-specific amswap[__db].{b/h} and amadd[__db].{b/h} instructions. (PR #113255)

2024-10-22 Thread Lu Weining via cfe-commits


@@ -2088,8 +2088,26 @@ multiclass binary_atomic_op_wd {
 (!cast(inst#"__DB_D"#signed) GPR:$rk, GPR:$rj)>;
 }
 
+// Atomic operation for byte and half word
+multiclass binary_atomic_op_bh {
+  def : Pat<(!cast(op#"_i8_monotonic") GPR:$rj, GPR:$rk),
+(!cast(inst#"_B") GPR:$rk, GPR:$rj)>;
+  def : Pat<(!cast(op#"_i16_monotonic") GPR:$rj, GPR:$rk),
+(!cast(inst#"_H") GPR:$rk, GPR:$rj)>;
+
+  def : Pat<(!cast(op#"_i8") GPR:$rj, GPR:$rk),
+(!cast(inst#"__DB_B") GPR:$rk, GPR:$rj)>;
+  def : Pat<(!cast(op#"_i16") GPR:$rj, GPR:$rk),
+(!cast(inst#"__DB_H") GPR:$rk, GPR:$rj)>;
+}
+
 let Predicates = [IsLA64] in {
 
+let Predicates = [ HasLAM_BH ] in {

SixWeining wrote:

Does this predicate override the predicate in line 2104?

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


[clang] [llvm] [LoongArch] [CodeGen] Add options for Clang to generate LoongArch-specific frecipe & frsqrte instructions (PR #109917)

2024-10-17 Thread Lu Weining via cfe-commits

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


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


[clang] [llvm] [LoongArch] [CodeGen] Add options for Clang to generate LoongArch-specific frecipe & frsqrte instructions (PR #109917)

2024-10-17 Thread Lu Weining via cfe-commits

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


[clang] [llvm] [LoongArch] [CodeGen] Support LoongArch-specific amswap[_db].{b/h} and amadd[_db].{b/h} instructions. (PR #113255)

2024-10-23 Thread Lu Weining via cfe-commits

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


[clang] [llvm] [LoongArch] Support LoongArch-specific amswap[_db].{b/h} and amadd[_db].{b/h} instructions (PR #113255)

2024-10-23 Thread Lu Weining via cfe-commits

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


[clang] [llvm] [LoongArch] Support LoongArch-specific amswap[_db].{b/h} and amadd[_db].{b/h} instructions (PR #113255)

2024-10-23 Thread Lu Weining via cfe-commits

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


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


[clang] [llvm] [LoongArch] Support LoongArch-specific amswap[_db].{b/h} and amadd[_db].{b/h} instructions (PR #113255)

2024-10-23 Thread Lu Weining via cfe-commits

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


[clang] [llvm] [LoongArch] Add options for annotate tablejump (PR #102411)

2024-10-12 Thread Lu Weining via cfe-commits


@@ -1888,6 +1888,14 @@ void Clang::AddLoongArchTargetArgs(const ArgList &Args,
 CmdArgs.push_back("-tune-cpu");
 CmdArgs.push_back(Args.MakeArgString(TuneCPU));
   }
+
+  if (Arg *A = Args.getLastArg(options::OPT_mannotate_tablejump,
+   options::OPT_mno_annotate_tablejump)) {
+if (A->getOption().matches(options::OPT_mannotate_tablejump)) {
+  CmdArgs.push_back("-mllvm");
+  CmdArgs.push_back("-loongarch-annotate-tablejump");
+}

SixWeining wrote:

else: -loongarch-annotate-tablejump=false

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


[clang] [llvm] [LoongArch] Add options for annotate tablejump (PR #102411)

2024-10-12 Thread Lu Weining via cfe-commits

https://github.com/SixWeining commented:

Better to add gcc's links to commit message to let people know the background.

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


[clang] [llvm] [LoongArch] Add options for annotate tablejump (PR #102411)

2024-10-12 Thread Lu Weining via cfe-commits


@@ -5340,6 +5340,10 @@ def mno_lasx : Flag<["-"], "mno-lasx">, 
Group,
 def msimd_EQ : Joined<["-"], "msimd=">, Group,
   Flags<[TargetSpecific]>,
   HelpText<"Select the SIMD extension(s) to be enabled in LoongArch either 
'none', 'lsx', 'lasx'.">;
+def mannotate_tablejump : Flag<["-"], "mannotate-tablejump">, 
Group,
+  HelpText<"Enable annotate table jump instruction to correlate it with the 
jump table.">;
+def mno_annotate_tablejump : Flag<["-"], "mno-annotate-tablejump">, 
Group,

SixWeining wrote:

The negative option is useless?

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


[clang] [lld] [lld][LoongArch] Add the relaxation option (PR #111488)

2024-10-14 Thread Lu Weining via cfe-commits

SixWeining wrote:

> How about now?

The patch doesn't touch lld, so my suggestion is "[Driver] Default enable 
LoongArch linker relaxation".

Some additional comments:
- Do we need to consider the `-gsplit-dwarf` issue #56642 resolved by 
https://reviews.llvm.org/D130190 ?
- The ``--no-relax`` option should be passed to linker, see #76432
- Pass ``-X`` to linker to discard a plethora of `.L` symbols due to linker 
relaxation. See https://reviews.llvm.org/D127826


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


[clang] [lld] [lld][LoongArch] Enable relaxation when --relax option is passed (PR #111488)

2024-10-13 Thread Lu Weining via cfe-commits


@@ -1462,6 +1462,8 @@ template  void 
Writer::finalizeAddressDependentContent() {
   for (;;) {
 bool changed = ctx.target->needsThunks
? tc.createThunks(pass, ctx.outputSections)
+   : ctx.arg.emachine == EM_LOONGARCH && !ctx.arg.relax

SixWeining wrote:

> Yes, it was an oversight. So for scenarios outside of align, is it necessary 
> to determine whether or not to apply relaxation via the incoming link 
> parameter, i.e. --relax? For example, in the relax function

I'm afraid it's not necessary because R_LARCH_RELAX is converted to R_NONE by 
function `getRelExpr` when `--no-relax`.
```
  case R_LARCH_RELAX:
return ctx.arg.relax ? R_RELAX_HINT : R_NONE;
  case R_LARCH_ALIGN:
return R_RELAX_HINT
```

Is it correct? @MQ-mengqing 


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


[clang] [llvm] [LoongArch] Support LoongArch-specific amswap[_db].{b/h} and amadd[_db].{b/h} instructions (PR #113255)

2024-10-24 Thread Lu Weining via cfe-commits

SixWeining wrote:

> Just a heads up, I think this broke documentation builds. After bisecting it 
> points to this commit.

Thanks. Fixed by #113632.

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


[clang] [LoongArch] fix description of clang option -m[no-]lam-bh (PR #113632)

2024-10-24 Thread Lu Weining via cfe-commits

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


[clang] [LoongArch] fix description of clang option -m[no-]lam-bh (PR #113632)

2024-10-24 Thread Lu Weining via cfe-commits

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


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


[clang] [LoongArch][Clang] Make the parameters and return value of {x,}vshuf.b builtins `signed char` vectors (PR #114512)

2024-11-03 Thread Lu Weining via cfe-commits

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


[clang] [LoongArch][Clang] Make the parameters and return value of {x,}vshuf.b builtins `signed char` vectors (PR #114512)

2024-11-03 Thread Lu Weining via cfe-commits

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


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


[clang] [LoongArch][Clang] Make the parameters and return value of {x,}vxor.v builti ns `unsigned char` vectors (PR #114513)

2024-11-04 Thread Lu Weining via cfe-commits

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

LGTM. Thanks.

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


[clang] [LoongArch][Clang] Make the parameters and return value of {x,}vxor.v builti ns `unsigned char` vectors (PR #114513)

2024-11-04 Thread Lu Weining via cfe-commits

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


  1   2   >