From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 0DBC53857C5A; Sun, 13 Sep 2020 17:14:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0DBC53857C5A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1600017294; bh=Mr1Dl9rLJdNpXBmFlAsMkQ70uX7PE7JgyhNav+iC9Os=; h=From:To:Subject:Date:From; b=K0KeYGzbC7ghla3Fmq9hWVOf3jurOgxqcuO5/LtF78TslbWsD2AZnrpX+eIkeJ7NR N4cDIwb11Mn8weRyTlV7cXr0Cj8uPGAygov1lDbky5VsA4vq6S3MSM2Zr20QYxBMgP 7rmGEses1cTwJw2ST9BrncJSpACAD8omX8qyeJyk= From: "ddiculoiu at dspace dot de" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/97040] New: incorrect fused multiply add/subtract instruction generated from C code Date: Sun, 13 Sep 2020 17:14:53 +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: 8.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: ddiculoiu at dspace dot de 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 cf_gcctarget 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: Sun, 13 Sep 2020 17:14:54 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D97040 Bug ID: 97040 Summary: incorrect fused multiply add/subtract instruction generated from C code Product: gcc Version: 8.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: ddiculoiu at dspace dot de Target Milestone: --- Target: v850-elf Consider the following simple code: __attribute__ ((noinline)) float func_a(float x, float y, float z) { return (x-y*z); } __attribute__ ((noinline)) float func_b(float x, float y, float z) { return (-x-y*z); } volatile float x =3D 5.0,y =3D 2.0,z =3D 1.0; int main() { volatile float c =3D func_a(x,y,z); volatile float d =3D func_b(x,y,z); return 0; } compiled with: v850-elf-gcc test.c -mrh850-abi -mv850e3v5 -nostdlib --entry=3D0 -O2 The gcc generates the following assembly code for the 'func_a' and 'func_b': 00100000 <_func_a>: 100000: 06 50 mov r6, r10 100002: e7 47 e4 54 fnmaf.s r7, r8, r10 100006: 7f 00 jmp [lp] 00100008 <_func_b>: 100008: 06 50 mov r6, r10 10000a: e7 47 e6 54 fnmsf.s r7, r8, r10 10000e: 7f 00 jmp [lp] In my opinion the 2 instructions 'fnmaf.s' and 'fnmsf.s' are exchanged in t= he 2 functions. The funtion 'func_a' must contain the 'fnmsf.s' and the 'func_b'= the 'fnmaf.s' instruction. Can someone confirm my observations? Thanks. P.S. I did a test with older (gcc 4.9.0) and latest (gcc 10.2.0) gcc.=20 Both have the same problem. I think the bug is from the first release where= the fused multiply and add/subtraction were added and nobody detected it yet. When I compile the same code with Green Hills Compiler I got the correct assembly instruction for 'func_a' and the 'func_b' uses negated value for x= and the 'fnmsf.s' instruction instead of the 'fnmaf.s' one, but the result is correct: 00001000 <_func_a>: 1000: 06 50 mov r6, r10 1002: e7 47 e6 54 fnmsf.s r7, r8, r10 1006: 7f 00 jmp [lp] 00001010 <_func_b>: 1010: e1 37 48 54 negf.s r6, r10 1014: e7 47 e6 54 fnmsf.s r7, r8, r10 1018: 7f 00 jmp [lp]=