public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Tamar Christina <tnfchris@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-5369] middle-end: Fix FMA detection when inspecting gimple which have no LHS.
Date: Thu, 18 Nov 2021 11:24:46 +0000 (GMT)	[thread overview]
Message-ID: <20211118112446.E01DA385AC1F@sourceware.org> (raw)

https://gcc.gnu.org/g:1a0bce98dcf84dd0a7b3ac67b51ac68758cc7ad0

commit r12-5369-g1a0bce98dcf84dd0a7b3ac67b51ac68758cc7ad0
Author: Tamar Christina <tamar.christina@arm.com>
Date:   Thu Nov 18 11:22:11 2021 +0000

    middle-end: Fix FMA detection when inspecting gimple which have no LHS.
    
    convert_mult_to_fma assumes that all gimple_assigns have a LHS set.  This
    assumption is however not true when an IFN is kept around just for the
    side-effects.  In those situations you have just the IFN and lhs will be null.
    
    Since there's no LHS, there also can't be any ADD and such it can't be an FMA
    so it's correct to just return early if no LHS.
    
    gcc/ChangeLog:
    
            PR tree-optimization/103253
            * tree-ssa-math-opts.c (convert_mult_to_fma): Check for LHS.
    
    gcc/testsuite/ChangeLog:
    
            PR tree-optimization/103253
            * gcc.dg/vect/pr103253.c: New test.

Diff:
---
 gcc/testsuite/gcc.dg/vect/pr103253.c | 16 ++++++++++++++++
 gcc/tree-ssa-math-opts.c             |  4 ++++
 2 files changed, 20 insertions(+)

diff --git a/gcc/testsuite/gcc.dg/vect/pr103253.c b/gcc/testsuite/gcc.dg/vect/pr103253.c
new file mode 100644
index 00000000000..abe3f09f381
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/pr103253.c
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target fopenmp } */
+/* { dg-additional-options "-O2 -fexceptions -fopenmp -fno-delete-dead-exceptions -fno-trapping-math" } */
+
+double
+do_work (double do_work_pri)
+{
+  int i;
+
+#pragma omp simd
+  for (i = 0; i < 17; ++i)
+    do_work_pri = (!i ? 0.5 : i) * 2.0;
+
+  return do_work_pri;
+}
+
diff --git a/gcc/tree-ssa-math-opts.c b/gcc/tree-ssa-math-opts.c
index c4a6492b50d..cc8496c3c32 100644
--- a/gcc/tree-ssa-math-opts.c
+++ b/gcc/tree-ssa-math-opts.c
@@ -3224,6 +3224,10 @@ convert_mult_to_fma (gimple *mul_stmt, tree op1, tree op2,
 		     fma_deferring_state *state, tree mul_cond = NULL_TREE)
 {
   tree mul_result = gimple_get_lhs (mul_stmt);
+  /* If there isn't a LHS then this can't be an FMA.  There can be no LHS
+     if the statement was left just for the side-effects.  */
+  if (!mul_result)
+    return false;
   tree type = TREE_TYPE (mul_result);
   gimple *use_stmt, *neguse_stmt;
   use_operand_p use_p;


                 reply	other threads:[~2021-11-18 11:24 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20211118112446.E01DA385AC1F@sourceware.org \
    --to=tnfchris@gcc.gnu.org \
    --cc=gcc-cvs@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).