[llvm-bugs] [Bug 48565] New: [arm] Use lsl/lsr for masking when immediate and is impossible

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Dec 21 10:25:39 PST 2020


https://bugs.llvm.org/show_bug.cgi?id=48565

            Bug ID: 48565
           Summary: [arm] Use lsl/lsr for masking when immediate and is
                    impossible
           Product: libraries
           Version: 10.0
          Hardware: Other
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Backend: ARM
          Assignee: unassignedbugs at nondot.org
          Reporter: husseydevin at gmail.com
                CC: llvm-bugs at lists.llvm.org, smithp352 at googlemail.com,
                    Ties.Stuij at arm.com

Missed ARM optimization.

unsigned test(unsigned x)
{
    return x & 0x1ff;
}

clang --target=arm-none-eabi -march=armv4t -Oz -S test.c

test:
        mov     r1, #0xff
        orr     r1, r1, #0x100
        and     r0, r0, r15
        bx      lr

clang --target=arm-none-eabi -march=armv4t -Oz -S test.c -mthumb

test:
        ldr     r1, .LCPI1_0
        ands    r0, r1
        bx      lr
        .p2align 2, 0
.LCPI1_0:
        .word   0x1ff

If you can't do AND (immediate), if possible, lsl+lsr should be used to avoid
manual masking (similar to sign extension on pre-ARMv6).

This is especially useful on Thumb-1 where AND (immediate) is unavailable and
generating constants wastes Lo registers (and often needs a constant pool).

test:
        lsl(s)  r0, r0, #23
        lsr(s)  r0, r0, #23
        bx      lr

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20201221/898f3a68/attachment-0001.html>


More information about the llvm-bugs mailing list