From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id EF7CA385783F; Tue, 16 May 2023 08:07:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EF7CA385783F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1684224454; bh=usJp1IQvkJ9tbFhjUlzgFLD536G3JLxaTQhXgbDIDoQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=DrghqjPpb2OWfJdaJzqU60RqYsW5PhbgTbsSmSoiXDj3OjDqQZeVrZiHqv921Jv1k gxK6VFbGmW70/7iGegUhWpKbImLz/qB329GyEhHwt+9P8ovrl/NgjD69mlxwstxKnA SS8T8wLzaO6vYX8SLsXS7ky5KAfbymfEY24ePaME= From: "ubizjak at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/109866] Sometimes using sub/test instead just test Date: Tue, 16 May 2023 08:07:34 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: rtl-optimization X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: enhancement X-Bugzilla-Who: ubizjak at gmail 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: 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D109866 --- Comment #1 from Uro=C5=A1 Bizjak --- (In reply to Andrew Pinski from comment #0) > Take: > ``` > int g(void); int h(void); int t(void); > int f(int a, int b) > { > int c =3D a - b; > if(c =3D=3D 0) > return g(); > if (c > 0) > return h(); > return t(); > } > ``` > This is reduced from bzip2 in spec 2006, though I am not so sure any more. > On x86_64 GCC produces: > ``` > subl %esi, %edi > testl %edi, %edi > je .L5 > jle .L3 > jmp h() > .L3: > jmp t() > .L5: > jmp g() > ``` > But GCC should produce (likes clang/LLVM does): > ``` > cmpl %esi, %edi > je .L5 > jle .L3 > jmp h() > .L3: > jmp t() > .L5: > jmp g() > ``` >=20 > Note a similar thing happens with aarch64 target too. These two assemblies are not equal as demonstrated by the following test: --cut here-- #include _Bool __attribute__((noinline)) foo (int a, int b) { _Bool r; int tmp; asm ("subl %3, %0; testl %0, %0" : "=3Dr"(tmp), "=3D@cc" "le"(r) : "0"(a), "r"(b)); return r; } _Bool __attribute__((noinline)) bar (int a, int b) { _Bool r; asm ("cmpl %2, %1" : "=3D@cc" "le"(r) : "r"(a), "r"(b)); return r; } int main () { int a, b; _Bool ra, rb; a =3D 0x80000000, b =3D 0x40000000; ra =3D foo (a, b); rb =3D bar (a, b); printf ("%i %i\n", ra, rb); return 0; } --cut here-- $ ./a.out=20 0 1 The difference is in handling of overflow flag.=