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]