From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 228A83857806; Tue, 27 Oct 2020 11:18:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 228A83857806 From: "jiawei at iscas dot ac.cn" To: gcc-bugs@gcc.gnu.org Subject: [Bug other/97417] RISC-V Unnecessary andi instruction when loading volatile bool Date: Tue, 27 Oct 2020 11:18:28 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: other X-Bugzilla-Version: 10.2.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: jiawei at iscas dot ac.cn X-Bugzilla-Status: NEW 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: Message-ID: In-Reply-To: References: 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: Tue, 27 Oct 2020 11:18:29 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D97417 --- Comment #4 from jiawei --- I had did some tests with this problem and find: foo.c #include extern volatile bool active; int foo(void) { if (!active) { return 42; } else { return -42; } } code generated in foo.s foo: lui a5,%hi(active) lbu a5,%lo(active)(a5) li a0,42 andi a5,a5,0xff beq a5,zero,.L2 li a0,-42 When we remove the keyword `volatile` foo_without_volatile.c #include extern bool active; int foo(void) { if (!active) { return 42; } else { return -42; } } code generated in foo_without_volatile.s foo: lui a5,%hi(active) lbu a5,%lo(active)(a5) li a0,42 beq a5,zero,.L2 li a0,-42 and then we change the type from `bool` to `int` foo_int.c #include extern volatile int active; int foo(void) { if (!active) { return 42; } else { return -42; } } code generated in foo_int.s foo: lui a5,%hi(active) lw a5,%lo(active)(a5) li a0,42 sext.w a5,a5 beq a5,zero,.L2 li a0,-42 the `sext.w` instruction replace the `andi` We also remove the keyword `volatile` in foo_int_without_volatile.c #include extern int active; int foo(void) { if (!active) { return 42; } else { return -42; } } code generated in foo_int_without_volatile.s also look like optimized foo: lui a5,%hi(active) lw a5,%lo(active)(a5) li a0,42 beq a5,zero,.L2 li a0,-42 Maybe this problem is due to the keyword `volatile`.=