public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/97040] New: incorrect fused multiply add/subtract instruction generated from C code
@ 2020-09-13 17:14 ddiculoiu at dspace dot de
  2022-02-06 18:20 ` [Bug target/97040] " law at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: ddiculoiu at dspace dot de @ 2020-09-13 17:14 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97040

            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 = 5.0,y = 2.0,z = 1.0;

int main()
{
  volatile float c = func_a(x,y,z);
  volatile float d = func_b(x,y,z);

  return 0;
}
compiled with:
v850-elf-gcc test.c  -mrh850-abi -mv850e3v5 -nostdlib --entry=0 -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 the 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. 
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]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-02-11 16:58 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-13 17:14 [Bug target/97040] New: incorrect fused multiply add/subtract instruction generated from C code ddiculoiu at dspace dot de
2022-02-06 18:20 ` [Bug target/97040] " law at gcc dot gnu.org
2022-02-09 19:06 ` law at gcc dot gnu.org
2022-02-09 19:13 ` cvs-commit at gcc dot gnu.org
2022-02-11 16:58 ` law at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).