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

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).