From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 336D23858C5F; Thu, 18 May 2023 14:59:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 336D23858C5F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1684421989; bh=zNjJbsTvbvRSTRtpmwwL2dQsUrk9uEpu419gaoKQ8e8=; h=From:To:Subject:Date:From; b=oOgRmM3TneAqyzD6FmEvEO/DCSJzTrn9BF24U7bO+gF8OXjUuaZOqjlem7tukyn+t sOrQPD19cyhVIh60kIphFPq97/otAczdHSqm/Axfd0i59FkFhiQO+QshJDFiNMN6Da fKzGQYpTpa8sIsYMhxn0jacPvp+41dCMA1Z6++iQ= From: "dimitri.gorokhovik at free dot fr" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/109903] New: Register misallocation in hand-crafted asm insn, no diagnostics produced Date: Thu, 18 May 2023 14:59:48 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: dimitri.gorokhovik at free dot fr 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 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D109903 Bug ID: 109903 Summary: Register misallocation in hand-crafted asm insn, no diagnostics produced Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: dimitri.gorokhovik at free dot fr Target Milestone: --- For the source code: #if NO_BUG unsigned long f (unsigned long a) { unsigned long v; asm ("mrs %[_1], pmccntr_eli0\n" "\tldr x1, [%[_2]]\n" : [_1] "=3Dr" (v) : [_2] "r" (a) ); return v; } #else // BUG extern void g(unsigned long); void f (unsigned long a) { unsigned long v; asm ("mrs %[_1], pmccntr_eli0\n" "\tldr x1, [%[_2]]\n" : [_1] "=3Dr" (v) : [_2] "r" (a) ); g(v); } #endif The asm output produced is: ## BUG #APP # 23 "bug.c" 1 mrs %rdi, pmccntr_eli0 ldr x1, [%rdi] # 0 "" 2 #NO_APP ## NO_BUG #APP # 6 "bug.c" 1 mrs %rax, pmccntr_eli0 ldr x1, [%rdi] # 0 "" 2 #NO_APP As one can see, in the "NO BUG" case, the registers allocated to reading "t= he counter" and to reading "memory", are different, whereas they are one and t= he same in the "BUG" case. This was obtained with today's trunk built for native compilation: gcc (GCC) 14.0.0 20230518 (experimental).=20 The example was compiled as: gcc -S -O3 -Wall -Wextra -o bug.S bug.c=20 no diagnostic messages are produced. Same was also observed with gcc-aarch64-none-linux toolchain 13.2 (from Arm download page), so "target-related issue" might not be an entirely correct classification for this.=