From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 38948393F87F; Fri, 14 May 2021 15:15:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 38948393F87F From: "dragan.mladjenovic at syrmia dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/100604] New: GCC generates invalid LO_SYM for unaligned global Date: Fri, 14 May 2021 15:15:38 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 11.1.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: dragan.mladjenovic at syrmia dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 14 May 2021 15:15:38 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D100604 Bug ID: 100604 Summary: GCC generates invalid LO_SYM for unaligned global Product: gcc Version: 11.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: dragan.mladjenovic at syrmia dot com Target Milestone: --- Created attachment 50814 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D50814&action=3Dedit Reproducer example. This a bit contrived example that requires -O0. Not sure if it applies to bitfield extracts in other contexts and optimization levels. I noticed it on STRICT_ALIGMENT targets w/o extzvmisalign. $cat unaligned.c int __attribute__((aligned(2))) bar; int foo (void) { return bar; } $riscv64-elf-gcc unaligned.c -S -o - .file "unaligned.c" .option nopic .attribute arch, "rv64i2p0_m2p0_a2p0_f2p0_d2p0_c2p0" .attribute unaligned_access, 0 .attribute stack_align, 16 .text .globl bar .section .sbss,"aw",@nobits .align 1 .type bar, @object .size bar, 4 bar: .zero 4 .text .align 1 .globl foo .type foo, @function foo: addi sp,sp,-16 sd s0,8(sp) addi s0,sp,16 lui a5,%hi(bar) lhu a4,%lo(bar)(a5) lhu a5,%lo(bar+2)(a5) slli a5,a5,16 or a5,a5,a4 slli a5,a5,32 srai a5,a5,32 sext.w a5,a5 mv a0,a5 ld s0,8(sp) addi sp,sp,16 jr ra .size foo, .-foo .ident "GCC: (Scratch/experimental build 20210514_1511) 11.1.1 20210503" $mipsisa64-elf-gcc -O0 unaligned.c -G 0 -mips64r6 -S -o - .file 1 "unaligned.c" .section .mdebug.eabi64 .previous .section .gcc_compiled_long64 .previous .nan 2008 .module fp=3D64 .module oddspreg .text .globl bar .section .bss,"aw",@nobits .align 1 .type bar, @object .size bar, 4 bar: .space 4 .text .align 2 .globl foo .set nomips16 .set nomicromips .ent foo .type foo, @function foo: .frame $fp,8,$31 # vars=3D 0, regs=3D 1/0, args=3D 0= , gp=3D 0 .mask 0x40000000,0 .fmask 0x00000000,0 .set noreorder .set nomacro daddiu $sp,$sp,-8 sd $fp,0($sp) move $fp,$sp lui $2,%hi(bar) lhu $3,%lo(bar)($2) dsll $3,$3,16 lhu $2,%lo(bar+2)($2) or $2,$2,$3 dsll $2,$2,32 dsra $2,$2,32 sll $2,$2,0 move $sp,$fp ld $fp,0($sp) daddiu $sp,$sp,8 jrc $31 .set macro .set reorder .end foo .size foo, .-foo .ident "GCC: (Scratch/experimental build 20210514_1405) 11.1.1 20210503" Notice that %lo(bar)(.*) and %lo(bar+2)(.*) resue same %hi(bar) value. This can be wrong since bar is 2-byte aligned and might be split between two different %hi pages.=