public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "tmsriram at google dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/59390] presence of  __attribute__((target("fma"))) declaration breaks __builtin_fma
Date: Fri, 06 Dec 2013 00:34:00 -0000	[thread overview]
Message-ID: <bug-59390-4-IBxbgiUhAW@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-59390-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #4 from Sriraman Tallam <tmsriram at google dot com> ---
Here is the problem. GCC adds target-specific builtins on demand. The FMA
target-specific builtin __builtin_ia32_vfmaddpd gets added via this
declaration:

void fun() __attribute__((target("fma")));

Specifically, the builtin __builtin_ia32_vfmaddpd gets added when
ix86_add_new_builtins is called from ix86_valid_target_attribute_tree when
processing this target attribute.

Now, when the vectorizer is processing the builtin "__builtin_fma" in function
other_fn(), it checks to see if this function is vectorizable and calls
ix86_builtin_vectorized_function in i386.c. That returns the builtin stored
here:


   case BUILT_IN_FMA:
      if (out_mode == DFmode && in_mode == DFmode)
    {
      if (out_n == 2 && in_n == 2)
        return ix86_builtins[IX86_BUILTIN_VFMADDPD];
          ....

ix86_builtins[IX86_BUILTIN_VFMADDPD] would have contained NULL_TREE had the
builtin not been added by the previous target attribute. That is why the code
works if we remove the previous declaration.

The fix then is to not just return the builtin but to also check if the current
function's isa allows the use of the builtin. For instance, this patch would
solve the problem:

@@ -33977,7 +33977,13 @@ ix86_builtin_vectorized_function (tree fndecl, tre
       if (out_mode == DFmode && in_mode == DFmode)
     {
       if (out_n == 2 && in_n == 2)
-        return ix86_builtins[IX86_BUILTIN_VFMADDPD];
+        {
+          if (ix86_builtins_isa[IX86_BUILTIN_VFMADDPD].isa
+          & global_options.x_ix86_isa_flags)
+            return ix86_builtins[IX86_BUILTIN_VFMADDPD];
+          else
+        return NULL_TREE;
+        }


but there are many instances of this usage in ix86_builtin_vectorized_function.
I will make a patch to cover all these cases and send for review.


  parent reply	other threads:[~2013-12-06  0:34 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-04 20:46 [Bug target/59390] New: " jtaylor.debian at googlemail dot com
2013-12-05  7:10 ` [Bug target/59390] " ubizjak at gmail dot com
2013-12-05 10:52 ` rguenth at gcc dot gnu.org
2013-12-05 19:24 ` tmsriram at google dot com
2013-12-06  0:34 ` tmsriram at google dot com [this message]
2013-12-11 20:06 ` tmsriram at gcc dot gnu.org
2021-08-09  7:30 ` pinskia at gcc dot gnu.org
2023-12-04  3:10 ` pinskia at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-59390-4-IBxbgiUhAW@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).