public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH][committed] aarch64: Suggest an -mcpu option when user passes CPU name to -march
@ 2022-09-05 13:35 Kyrylo Tkachov
  2022-09-05 13:42 ` Richard Earnshaw
  0 siblings, 1 reply; 3+ messages in thread
From: Kyrylo Tkachov @ 2022-09-05 13:35 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1095 bytes --]

Hi all,

This small patch helps users who confuse -march and -mcpu on AArch64.
Sometimes users pass -march with a CPU name, where they most likely wanted to
use -mcpu, which would select the right architecture features *and* tune for
their desired CPU. Currently we'll just error out with an unkown architecture
message and list the valid architecture options.
With this patch we check if their string matches a known CPU and suggest they
use an -mcpu option instead.

So compiling with -march=neoverse-n1 will now give the error:
cc1: error: unknown value 'neoverse-n1' for '-march'
cc1: note: valid arguments are: armv8-a armv8.1-a armv8.2-a armv8.3-a armv8.4-a armv8.5-a armv8.6-a armv8.7-a armv8.8-a armv8-r armv9-a
cc1: note: did you mean '-mcpu=neoverse-n1'?

Bootstrapped and tested on aarch64-none-linux-gnu.
Pushing to trunk.
Thanks,
Kyrill

gcc/ChangeLog:

	* config/aarch64/aarch64.cc (aarch64_validate_march): Check if invalid arch
	string is a valid -mcpu string and emit hint.

gcc/testsuite/ChangeLog:

	* gcc.target/aarch64/spellcheck_10.c: New test.

[-- Attachment #2: mcpu.patch --]
[-- Type: application/octet-stream, Size: 1632 bytes --]

diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
index 4b486aeea90ea2afb9cdd96a4dbe15c5bb2abd7a..1d0b14778a9b38ca14e1ec3248c57dc6b9fa2a75 100644
--- a/gcc/config/aarch64/aarch64.cc
+++ b/gcc/config/aarch64/aarch64.cc
@@ -18018,6 +18018,11 @@ aarch64_validate_march (const char *str, const struct processor **res,
       case AARCH64_PARSE_INVALID_ARG:
 	error ("unknown value %qs for %<-march%>", str);
 	aarch64_print_hint_for_arch (str);
+	/* A common user error is confusing -march and -mcpu.
+	   If the -march string matches a known CPU suggest -mcpu.  */
+	parse_res = aarch64_parse_cpu (str, res, isa_flags, &invalid_extension);
+	if (parse_res == AARCH64_PARSE_OK)
+	  inform (input_location, "did you mean %<-mcpu=%s%>?", str);
 	break;
       case AARCH64_PARSE_INVALID_FEATURE:
 	error ("invalid feature modifier %qs in %<-march=%s%>",
diff --git a/gcc/testsuite/gcc.target/aarch64/spellcheck_10.c b/gcc/testsuite/gcc.target/aarch64/spellcheck_10.c
new file mode 100644
index 0000000000000000000000000000000000000000..08540c9c25bc2a460794f9a93c8ea7ceafaad38c
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/spellcheck_10.c
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-skip-if "" { *-*-* } { "-march=*" } { "" } } */
+/* { dg-skip-if "" { *-*-* } { "-mcpu=*" } { "" } } */
+/* { dg-options "-march=neoverse-n1" } */
+
+void
+foo ()
+{
+}
+
+/* { dg-error "unknown value .neoverse-n1. for .-march."  "" { target *-*-* } 0 } */
+/* { dg-message "valid arguments are: \[^\n\r]*"  "" { target *-*-* } 0 } */
+/* { dg-message "did you mean .-mcpu=neoverse-n1.?"  "" { target *-*-* } 0 } */

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH][committed] aarch64: Suggest an -mcpu option when user passes CPU name to -march
  2022-09-05 13:35 [PATCH][committed] aarch64: Suggest an -mcpu option when user passes CPU name to -march Kyrylo Tkachov
@ 2022-09-05 13:42 ` Richard Earnshaw
  2022-09-06  9:53   ` Kyrylo Tkachov
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Earnshaw @ 2022-09-05 13:42 UTC (permalink / raw)
  To: Kyrylo Tkachov, gcc-patches



On 05/09/2022 14:35, Kyrylo Tkachov via Gcc-patches wrote:
> Hi all,
> 
> This small patch helps users who confuse -march and -mcpu on AArch64.
> Sometimes users pass -march with a CPU name, where they most likely wanted to
> use -mcpu, which would select the right architecture features *and* tune for
> their desired CPU. Currently we'll just error out with an unkown architecture
> message and list the valid architecture options.
> With this patch we check if their string matches a known CPU and suggest they
> use an -mcpu option instead.
> 
> So compiling with -march=neoverse-n1 will now give the error:
> cc1: error: unknown value 'neoverse-n1' for '-march'
> cc1: note: valid arguments are: armv8-a armv8.1-a armv8.2-a armv8.3-a armv8.4-a armv8.5-a armv8.6-a armv8.7-a armv8.8-a armv8-r armv9-a
> cc1: note: did you mean '-mcpu=neoverse-n1'?
> 
> Bootstrapped and tested on aarch64-none-linux-gnu.
> Pushing to trunk.
> Thanks,
> Kyrill
> 
> gcc/ChangeLog:
> 
> 	* config/aarch64/aarch64.cc (aarch64_validate_march): Check if invalid arch
> 	string is a valid -mcpu string and emit hint.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* gcc.target/aarch64/spellcheck_10.c: New test.

What about the reverse case, passing an architecture to -mcpu?

R.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: [PATCH][committed] aarch64: Suggest an -mcpu option when user passes CPU name to -march
  2022-09-05 13:42 ` Richard Earnshaw
@ 2022-09-06  9:53   ` Kyrylo Tkachov
  0 siblings, 0 replies; 3+ messages in thread
From: Kyrylo Tkachov @ 2022-09-06  9:53 UTC (permalink / raw)
  To: Richard Earnshaw, gcc-patches



> -----Original Message-----
> From: Richard Earnshaw <Richard.Earnshaw@foss.arm.com>
> Sent: Monday, September 5, 2022 2:43 PM
> To: Kyrylo Tkachov <Kyrylo.Tkachov@arm.com>; gcc-patches@gcc.gnu.org
> Subject: Re: [PATCH][committed] aarch64: Suggest an -mcpu option when
> user passes CPU name to -march
> 
> 
> 
> On 05/09/2022 14:35, Kyrylo Tkachov via Gcc-patches wrote:
> > Hi all,
> >
> > This small patch helps users who confuse -march and -mcpu on AArch64.
> > Sometimes users pass -march with a CPU name, where they most likely
> wanted to
> > use -mcpu, which would select the right architecture features *and* tune
> for
> > their desired CPU. Currently we'll just error out with an unkown
> architecture
> > message and list the valid architecture options.
> > With this patch we check if their string matches a known CPU and suggest
> they
> > use an -mcpu option instead.
> >
> > So compiling with -march=neoverse-n1 will now give the error:
> > cc1: error: unknown value 'neoverse-n1' for '-march'
> > cc1: note: valid arguments are: armv8-a armv8.1-a armv8.2-a armv8.3-a
> armv8.4-a armv8.5-a armv8.6-a armv8.7-a armv8.8-a armv8-r armv9-a
> > cc1: note: did you mean '-mcpu=neoverse-n1'?
> >
> > Bootstrapped and tested on aarch64-none-linux-gnu.
> > Pushing to trunk.
> > Thanks,
> > Kyrill
> >
> > gcc/ChangeLog:
> >
> > 	* config/aarch64/aarch64.cc (aarch64_validate_march): Check if
> invalid arch
> > 	string is a valid -mcpu string and emit hint.
> >
> > gcc/testsuite/ChangeLog:
> >
> > 	* gcc.target/aarch64/spellcheck_10.c: New test.
> 
> What about the reverse case, passing an architecture to -mcpu?

It'd be good to warn for that too, though I think it's a somewhat less common error.
It can be a separate patch in any case.
Thanks,
Kyrill

> 
> R.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-09-06  9:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-05 13:35 [PATCH][committed] aarch64: Suggest an -mcpu option when user passes CPU name to -march Kyrylo Tkachov
2022-09-05 13:42 ` Richard Earnshaw
2022-09-06  9:53   ` Kyrylo Tkachov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).