https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90363
Bug ID: 90363 Summary: or1k: Extra mask insn after load from memory Product: gcc Version: 9.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: shorne at gcc dot gnu.org Target Milestone: --- When compiling the below code we see and extra "l.andi r17, r17, 0xff" mask instruction when reading a byte from memory. This is not needed as loads already zero extend. Example: #include <stdint.h> volatile uint8_t g_doswap = 1; uint64_t swap_1(uint64_t u64) { uint32_t u64_lo, u64_hi, u64_tmp; u64_lo = u64 & 0xFFFFFFFF; u64_hi = u64 >> 32; if (g_doswap) { u64_tmp = u64_lo; u64_lo = u64_hi; u64_hi = u64_tmp; } u64 = u64_lo; u64 += ((uint64_t) u64_hi << 32); return u64; } // swap_1 Output: or1k-elf-gcc -O2 -S doswap_1.c .file "doswap_1.c" .section .text .align 4 .global swap_1 .type swap_1, @function swap_1: l.movhi r17, ha(.LANCHOR0) l.lbz r17, lo(.LANCHOR0)(r17) l.andi r17, r17, 0xff // <---- Where is this coming from l.movhi r19, hi(0) l.sfeq r17, r19 l.or r12, r4, r4 l.bf .L6 l.or r11, r3, r3 l.bf .L6 l.or r11, r4, r4 l.or r12, r3, r3 .L6: l.jr r9 l.nop .size swap_1, .-swap_1 .global g_doswap .section .data .set .LANCHOR0,. + 0 .type g_doswap, @object .size g_doswap, 1 g_doswap: .byte 1 .ident "GCC: (GNU) 9.0.1 20190326 (experimental)"