Skip to content

Commit df03a8a

Browse files
Ami-zhangyuxuanchen1997
authored andcommitted
[LoongArch] Enable 128-bits vector by default (#100056)
Summary: This commit is to enable 128 vector feature by default, in order to be consistent with gcc. Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60251089
1 parent 8d1771d commit df03a8a

File tree

7 files changed

+60
-44
lines changed

7 files changed

+60
-44
lines changed

clang/lib/Driver/ToolChains/Arch/LoongArch.cpp

+45-31
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
127127
const llvm::Triple &Triple,
128128
const ArgList &Args,
129129
std::vector<StringRef> &Features) {
130+
// Enable the `lsx` feature on 64-bit LoongArch by default.
131+
if (Triple.isLoongArch64() &&
132+
(!Args.hasArgNoClaim(clang::driver::options::OPT_march_EQ)))
133+
Features.push_back("+lsx");
134+
130135
std::string ArchName;
131136
if (const Arg *A = Args.getLastArg(options::OPT_march_EQ))
132137
ArchName = A->getValue();
@@ -145,9 +150,11 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
145150
} else if (A->getOption().matches(options::OPT_msingle_float)) {
146151
Features.push_back("+f");
147152
Features.push_back("-d");
153+
Features.push_back("-lsx");
148154
} else /*Soft-float*/ {
149155
Features.push_back("-f");
150156
Features.push_back("-d");
157+
Features.push_back("-lsx");
151158
}
152159
} else if (const Arg *A = Args.getLastArg(options::OPT_mfpu_EQ)) {
153160
StringRef FPU = A->getValue();
@@ -157,9 +164,11 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
157164
} else if (FPU == "32") {
158165
Features.push_back("+f");
159166
Features.push_back("-d");
167+
Features.push_back("-lsx");
160168
} else if (FPU == "0" || FPU == "none") {
161169
Features.push_back("-f");
162170
Features.push_back("-d");
171+
Features.push_back("-lsx");
163172
} else {
164173
D.Diag(diag::err_drv_loongarch_invalid_mfpu_EQ) << FPU;
165174
}
@@ -174,6 +183,42 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
174183
A->ignoreTargetSpecific();
175184
if (Arg *A = Args.getLastArgNoClaim(options::OPT_mfpu_EQ))
176185
A->ignoreTargetSpecific();
186+
if (Arg *A = Args.getLastArgNoClaim(options::OPT_msimd_EQ))
187+
A->ignoreTargetSpecific();
188+
189+
// Select lsx/lasx feature determined by -msimd=.
190+
// Option -msimd= precedes -m[no-]lsx and -m[no-]lasx.
191+
if (const Arg *A = Args.getLastArg(options::OPT_msimd_EQ)) {
192+
StringRef MSIMD = A->getValue();
193+
if (MSIMD == "lsx") {
194+
// Option -msimd=lsx depends on 64-bit FPU.
195+
// -m*-float and -mfpu=none/0/32 conflict with -msimd=lsx.
196+
if (llvm::find(Features, "-d") != Features.end())
197+
D.Diag(diag::err_drv_loongarch_wrong_fpu_width) << /*LSX*/ 0;
198+
else
199+
Features.push_back("+lsx");
200+
} else if (MSIMD == "lasx") {
201+
// Option -msimd=lasx depends on 64-bit FPU and LSX.
202+
// -m*-float, -mfpu=none/0/32 and -mno-lsx conflict with -msimd=lasx.
203+
if (llvm::find(Features, "-d") != Features.end())
204+
D.Diag(diag::err_drv_loongarch_wrong_fpu_width) << /*LASX*/ 1;
205+
else if (llvm::find(Features, "-lsx") != Features.end())
206+
D.Diag(diag::err_drv_loongarch_invalid_simd_option_combination);
207+
208+
// The command options do not contain -mno-lasx.
209+
if (!Args.getLastArg(options::OPT_mno_lasx)) {
210+
Features.push_back("+lsx");
211+
Features.push_back("+lasx");
212+
}
213+
} else if (MSIMD == "none") {
214+
if (llvm::find(Features, "+lsx") != Features.end())
215+
Features.push_back("-lsx");
216+
if (llvm::find(Features, "+lasx") != Features.end())
217+
Features.push_back("-lasx");
218+
} else {
219+
D.Diag(diag::err_drv_loongarch_invalid_msimd_EQ) << MSIMD;
220+
}
221+
}
177222

178223
// Select lsx feature determined by -m[no-]lsx.
179224
if (const Arg *A = Args.getLastArg(options::OPT_mlsx, options::OPT_mno_lsx)) {
@@ -197,44 +242,13 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
197242
if (A->getOption().matches(options::OPT_mlasx)) {
198243
if (llvm::find(Features, "-d") != Features.end())
199244
D.Diag(diag::err_drv_loongarch_wrong_fpu_width) << /*LASX*/ 1;
200-
else if (llvm::find(Features, "-lsx") != Features.end())
201-
D.Diag(diag::err_drv_loongarch_invalid_simd_option_combination);
202245
else { /*-mlasx*/
203246
Features.push_back("+lsx");
204247
Features.push_back("+lasx");
205248
}
206249
} else /*-mno-lasx*/
207250
Features.push_back("-lasx");
208251
}
209-
210-
// Select lsx/lasx feature determined by -msimd=.
211-
// Option -msimd= has lower priority than -m[no-]lsx and -m[no-]lasx.
212-
if (const Arg *A = Args.getLastArg(options::OPT_msimd_EQ)) {
213-
StringRef MSIMD = A->getValue();
214-
if (MSIMD == "lsx") {
215-
// Option -msimd=lsx depends on 64-bit FPU.
216-
// -m*-float and -mfpu=none/0/32 conflict with -mlsx.
217-
if (llvm::find(Features, "-d") != Features.end())
218-
D.Diag(diag::err_drv_loongarch_wrong_fpu_width) << /*LSX*/ 0;
219-
// The previous option does not contain feature -lsx.
220-
else if (llvm::find(Features, "-lsx") == Features.end())
221-
Features.push_back("+lsx");
222-
} else if (MSIMD == "lasx") {
223-
// Option -msimd=lasx depends on 64-bit FPU and LSX.
224-
// -m*-float and -mfpu=none/0/32 conflict with -mlsx.
225-
if (llvm::find(Features, "-d") != Features.end())
226-
D.Diag(diag::err_drv_loongarch_wrong_fpu_width) << /*LASX*/ 1;
227-
else if (llvm::find(Features, "-lsx") != Features.end())
228-
D.Diag(diag::err_drv_loongarch_invalid_simd_option_combination);
229-
// The previous option does not contain feature -lasx.
230-
else if (llvm::find(Features, "-lasx") == Features.end()) {
231-
Features.push_back("+lsx");
232-
Features.push_back("+lasx");
233-
}
234-
} else if (MSIMD != "none") {
235-
D.Diag(diag::err_drv_loongarch_invalid_msimd_EQ) << MSIMD;
236-
}
237-
}
238252
}
239253

240254
std::string loongarch::postProcessTargetCPUString(const std::string &CPU,

clang/test/Driver/loongarch-features.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// RUN: %clang --target=loongarch64 -S -emit-llvm %s -o - | FileCheck %s --check-prefix=LA64
33

44
// LA32: "target-features"="+32bit"
5-
// LA64: "target-features"="+64bit,+d,+f,+ual"
5+
// LA64: "target-features"="+64bit,+d,+f,+lsx,+ual"
66

77
int foo(void) {
88
return 3;

clang/test/Driver/loongarch-mlasx.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// RUN: %clang --target=loongarch64 -mno-lasx -fsyntax-only %s -### 2>&1 | \
66
// RUN: FileCheck %s --check-prefix=CC1-NOLASX
77
// RUN: %clang --target=loongarch64 -mlasx -mno-lasx -fsyntax-only %s -### 2>&1 | \
8-
// RUN: FileCheck %s --check-prefix=CC1-NOLASX
8+
// RUN: FileCheck %s --check-prefix=CC1-LSX
99
// RUN: %clang --target=loongarch64 -mno-lasx -mlasx -fsyntax-only %s -### 2>&1 | \
1010
// RUN: FileCheck %s --check-prefix=CC1-LASX
1111
// RUN: %clang --target=loongarch64 -mlsx -mlasx -fsyntax-only %s -### 2>&1 | \
@@ -18,17 +18,19 @@
1818
// RUN: %clang --target=loongarch64 -mno-lasx -S -emit-llvm %s -o - | \
1919
// RUN: FileCheck %s --check-prefix=IR-NOLASX
2020
// RUN: %clang --target=loongarch64 -mlasx -mno-lasx -S -emit-llvm %s -o - | \
21-
// RUN: FileCheck %s --check-prefix=IR-NOLASX
21+
// RUN: FileCheck %s --check-prefix=IR-LSX
2222
// RUN: %clang --target=loongarch64 -mno-lasx -mlasx -S -emit-llvm %s -o - | \
2323
// RUN: FileCheck %s --check-prefix=IR-LASX
2424
// RUN: %clang --target=loongarch64 -mlsx -mlasx -S -emit-llvm %s -o - | \
2525
// RUN: FileCheck %s --check-prefix=IR-LASX
2626
// RUN: %clang --target=loongarch64 -mlasx -mlsx -S -emit-llvm %s -o - | \
2727
// RUN: FileCheck %s --check-prefix=IR-LASX
2828

29+
// CC1-LSX: "-target-feature" "+lsx"
2930
// CC1-LASX: "-target-feature" "+lsx" "-target-feature" "+lasx"
3031
// CC1-NOLASX: "-target-feature" "-lasx"
3132

33+
// IR-LSX: attributes #[[#]] ={{.*}}"target-features"="{{(.*,)?}}+lsx{{(,.*)?}}"
3234
// IR-LASX: attributes #[[#]] ={{.*}}"target-features"="{{(.*,)?}}+lasx{{(,.*)?}}"
3335
// IR-NOLASX: attributes #[[#]] ={{.*}}"target-features"="{{(.*,)?}}-lasx{{(,.*)?}}"
3436

clang/test/Driver/loongarch-msimd.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@
7575
// RUN: FileCheck %s --check-prefixes=LSX,LASX
7676

7777
// RUN: %clang --target=loongarch64 -mlasx -mno-lasx -msimd=lasx -fsyntax-only %s -### 2>&1 | \
78-
// RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX
78+
// RUN: FileCheck %s --check-prefixes=LSX,NOLASX
7979
// RUN: %clang --target=loongarch64 -mno-lasx -msimd=lasx -fsyntax-only %s -### 2>&1 | \
80-
// RUN: FileCheck %s --check-prefixes=NOLSX,NOLASX
80+
// RUN: FileCheck %s --check-prefixes=LSX,NOLASX
8181

8282
// RUN: %clang --target=loongarch64 -mlasx -mno-lasx -mlsx -msimd=lasx -fsyntax-only %s -### 2>&1 | \
8383
// RUN: FileCheck %s --check-prefixes=LSX,NOLASX

clang/test/Driver/loongarch-msingle-float.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
// WARN: warning: ignoring '-mabi=lp64s' as it conflicts with that implied by '-msingle-float' (lp64f)
1212
// WARN: warning: ignoring '-mfpu=64' as it conflicts with that implied by '-msingle-float' (32)
1313

14-
// CC1: "-target-feature" "+f"{{.*}} "-target-feature" "-d"
14+
// CC1: "-target-feature" "+f"{{.*}} "-target-feature" "-d" "-target-feature" "-lsx"
1515
// CC1: "-target-abi" "lp64f"
1616

17-
// IR: attributes #[[#]] ={{.*}}"target-features"="{{(.*,)?}}+f,{{(.*,)?}}-d"
17+
// IR: attributes #[[#]] ={{.*}}"target-features"="{{(.*,)?}}+f,{{(.*,)?}}-d,-lsx"
1818

1919
int foo(void) {
2020
return 3;

clang/test/Driver/loongarch-msoft-float.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
// WARN: warning: ignoring '-mabi=lp64d' as it conflicts with that implied by '-msoft-float' (lp64s)
1212
// WARN: warning: ignoring '-mfpu=64' as it conflicts with that implied by '-msoft-float' (0)
1313

14-
// CC1: "-target-feature" "-f"{{.*}} "-target-feature" "-d"
14+
// CC1: "-target-feature" "-f"{{.*}} "-target-feature" "-d" "-target-feature" "-lsx"
1515
// CC1: "-target-abi" "lp64s"
1616

17-
// IR: attributes #[[#]] ={{.*}}"target-features"="{{(.*,)?}}-d,{{(.*,)?}}-f{{(,.*)?}}"
17+
// IR: attributes #[[#]] ={{.*}}"target-features"="{{(.*,)?}}-d,{{(.*,)?}}-f,-lsx"
1818

1919
int foo(void) {
2020
return 3;

clang/test/Preprocessor/init-loongarch.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,8 @@
824824
// RUN: | FileCheck --match-full-lines --check-prefix=MLSX %s
825825
// RUN: %clang --target=loongarch64 -mlsx -mno-lasx -x c -E -dM %s -o - \
826826
// RUN: | FileCheck --match-full-lines --check-prefix=MLSX %s
827+
// RUN: %clang --target=loongarch64 -mno-lasx -x c -E -dM %s -o - \
828+
// RUN: | FileCheck --match-full-lines --check-prefix=MLSX %s
827829
// RUN: %clang --target=loongarch64 -mno-lasx -mlsx -x c -E -dM %s -o - \
828830
// RUN: | FileCheck --match-full-lines --check-prefix=MLSX %s
829831
// MLSX-NOT: #define __loongarch_asx
@@ -832,12 +834,12 @@
832834

833835
// RUN: %clang --target=loongarch64 -mlasx -x c -E -dM %s -o - \
834836
// RUN: | FileCheck --match-full-lines --check-prefix=MLASX %s
835-
// RUN: %clang --target=loongarch64 -mno-lasx -mlasx -x c -E -dM %s -o - \
836-
// RUN: | FileCheck --match-full-lines --check-prefix=MLASX %s
837837
// RUN: %clang --target=loongarch64 -mlsx -mlasx -x c -E -dM %s -o - \
838838
// RUN: | FileCheck --match-full-lines --check-prefix=MLASX %s
839839
// RUN: %clang --target=loongarch64 -mlasx -mlsx -x c -E -dM %s -o - \
840840
// RUN: | FileCheck --match-full-lines --check-prefix=MLASX %s
841+
// RUN: %clang --target=loongarch64 -mno-lasx -mlasx -x c -E -dM %s -o - \
842+
// RUN: | FileCheck --match-full-lines --check-prefix=MLASX %s
841843
// MLASX: #define __loongarch_asx 1
842844
// MLASX: #define __loongarch_simd_width 256
843845
// MLASX: #define __loongarch_sx 1
@@ -850,8 +852,6 @@
850852
// RUN: | FileCheck --match-full-lines --check-prefix=MNO-LSX %s
851853
// RUN: %clang --target=loongarch64 -mno-lasx -mno-lsx -x c -E -dM %s -o - \
852854
// RUN: | FileCheck --match-full-lines --check-prefix=MNO-LSX %s
853-
// RUN: %clang --target=loongarch64 -mno-lasx -x c -E -dM %s -o - \
854-
// RUN: | FileCheck --match-full-lines --check-prefix=MNO-LSX %s
855855
// MNO-LSX-NOT: #define __loongarch_asx
856856
// MNO-LSX-NOT: #define __loongarch_simd_width
857857
// MNO-LSX-NOT: #define __loongarch_sx

0 commit comments

Comments
 (0)