public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH]middle-end: Fix FMA detection when inspecting gimple which have no LHS.
@ 2021-11-16 15:35 Tamar Christina
  2021-11-18 11:06 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Tamar Christina @ 2021-11-16 15:35 UTC (permalink / raw)
  To: gcc-patches; +Cc: nd, rguenther

[-- Attachment #1: Type: text/plain, Size: 2012 bytes --]

Hi All,

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.

Bootstrapped Regtested on aarch64-none-linux-gnu,
x86_64-pc-linux-gnu and no regressions.

Ok for master?

Thanks,
Tamar



gcc/ChangeLog:

	PR tree-optimizations/103253
	* tree-ssa-math-opts.c (convert_mult_to_fma): Check for LHS.

gcc/testsuite/ChangeLog:

	* gcc.dg/vect/pr103253.c: New test.

--- inline copy of patch -- 
diff --git a/gcc/testsuite/gcc.dg/vect/pr103253.c b/gcc/testsuite/gcc.dg/vect/pr103253.c
new file mode 100644
index 0000000000000000000000000000000000000000..abe3f09f3818d79a53f2aa962c6b6c06855d618e
--- /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 c4a6492b50df25b4cf296a75bd51e5af34eeacc7..cc8496c3c325f3cc303a90b9b9cac383e5a7942d 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;


-- 

[-- Attachment #2: rb15089.patch --]
[-- Type: text/x-diff, Size: 1320 bytes --]

diff --git a/gcc/testsuite/gcc.dg/vect/pr103253.c b/gcc/testsuite/gcc.dg/vect/pr103253.c
new file mode 100644
index 0000000000000000000000000000000000000000..abe3f09f3818d79a53f2aa962c6b6c06855d618e
--- /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 c4a6492b50df25b4cf296a75bd51e5af34eeacc7..cc8496c3c325f3cc303a90b9b9cac383e5a7942d 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;


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

* Re: [PATCH]middle-end: Fix FMA detection when inspecting gimple which have no LHS.
  2021-11-16 15:35 [PATCH]middle-end: Fix FMA detection when inspecting gimple which have no LHS Tamar Christina
@ 2021-11-18 11:06 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2021-11-18 11:06 UTC (permalink / raw)
  To: Tamar Christina; +Cc: gcc-patches, nd

On Tue, 16 Nov 2021, Tamar Christina wrote:

> Hi All,
> 
> 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.
> 
> Bootstrapped Regtested on aarch64-none-linux-gnu,
> x86_64-pc-linux-gnu and no regressions.
> 
> Ok for master?

OK.

Thanks,
Richard.

> Thanks,
> Tamar
> 
> 
> 
> gcc/ChangeLog:
> 
> 	PR tree-optimizations/103253
> 	* tree-ssa-math-opts.c (convert_mult_to_fma): Check for LHS.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* gcc.dg/vect/pr103253.c: New test.
> 
> --- inline copy of patch -- 
> diff --git a/gcc/testsuite/gcc.dg/vect/pr103253.c b/gcc/testsuite/gcc.dg/vect/pr103253.c
> new file mode 100644
> index 0000000000000000000000000000000000000000..abe3f09f3818d79a53f2aa962c6b6c06855d618e
> --- /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 c4a6492b50df25b4cf296a75bd51e5af34eeacc7..cc8496c3c325f3cc303a90b9b9cac383e5a7942d 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;
> 
> 
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg,
Germany; GF: Ivo Totev; HRB 36809 (AG Nuernberg)

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

end of thread, other threads:[~2021-11-18 11:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-16 15:35 [PATCH]middle-end: Fix FMA detection when inspecting gimple which have no LHS Tamar Christina
2021-11-18 11:06 ` Richard Biener

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