public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/59385] New: gcc 4.9 fails to use fma with __attribute__((target("fma")))
@ 2013-12-04 16:45 jtaylor.debian at googlemail dot com
  2013-12-04 16:45 ` [Bug c/59385] " jtaylor.debian at googlemail dot com
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: jtaylor.debian at googlemail dot com @ 2013-12-04 16:45 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59385

            Bug ID: 59385
           Summary: gcc 4.9 fails to use fma with
                    __attribute__((target("fma")))
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jtaylor.debian at googlemail dot com

attached code does not emit fma instructions in gcc 4.9 while it did in gcc-4.8
(ffast-math is enabled):

$ gcc -v
COLLECT_GCC=/scratch/jtaylor/gcc/local-trunk/bin//gcc
COLLECT_LTO_WRAPPER=/scratch/jtaylor/gcc/local-trunk/libexec/gcc/x86_64-unknown-linux-gnu/4.9.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: /media/jtaylor/external1/buildacc/gcc-trunk/configure
--enable-languages=c,c++,fortran --enable-tls
--prefix=/scratch/jtaylor/gcc/local-trunk --with-gmp=/usr --with-mpfr=/usr
--with-mpc=/usr --with-cloog=/usr --with-ppl=/usr --with-isl=/usr
Thread model: posix
gcc version 4.9.0 20131204 (experimental) (GCC) 

$ gcc-4.9 -Wall fma-attribute.c -c -std=c99 -O2 && objdump -d fma-attribute.o 

fma-attribute.o:     file format elf64-x86-64


Disassembly of section .text:

0000000000000000 <f>:
   0:    c5 fb 10 06              vmovsd (%rsi),%xmm0
   4:    c5 fb 59 02              vmulsd (%rdx),%xmm0,%xmm0
   8:    c5 fb 58 01              vaddsd (%rcx),%xmm0,%xmm0
   c:    c5 fb 11 07              vmovsd %xmm0,(%rdi)
  10:    c3                       retq   

whereas gcc 4.8.1 does:

COLLECT_GCC=/usr/bin/gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.8/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro
4.8.1-10ubuntu9' --with-bugurl=file:///usr/share/doc/gcc-4.8/README.Bugs
--enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr
--program-suffix=-4.8 --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--with-gxx-include-dir=/usr/include/c++/4.8 --libdir=/usr/lib --enable-nls
--with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug
--enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin
--with-system-zlib --disable-browser-plugin --enable-java-awt=gtk
--enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64/jre
--enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64
--with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.8-amd64
--with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar
--enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686
--with-abi=m64 --with-multilib-list=m32,m64,mx32 --with-tune=generic
--enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu
--target=x86_64-linux-gnu
Thread model: posix
gcc version 4.8.1 (Ubuntu/Linaro 4.8.1-10ubuntu9) 

$ gcc-4.8 -Wall fma-attribute.c -c -std=c99 -O2 && objdump -d fma-attribute.o 

0000000000000000 <f>:
   0:    c5 fb 10 06              vmovsd (%rsi),%xmm0
   4:    c5 fb 10 09              vmovsd (%rcx),%xmm1
   8:    c4 e2 f1 99 02           vfmadd132sd (%rdx),%xmm1,%xmm0
   d:    c5 fb 11 07              vmovsd %xmm0,(%rdi)
  11:    c3                       retq   
  12:    66 66 66 66 66 2e 0f     data32 data32 data32 data32 nopw
%cs:0x0(%rax,%rax,1)
  19:    1f 84 00 00 00 00 00 


another weirdness is that gcc 4.8 and 4.9 it uses fma/avx also for the function
marked target("sse"), this can be fixed by only setting it in the declaration
and not the definition. Is that intentional?


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

* [Bug c/59385] gcc 4.9 fails to use fma with __attribute__((target("fma")))
  2013-12-04 16:45 [Bug c/59385] New: gcc 4.9 fails to use fma with __attribute__((target("fma"))) jtaylor.debian at googlemail dot com
@ 2013-12-04 16:45 ` jtaylor.debian at googlemail dot com
  2013-12-05 19:45 ` [Bug target/59385] " tmsriram at google dot com
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jtaylor.debian at googlemail dot com @ 2013-12-04 16:45 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59385

--- Comment #1 from Julian Taylor <jtaylor.debian at googlemail dot com> ---
Created attachment 31381
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=31381&action=edit
code reproducing the issue


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

* [Bug target/59385] gcc 4.9 fails to use fma with __attribute__((target("fma")))
  2013-12-04 16:45 [Bug c/59385] New: gcc 4.9 fails to use fma with __attribute__((target("fma"))) jtaylor.debian at googlemail dot com
  2013-12-04 16:45 ` [Bug c/59385] " jtaylor.debian at googlemail dot com
@ 2013-12-05 19:45 ` tmsriram at google dot com
  2013-12-06 22:58 ` tmsriram at google dot com
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: tmsriram at google dot com @ 2013-12-05 19:45 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59385

Sriraman Tallam <tmsriram at google dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |davidxl at google dot com

--- Comment #3 from Sriraman Tallam <tmsriram at google dot com> ---
Removing the target attributes and using -ffast-math -ftree-vectorize -mfma on
the command line is still not producing vfmadd132sd insn. Investigating.


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

* [Bug target/59385] gcc 4.9 fails to use fma with __attribute__((target("fma")))
  2013-12-04 16:45 [Bug c/59385] New: gcc 4.9 fails to use fma with __attribute__((target("fma"))) jtaylor.debian at googlemail dot com
  2013-12-04 16:45 ` [Bug c/59385] " jtaylor.debian at googlemail dot com
  2013-12-05 19:45 ` [Bug target/59385] " tmsriram at google dot com
@ 2013-12-06 22:58 ` tmsriram at google dot com
  2013-12-07  0:42 ` tmsriram at google dot com
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: tmsriram at google dot com @ 2013-12-06 22:58 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59385

--- Comment #4 from Sriraman Tallam <tmsriram at google dot com> ---
The "widening_mult" has the answer. This pass converts this gimple sequence

  double _31;
  double _33;
  double _36;
  double _37;

  _31 = *a_4;
  _33 = *b_6;
  _34 = _33 * _31;
  _36 = *c_8;
  _37 = _34 + _36;

into:

  _31 = *a_4;
  _33 = *b_6;
  _36 = *c_8;
  _37 = _33 * _31 + _36; (fma gets recognized from this pattern in rtl expand)

for the compiler where the vfmadd132sd insn is generated.

This conversion fails to happen in gcc-4.9. The problem should mostly be in
this function convert_mult_to_widen in treessa-math-opts.c. I have not looked
closely at this function yet.


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

* [Bug target/59385] gcc 4.9 fails to use fma with __attribute__((target("fma")))
  2013-12-04 16:45 [Bug c/59385] New: gcc 4.9 fails to use fma with __attribute__((target("fma"))) jtaylor.debian at googlemail dot com
                   ` (2 preceding siblings ...)
  2013-12-06 22:58 ` tmsriram at google dot com
@ 2013-12-07  0:42 ` tmsriram at google dot com
  2014-01-09 10:48 ` jtaylor.debian at googlemail dot com
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: tmsriram at google dot com @ 2013-12-07  0:42 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59385

--- Comment #5 from Sriraman Tallam <tmsriram at google dot com> ---
The root-cause is because floating point expression contraction is default
disabled in ISO C unless specified explicitly. So, adding -ffp-contract=fast
solves the problem.

Details:

The problem is in function convert_mult_to_fma in tree-ssa-math-opts.c. This
does not try to convert the mult into an fma expression because:


static bool
convert_mult_to_fma (gimple mul_stmt, tree op1, tree op2)
{
  tree mul_result = gimple_get_lhs (mul_stmt);
  tree type = TREE_TYPE (mul_result);
  gimple use_stmt, neguse_stmt, fma_stmt;
  use_operand_p use_p;
  imm_use_iterator imm_iter;

  if (FLOAT_TYPE_P (type)
      && flag_fp_contract_mode == FP_CONTRACT_OFF)
    return false;

Here, flag_fp_contract_mode is set to FP_CONTRACT_OFF even though it was
initialized to FP_CONTRACT_FAST.

flag_fp_contract_mode gets reset to FP_CONTRACT_OFF here:

c-family/c-opts.c:

bool
c_common_post_options (const char **pfilename)
{
  ...
  /* ISO C restricts floating-point expression contraction to within
     source-language expressions (-ffp-contract=on, currently an alias
     for -ffp-contract=off).  */
  if (flag_iso
      && !c_dialect_cxx ()
      && (global_options_set.x_flag_fp_contract_mode
      == (enum fp_contract_mode) 0))
    flag_fp_contract_mode = FP_CONTRACT_OFF;

That happened in rev. 204460. I do not understand this restriction. However,
specifying -ffp-contract=fast in the command-line disables this reset.


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

* [Bug target/59385] gcc 4.9 fails to use fma with __attribute__((target("fma")))
  2013-12-04 16:45 [Bug c/59385] New: gcc 4.9 fails to use fma with __attribute__((target("fma"))) jtaylor.debian at googlemail dot com
                   ` (3 preceding siblings ...)
  2013-12-07  0:42 ` tmsriram at google dot com
@ 2014-01-09 10:48 ` jtaylor.debian at googlemail dot com
  2014-01-31 10:49 ` [Bug target/59385] [4.9 regression] " rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jtaylor.debian at googlemail dot com @ 2014-01-09 10:48 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59385

--- Comment #6 from Julian Taylor <jtaylor.debian at googlemail dot com> ---
shouldn't -ffast-math enable -ffp-contract=fast?

also gcc 4.9 still documents -ffp-contract=fast as being the default while it
is apparently not anymore.


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

* [Bug target/59385] [4.9 regression] gcc 4.9 fails to use fma with __attribute__((target("fma")))
  2013-12-04 16:45 [Bug c/59385] New: gcc 4.9 fails to use fma with __attribute__((target("fma"))) jtaylor.debian at googlemail dot com
                   ` (4 preceding siblings ...)
  2014-01-09 10:48 ` jtaylor.debian at googlemail dot com
@ 2014-01-31 10:49 ` rguenth at gcc dot gnu.org
  2014-01-31 11:14 ` rguenth at gcc dot gnu.org
  2014-01-31 12:26 ` jtaylor.debian at googlemail dot com
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2014-01-31 10:49 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59385

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |4.9.0


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

* [Bug target/59385] [4.9 regression] gcc 4.9 fails to use fma with __attribute__((target("fma")))
  2013-12-04 16:45 [Bug c/59385] New: gcc 4.9 fails to use fma with __attribute__((target("fma"))) jtaylor.debian at googlemail dot com
                   ` (5 preceding siblings ...)
  2014-01-31 10:49 ` [Bug target/59385] [4.9 regression] " rguenth at gcc dot gnu.org
@ 2014-01-31 11:14 ` rguenth at gcc dot gnu.org
  2014-01-31 12:26 ` jtaylor.debian at googlemail dot com
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2014-01-31 11:14 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59385

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |WORKSFORME

--- Comment #7 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Julian Taylor from comment #6)
> shouldn't -ffast-math enable -ffp-contract=fast?

it doesn't (it probably should)

> also gcc 4.9 still documents -ffp-contract=fast as being the default while
> it is apparently not anymore.

it's the default unless you override it with -std=c99 (always use -std=gnu99).

Are you sure this worked correctly in 4.8.0?  I see both functions using
vfmadd132sd there - that's cleary wrong as well.

Works for me correctly, with -std=gnu99.

Thus, it works as intended in 4.9 and the bug in 4.8 was fixed.


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

* [Bug target/59385] [4.9 regression] gcc 4.9 fails to use fma with __attribute__((target("fma")))
  2013-12-04 16:45 [Bug c/59385] New: gcc 4.9 fails to use fma with __attribute__((target("fma"))) jtaylor.debian at googlemail dot com
                   ` (6 preceding siblings ...)
  2014-01-31 11:14 ` rguenth at gcc dot gnu.org
@ 2014-01-31 12:26 ` jtaylor.debian at googlemail dot com
  7 siblings, 0 replies; 9+ messages in thread
From: jtaylor.debian at googlemail dot com @ 2014-01-31 12:26 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59385

--- Comment #8 from Julian Taylor <jtaylor.debian at googlemail dot com> ---
>
> > also gcc 4.9 still documents -ffp-contract=fast as being the default
> while
> > it is apparently not anymore.
>
> it's the default unless you override it with -std=c99 (always use
> -std=gnu99).
>

it would be nice if the documentation would be updated to reflect this. It
is not obvious -std overrides it, you expect the more specific options
override the generic ones (e.g. -O2 -ftree-vectorize).


> Are you sure this worked correctly in 4.8.0?  I see both functions using
> vfmadd132sd there - that's cleary wrong as well.
>

I can't say if its correct, but it behaved as I expected it.

The emitting of fma in the non-fma target is a different issue, see:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54344


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

end of thread, other threads:[~2014-01-31 12:26 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-04 16:45 [Bug c/59385] New: gcc 4.9 fails to use fma with __attribute__((target("fma"))) jtaylor.debian at googlemail dot com
2013-12-04 16:45 ` [Bug c/59385] " jtaylor.debian at googlemail dot com
2013-12-05 19:45 ` [Bug target/59385] " tmsriram at google dot com
2013-12-06 22:58 ` tmsriram at google dot com
2013-12-07  0:42 ` tmsriram at google dot com
2014-01-09 10:48 ` jtaylor.debian at googlemail dot com
2014-01-31 10:49 ` [Bug target/59385] [4.9 regression] " rguenth at gcc dot gnu.org
2014-01-31 11:14 ` rguenth at gcc dot gnu.org
2014-01-31 12:26 ` jtaylor.debian at googlemail dot com

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).