https://github.com/Ami-zhang created https://github.com/llvm/llvm-project/pull/100056
This commit is to enable 128 vector feature by default, in order to be consistent with gcc. >From d6e0e004d46194008a73d2de510a706932d11776 Mon Sep 17 00:00:00 2001 From: Ami-zhang <zhangli...@loongson.cn> Date: Thu, 18 Jul 2024 09:33:35 +0800 Subject: [PATCH] [LoongArch] Enable 128-bits vector by default This commit is to enable 128 vector feature by default, in order to be consistent with gcc. --- .../lib/Driver/ToolChains/Arch/LoongArch.cpp | 76 +++++++++++-------- clang/test/Driver/loongarch-features.c | 2 +- clang/test/Driver/loongarch-mlasx.c | 6 +- clang/test/Driver/loongarch-msimd.c | 4 +- clang/test/Driver/loongarch-msingle-float.c | 4 +- clang/test/Driver/loongarch-msoft-float.c | 4 +- clang/test/Preprocessor/init-loongarch.c | 8 +- 7 files changed, 60 insertions(+), 44 deletions(-) diff --git a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp index 4a2b9efc9ffad..b0756c42a6e4c 100644 --- a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp +++ b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp @@ -127,6 +127,11 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D, const llvm::Triple &Triple, const ArgList &Args, std::vector<StringRef> &Features) { + // Enable the `lsx` feature on 64-bit LoongArch by default. + if (Triple.isLoongArch64() && + (!Args.hasArg(clang::driver::options::OPT_march_EQ))) + Features.push_back("+lsx"); + std::string ArchName; if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) ArchName = A->getValue(); @@ -145,9 +150,11 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D, } else if (A->getOption().matches(options::OPT_msingle_float)) { Features.push_back("+f"); Features.push_back("-d"); + Features.push_back("-lsx"); } else /*Soft-float*/ { Features.push_back("-f"); Features.push_back("-d"); + Features.push_back("-lsx"); } } else if (const Arg *A = Args.getLastArg(options::OPT_mfpu_EQ)) { StringRef FPU = A->getValue(); @@ -157,9 +164,11 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D, } else if (FPU == "32") { Features.push_back("+f"); Features.push_back("-d"); + Features.push_back("-lsx"); } else if (FPU == "0" || FPU == "none") { Features.push_back("-f"); Features.push_back("-d"); + Features.push_back("-lsx"); } else { D.Diag(diag::err_drv_loongarch_invalid_mfpu_EQ) << FPU; } @@ -174,6 +183,42 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D, A->ignoreTargetSpecific(); if (Arg *A = Args.getLastArgNoClaim(options::OPT_mfpu_EQ)) A->ignoreTargetSpecific(); + if (Arg *A = Args.getLastArgNoClaim(options::OPT_msimd_EQ)) + A->ignoreTargetSpecific(); + + // Select lsx/lasx feature determined by -msimd=. + // Option -msimd= precedes -m[no-]lsx and -m[no-]lasx. + if (const Arg *A = Args.getLastArg(options::OPT_msimd_EQ)) { + StringRef MSIMD = A->getValue(); + if (MSIMD == "lsx") { + // Option -msimd=lsx depends on 64-bit FPU. + // -m*-float and -mfpu=none/0/32 conflict with -msimd=lsx. + if (llvm::find(Features, "-d") != Features.end()) + D.Diag(diag::err_drv_loongarch_wrong_fpu_width) << /*LSX*/ 0; + else + Features.push_back("+lsx"); + } else if (MSIMD == "lasx") { + // Option -msimd=lasx depends on 64-bit FPU and LSX. + // -m*-float, -mfpu=none/0/32 and -mno-lsx conflict with -msimd=lasx. + if (llvm::find(Features, "-d") != Features.end()) + D.Diag(diag::err_drv_loongarch_wrong_fpu_width) << /*LASX*/ 1; + else if (llvm::find(Features, "-lsx") != Features.end()) + D.Diag(diag::err_drv_loongarch_invalid_simd_option_combination); + + // The command options do not contain -mno-lasx. + if (!Args.getLastArg(options::OPT_mno_lasx)) { + Features.push_back("+lsx"); + Features.push_back("+lasx"); + } + } else if (MSIMD == "none") { + if (llvm::find(Features, "+lsx") != Features.end()) + Features.push_back("-lsx"); + if (llvm::find(Features, "+lasx") != Features.end()) + Features.push_back("-lasx"); + } else { + D.Diag(diag::err_drv_loongarch_invalid_msimd_EQ) << MSIMD; + } + } // Select lsx feature determined by -m[no-]lsx. if (const Arg *A = Args.getLastArg(options::OPT_mlsx, options::OPT_mno_lsx)) { @@ -197,8 +242,6 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D, if (A->getOption().matches(options::OPT_mlasx)) { if (llvm::find(Features, "-d") != Features.end()) D.Diag(diag::err_drv_loongarch_wrong_fpu_width) << /*LASX*/ 1; - else if (llvm::find(Features, "-lsx") != Features.end()) - D.Diag(diag::err_drv_loongarch_invalid_simd_option_combination); else { /*-mlasx*/ Features.push_back("+lsx"); Features.push_back("+lasx"); @@ -206,35 +249,6 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D, } else /*-mno-lasx*/ Features.push_back("-lasx"); } - - // Select lsx/lasx feature determined by -msimd=. - // Option -msimd= has lower priority than -m[no-]lsx and -m[no-]lasx. - if (const Arg *A = Args.getLastArg(options::OPT_msimd_EQ)) { - StringRef MSIMD = A->getValue(); - if (MSIMD == "lsx") { - // Option -msimd=lsx depends on 64-bit FPU. - // -m*-float and -mfpu=none/0/32 conflict with -mlsx. - if (llvm::find(Features, "-d") != Features.end()) - D.Diag(diag::err_drv_loongarch_wrong_fpu_width) << /*LSX*/ 0; - // The previous option does not contain feature -lsx. - else if (llvm::find(Features, "-lsx") == Features.end()) - Features.push_back("+lsx"); - } else if (MSIMD == "lasx") { - // Option -msimd=lasx depends on 64-bit FPU and LSX. - // -m*-float and -mfpu=none/0/32 conflict with -mlsx. - if (llvm::find(Features, "-d") != Features.end()) - D.Diag(diag::err_drv_loongarch_wrong_fpu_width) << /*LASX*/ 1; - else if (llvm::find(Features, "-lsx") != Features.end()) - D.Diag(diag::err_drv_loongarch_invalid_simd_option_combination); - // The previous option does not contain feature -lasx. - else if (llvm::find(Features, "-lasx") == Features.end()) { - Features.push_back("+lsx"); - Features.push_back("+lasx"); - } - } else if (MSIMD != "none") { - D.Diag(diag::err_drv_loongarch_invalid_msimd_EQ) << MSIMD; - } - } } std::string loongarch::postProcessTargetCPUString(const std::string &CPU, diff --git a/clang/test/Driver/loongarch-features.c b/clang/test/Driver/loongarch-features.c index 3cdf3ba3d23e1..90634bbcf0035 100644 --- a/clang/test/Driver/loongarch-features.c +++ b/clang/test/Driver/loongarch-features.c @@ -2,7 +2,7 @@ // RUN: %clang --target=loongarch64 -S -emit-llvm %s -o - | FileCheck %s --check-prefix=LA64 // LA32: "target-features"="+32bit" -// LA64: "target-features"="+64bit,+d,+f,+ual" +// LA64: "target-features"="+64bit,+d,+f,+lsx,+ual" int foo(void) { return 3; diff --git a/clang/test/Driver/loongarch-mlasx.c b/clang/test/Driver/loongarch-mlasx.c index 0b934f125c9e4..87634ff5a9a40 100644 --- a/clang/test/Driver/loongarch-mlasx.c +++ b/clang/test/Driver/loongarch-mlasx.c @@ -5,7 +5,7 @@ // RUN: %clang --target=loongarch64 -mno-lasx -fsyntax-only %s -### 2>&1 | \ // RUN: FileCheck %s --check-prefix=CC1-NOLASX // RUN: %clang --target=loongarch64 -mlasx -mno-lasx -fsyntax-only %s -### 2>&1 | \ -// RUN: FileCheck %s --check-prefix=CC1-NOLASX +// RUN: FileCheck %s --check-prefix=CC1-LSX // RUN: %clang --target=loongarch64 -mno-lasx -mlasx -fsyntax-only %s -### 2>&1 | \ // RUN: FileCheck %s --check-prefix=CC1-LASX // RUN: %clang --target=loongarch64 -mlsx -mlasx -fsyntax-only %s -### 2>&1 | \ @@ -18,7 +18,7 @@ // RUN: %clang --target=loongarch64 -mno-lasx -S -emit-llvm %s -o - | \ // RUN: FileCheck %s --check-prefix=IR-NOLASX // RUN: %clang --target=loongarch64 -mlasx -mno-lasx -S -emit-llvm %s -o - | \ -// RUN: FileCheck %s --check-prefix=IR-NOLASX +// RUN: FileCheck %s --check-prefix=IR-LSX // RUN: %clang --target=loongarch64 -mno-lasx -mlasx -S -emit-llvm %s -o - | \ // RUN: FileCheck %s --check-prefix=IR-LASX // RUN: %clang --target=loongarch64 -mlsx -mlasx -S -emit-llvm %s -o - | \ @@ -26,9 +26,11 @@ // RUN: %clang --target=loongarch64 -mlasx -mlsx -S -emit-llvm %s -o - | \ // RUN: FileCheck %s --check-prefix=IR-LASX +// CC1-LSX: "-target-feature" "+lsx" // CC1-LASX: "-target-feature" "+lsx" "-target-feature" "+lasx" // CC1-NOLASX: "-target-feature" "-lasx" +// IR-LSX: attributes #[[#]] ={{.*}}"target-features"="{{(.*,)?}}+lsx{{(,.*)?}}" // IR-LASX: attributes #[[#]] ={{.*}}"target-features"="{{(.*,)?}}+lasx{{(,.*)?}}" // IR-NOLASX: attributes #[[#]] ={{.*}}"target-features"="{{(.*,)?}}-lasx{{(,.*)?}}" diff --git a/clang/test/Driver/loongarch-msimd.c b/clang/test/Driver/loongarch-msimd.c index cd463300c8747..49d298e1b2e3f 100644 --- a/clang/test/Driver/loongarch-msimd.c +++ b/clang/test/Driver/loongarch-msimd.c @@ -75,9 +75,9 @@ // RUN: FileCheck %s --check-prefixes=LSX,LASX // RUN: %clang --target=loongarch64 -mlasx -mno-lasx -msimd=lasx -fsyntax-only %s -### 2>&1 | \ -// RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX +// RUN: FileCheck %s --check-prefixes=LSX,NOLASX // RUN: %clang --target=loongarch64 -mno-lasx -msimd=lasx -fsyntax-only %s -### 2>&1 | \ -// RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX +// RUN: FileCheck %s --check-prefixes=LSX,NOLASX // RUN: %clang --target=loongarch64 -mlasx -mno-lasx -mlsx -msimd=lasx -fsyntax-only %s -### 2>&1 | \ // RUN: FileCheck %s --check-prefixes=LSX,NOLASX diff --git a/clang/test/Driver/loongarch-msingle-float.c b/clang/test/Driver/loongarch-msingle-float.c index bd9b3e8a8c019..4eb0865b53a59 100644 --- a/clang/test/Driver/loongarch-msingle-float.c +++ b/clang/test/Driver/loongarch-msingle-float.c @@ -11,10 +11,10 @@ // WARN: warning: ignoring '-mabi=lp64s' as it conflicts with that implied by '-msingle-float' (lp64f) // WARN: warning: ignoring '-mfpu=64' as it conflicts with that implied by '-msingle-float' (32) -// CC1: "-target-feature" "+f"{{.*}} "-target-feature" "-d" +// CC1: "-target-feature" "+f"{{.*}} "-target-feature" "-d" "-target-feature" "-lsx" // CC1: "-target-abi" "lp64f" -// IR: attributes #[[#]] ={{.*}}"target-features"="{{(.*,)?}}+f,{{(.*,)?}}-d" +// IR: attributes #[[#]] ={{.*}}"target-features"="{{(.*,)?}}+f,{{(.*,)?}}-d,-lsx" int foo(void) { return 3; diff --git a/clang/test/Driver/loongarch-msoft-float.c b/clang/test/Driver/loongarch-msoft-float.c index 0e5121ac84b4c..ebf27fb00e309 100644 --- a/clang/test/Driver/loongarch-msoft-float.c +++ b/clang/test/Driver/loongarch-msoft-float.c @@ -11,10 +11,10 @@ // WARN: warning: ignoring '-mabi=lp64d' as it conflicts with that implied by '-msoft-float' (lp64s) // WARN: warning: ignoring '-mfpu=64' as it conflicts with that implied by '-msoft-float' (0) -// CC1: "-target-feature" "-f"{{.*}} "-target-feature" "-d" +// CC1: "-target-feature" "-f"{{.*}} "-target-feature" "-d" "-target-feature" "-lsx" // CC1: "-target-abi" "lp64s" -// IR: attributes #[[#]] ={{.*}}"target-features"="{{(.*,)?}}-d,{{(.*,)?}}-f{{(,.*)?}}" +// IR: attributes #[[#]] ={{.*}}"target-features"="{{(.*,)?}}-d,{{(.*,)?}}-f,-lsx" int foo(void) { return 3; diff --git a/clang/test/Preprocessor/init-loongarch.c b/clang/test/Preprocessor/init-loongarch.c index 182f904b76592..cb3ddef11401e 100644 --- a/clang/test/Preprocessor/init-loongarch.c +++ b/clang/test/Preprocessor/init-loongarch.c @@ -824,6 +824,8 @@ // RUN: | FileCheck --match-full-lines --check-prefix=MLSX %s // RUN: %clang --target=loongarch64 -mlsx -mno-lasx -x c -E -dM %s -o - \ // RUN: | FileCheck --match-full-lines --check-prefix=MLSX %s +// RUN: %clang --target=loongarch64 -mno-lasx -x c -E -dM %s -o - \ +// RUN: | FileCheck --match-full-lines --check-prefix=MLSX %s // RUN: %clang --target=loongarch64 -mno-lasx -mlsx -x c -E -dM %s -o - \ // RUN: | FileCheck --match-full-lines --check-prefix=MLSX %s // MLSX-NOT: #define __loongarch_asx @@ -832,12 +834,12 @@ // RUN: %clang --target=loongarch64 -mlasx -x c -E -dM %s -o - \ // RUN: | FileCheck --match-full-lines --check-prefix=MLASX %s -// RUN: %clang --target=loongarch64 -mno-lasx -mlasx -x c -E -dM %s -o - \ -// RUN: | FileCheck --match-full-lines --check-prefix=MLASX %s // RUN: %clang --target=loongarch64 -mlsx -mlasx -x c -E -dM %s -o - \ // RUN: | FileCheck --match-full-lines --check-prefix=MLASX %s // RUN: %clang --target=loongarch64 -mlasx -mlsx -x c -E -dM %s -o - \ // RUN: | FileCheck --match-full-lines --check-prefix=MLASX %s +// RUN: %clang --target=loongarch64 -mno-lasx -mlasx -x c -E -dM %s -o - \ +// RUN: | FileCheck --match-full-lines --check-prefix=MLASX %s // MLASX: #define __loongarch_asx 1 // MLASX: #define __loongarch_simd_width 256 // MLASX: #define __loongarch_sx 1 @@ -850,8 +852,6 @@ // RUN: | FileCheck --match-full-lines --check-prefix=MNO-LSX %s // RUN: %clang --target=loongarch64 -mno-lasx -mno-lsx -x c -E -dM %s -o - \ // RUN: | FileCheck --match-full-lines --check-prefix=MNO-LSX %s -// RUN: %clang --target=loongarch64 -mno-lasx -x c -E -dM %s -o - \ -// RUN: | FileCheck --match-full-lines --check-prefix=MNO-LSX %s // MNO-LSX-NOT: #define __loongarch_asx // MNO-LSX-NOT: #define __loongarch_simd_width // MNO-LSX-NOT: #define __loongarch_sx _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits