Skip to content

arc: Do not pass -mcode-density to the assembler with -mno-code-density#271

Open
luismgsilva wants to merge 2 commits into
arc-2026.09-devfrom
luis/no-code-density
Open

arc: Do not pass -mcode-density to the assembler with -mno-code-density#271
luismgsilva wants to merge 2 commits into
arc-2026.09-devfrom
luis/no-code-density

Conversation

@luismgsilva

Copy link
Copy Markdown
Member
arc: Do not pass -mcode-density to the assembler with -mno-code-density

For ARC EM CPUs that enable code density by default, cpu_to_as adds
-mcode-density to the assembler command line.  When the user passes
-mno-code-density, the compiler disables the extension, but cpu_to_as
still requested -mcode-density for those CPUs.  The GNU assembler only
has a positive -mcode-density option and no way to disable the
extension from the command line, so the driver must omit -mcode-density
instead of forwarding the user's -mno-code-density flag.

Pass a marker from ASM_SPEC when -mno-code-density is given, and
suppress the default -mcode-density request in cpu_to_as.  Explicit
-mcode-density continues to be forwarded by %{mcode-density}.

For example, with -mcpu=em4_dmips the driver invokes the assembler as:

        gcc ... -mcpu=em4_dmips -c test.c
        -> as ... -mcpu=arcem -mcode-density ...

With -mno-code-density, it used to make no difference:

        gcc ... -mcpu=em4_dmips -mno-code-density -c test.c
        -> as ... -mcpu=arcem -mcode-density ...

and now correctly omits -mcode-density:

        gcc ... -mcpu=em4_dmips -mno-code-density -c test.c
        -> as ... -mcpu=arcem ...

Assembling the same test program shows different instruction encodings
in the object file, for example:

        $ gcc -c test.c -mcpu=em4_dmips
        $ objdump -d test.o
           4:   4104                    ld_s    r1,[r0,0]
          10:   4004                    ld_s    r0,[r0,0]

versus:

        $ gcc -c test.c -mcpu=em4_dmips -mno-code-density
        $ objdump -d test.o
           4:   8020                    ld_s    r1,[r0,0]
          10:   8000                    ld_s    r0,[r0,0]

gcc/ChangeLog:

        * config/arc/arc.h (ASM_SPEC): Pass a no-cd marker to cpu_to_as
        when -mno-code-density is given.
        * config/arc/driver-arc.cc (arc_cpu_to_as): Do not request
        -mcode-density from the assembler when the marker is present.

Signed-off-by: Luis Silva <luis.silva@globalfoundries.com>

@luismgsilva luismgsilva self-assigned this Jun 16, 2026
@luismgsilva luismgsilva marked this pull request as ready for review June 17, 2026 10:53
@luismgsilva

Copy link
Copy Markdown
Member Author

This patch fixes the original issue reported in #253

@luismgsilva luismgsilva force-pushed the luis/no-code-density branch from cc0cdec to 9f30dfa Compare June 18, 2026 11:10
@luismgsilva luismgsilva marked this pull request as ready for review June 18, 2026 11:11
@luismgsilva luismgsilva force-pushed the luis/no-code-density branch from 9f30dfa to ad4017e Compare June 18, 2026 12:13
For ARC EM CPUs that enable code density by default, cpu_to_as adds
-mcode-density to the assembler command line.  When the user passes
-mno-code-density, the compiler disables the extension, but cpu_to_as
still requested -mcode-density for those CPUs.  The GNU assembler only
has a positive -mcode-density option and no way to disable the
extension from the command line, so the driver must omit -mcode-density
instead of forwarding the user's -mno-code-density flag.

Pass a no-cd marker from ASM_SPEC when -mno-code-density is given, and
have cpu_to_as parse it from the spec function arguments and suppress
the default -mcode-density request.  Explicit -mcode-density continues
to be forwarded by %{mcode-density}.  The assembler now uses the
instruction encoding that matches whether code density is enabled or
disabled.

For example, with -mcpu=em4_dmips the driver invokes the assembler as:

	gcc ... -mcpu=em4_dmips -c test.c
	-> as ... -mcpu=arcem -mcode-density ...

With -mno-code-density, it used to make no difference:

	gcc ... -mcpu=em4_dmips -mno-code-density -c test.c
	-> as ... -mcpu=arcem -mcode-density ...

and now correctly omits -mcode-density:

	gcc ... -mcpu=em4_dmips -mno-code-density -c test.c
	-> as ... -mcpu=arcem ...

Assembling the same test program shows different instruction encodings
in the object file, for example:

	$ gcc -c test.c -mcpu=em4_dmips
	$ objdump -d test.o
	   4:   4104                    ld_s    r1,[r0,0]
	  10:   4004                    ld_s    r0,[r0,0]

versus:

	$ gcc -c test.c -mcpu=em4_dmips -mno-code-density
	$ objdump -d test.o
	   4:   8020                    ld_s    r1,[r0,0]
	  10:   8000                    ld_s    r0,[r0,0]

gcc/ChangeLog:

	* config/arc/arc.h (ASM_SPEC): Pass a no-cd marker to cpu_to_as
	when -mno-code-density is given.
	* config/arc/driver-arc.cc (arc_cpu_to_as): Parse the marker and
	the optional -mcpu name from the spec arguments; do not request
	-mcode-density from the assembler when the marker is present.

Signed-off-by: Luis Silva <luis.silva@globalfoundries.com>
@luismgsilva luismgsilva force-pushed the luis/no-code-density branch from 61c48ef to 2fc37c8 Compare June 18, 2026 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant