public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/96768] New: -mpure-code produces switch tables for thumb-1
@ 2020-08-24 13:19 clyon at gcc dot gnu.org
2020-08-27 13:27 ` [Bug target/96768] " clyon at gcc dot gnu.org
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: clyon at gcc dot gnu.org @ 2020-08-24 13:19 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96768
Bug ID: 96768
Summary: -mpure-code produces switch tables for thumb-1
Product: gcc
Version: 10.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: clyon at gcc dot gnu.org
Target Milestone: ---
As discussed in PR94538, -mpure-code produces switch tables for thumb-1.
int f2 (int x, int y)
{
switch (x)
{
case 0: return y + 0;
case 1: return y + 1;
case 2: return y + 2;
case 3: return y + 3;
case 4: return y + 4;
case 5: return y + 5;
}
return y;
}
Compiled with -O2 -mpure-code,
-mcpu=cortex-m0:
f2:
cmp r0, #5
bhi .L9
movs r2, #:upper8_15:#.LC0
lsls r2, #8
adds r2, #:upper0_7:#.LC0
lsls r2, #8
adds r2, #:lower8_15:#.LC0
lsls r2, #8
adds r2, #:lower0_7:#.LC0
ldr r2, [r2]
lsls r0, r0, #2
ldr r3, [r2, r0]
mov pc, r3
.section .rodata
.align 2
.L4:
.word .L9
.word .L8
.word .L7
.word .L6
.word .L5
.word .L3
.section .text,"0x20000006",%progbits
.L3:
adds r0, r1, #5
.L1:
@ sp needed
bx lr
.L8:
adds r0, r1, #1
b .L1
.L7:
adds r0, r1, #2
b .L1
.L6:
adds r0, r1, #3
b .L1
.L5:
adds r0, r1, #4
b .L1
.L9:
movs r0, r1
b .L1
For cortex-m23:
f2:
cmp r0, #5
bhi .L9
movw r2, #:lower16:.LC0
movt r2, #:upper16:.LC0
ldr r2, [r2]
lsls r0, r0, #2
ldr r3, [r2, r0]
mov pc, r3
For reference, for cortex-m3:
f2:
cmp r0, #3
beq .L2
ble .L11
cmp r0, #4
beq .L7
cmp r0, #5
bne .L9
adds r0, r1, #5
bx lr
.L11:
cmp r0, #1
beq .L4
cmp r0, #2
bne .L9
adds r0, r1, #2
bx lr
.L2:
adds r0, r1, #3
bx lr
.L7:
adds r0, r1, #4
bx lr
.L4:
adds r0, r1, #1
bx lr
.L9:
mov r0, r1
bx lr
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug target/96768] -mpure-code produces switch tables for thumb-1
2020-08-24 13:19 [Bug target/96768] New: -mpure-code produces switch tables for thumb-1 clyon at gcc dot gnu.org
@ 2020-08-27 13:27 ` clyon at gcc dot gnu.org
2020-08-27 13:28 ` clyon at gcc dot gnu.org
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: clyon at gcc dot gnu.org @ 2020-08-27 13:27 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96768
--- Comment #1 from Christophe Lyon <clyon at gcc dot gnu.org> ---
This is related to comments 10,11,14,15 and 16 in the original PR94538.
In comment 14, Wilco suggested: "The best option is to do the same as
Cortex-M3: just switch off branch tables altogether and fall back to
compare+branch. That completely avoids loading data from flash and is always
smaller than emitting 32-bit tables."
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug target/96768] -mpure-code produces switch tables for thumb-1
2020-08-24 13:19 [Bug target/96768] New: -mpure-code produces switch tables for thumb-1 clyon at gcc dot gnu.org
2020-08-27 13:27 ` [Bug target/96768] " clyon at gcc dot gnu.org
@ 2020-08-27 13:28 ` clyon at gcc dot gnu.org
2020-08-27 13:32 ` clyon at gcc dot gnu.org
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: clyon at gcc dot gnu.org @ 2020-08-27 13:28 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96768
--- Comment #2 from Christophe Lyon <clyon at gcc dot gnu.org> ---
Send patch proposal:
https://gcc.gnu.org/pipermail/gcc-patches/2020-August/552798.html
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug target/96768] -mpure-code produces switch tables for thumb-1
2020-08-24 13:19 [Bug target/96768] New: -mpure-code produces switch tables for thumb-1 clyon at gcc dot gnu.org
2020-08-27 13:27 ` [Bug target/96768] " clyon at gcc dot gnu.org
2020-08-27 13:28 ` clyon at gcc dot gnu.org
@ 2020-08-27 13:32 ` clyon at gcc dot gnu.org
2020-08-28 11:58 ` rearnsha at gcc dot gnu.org
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: clyon at gcc dot gnu.org @ 2020-08-27 13:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96768
Christophe Lyon <clyon at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2020-08-27
Ever confirmed|0 |1
Status|UNCONFIRMED |ASSIGNED
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug target/96768] -mpure-code produces switch tables for thumb-1
2020-08-24 13:19 [Bug target/96768] New: -mpure-code produces switch tables for thumb-1 clyon at gcc dot gnu.org
` (2 preceding siblings ...)
2020-08-27 13:32 ` clyon at gcc dot gnu.org
@ 2020-08-28 11:58 ` rearnsha at gcc dot gnu.org
2020-08-28 13:23 ` clyon at gcc dot gnu.org
2020-08-28 18:23 ` wilco at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: rearnsha at gcc dot gnu.org @ 2020-08-28 11:58 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96768
--- Comment #3 from Richard Earnshaw <rearnsha at gcc dot gnu.org> ---
Note that the switch table is in the .rodata section, so that's not a problem.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug target/96768] -mpure-code produces switch tables for thumb-1
2020-08-24 13:19 [Bug target/96768] New: -mpure-code produces switch tables for thumb-1 clyon at gcc dot gnu.org
` (3 preceding siblings ...)
2020-08-28 11:58 ` rearnsha at gcc dot gnu.org
@ 2020-08-28 13:23 ` clyon at gcc dot gnu.org
2020-08-28 18:23 ` wilco at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: clyon at gcc dot gnu.org @ 2020-08-28 13:23 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96768
--- Comment #4 from Christophe Lyon <clyon at gcc dot gnu.org> ---
That's what I replied in the original PR94538, but Wilco said the best option
was to turn off switch tables:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94538#c14
See also another comment from him:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94538#c16 related to immediate
loads from rodata/bss.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug target/96768] -mpure-code produces switch tables for thumb-1
2020-08-24 13:19 [Bug target/96768] New: -mpure-code produces switch tables for thumb-1 clyon at gcc dot gnu.org
` (4 preceding siblings ...)
2020-08-28 13:23 ` clyon at gcc dot gnu.org
@ 2020-08-28 18:23 ` wilco at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: wilco at gcc dot gnu.org @ 2020-08-28 18:23 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96768
Wilco <wilco at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |wilco at gcc dot gnu.org
--- Comment #5 from Wilco <wilco at gcc dot gnu.org> ---
(In reply to Christophe Lyon from comment #4)
> That's what I replied in the original PR94538, but Wilco said the best
> option was to turn off switch tables:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94538#c14
>
> See also another comment from him:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94538#c16 related to immediate
> loads from rodata/bss.
Yes, switching off switch tables is obviously the best option - just look at
the m0 vs m3 code above. It's the fastest and smallest, and is also "pure code"
since there are no extra literals generated anywhere.
In AArch32 switch tables are very inefficient. An easy improvement would be to
copy the AArch64 case_values_threshold to disable tables if there are fewer
than 16 cases.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2020-08-28 18:23 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-24 13:19 [Bug target/96768] New: -mpure-code produces switch tables for thumb-1 clyon at gcc dot gnu.org
2020-08-27 13:27 ` [Bug target/96768] " clyon at gcc dot gnu.org
2020-08-27 13:28 ` clyon at gcc dot gnu.org
2020-08-27 13:32 ` clyon at gcc dot gnu.org
2020-08-28 11:58 ` rearnsha at gcc dot gnu.org
2020-08-28 13:23 ` clyon at gcc dot gnu.org
2020-08-28 18:23 ` wilco at gcc dot gnu.org
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).