public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH][Backport][GCC10] Fix SSA corruption due to widening_mul opt on conflict across an abnormal edge [PR111407]
@ 2024-04-01 13:35 Qing Zhao
  2024-04-02  7:06 ` Richard Biener
  0 siblings, 1 reply; 3+ messages in thread
From: Qing Zhao @ 2024-04-01 13:35 UTC (permalink / raw)
  To: gcc-patches; +Cc: pinskia, Qing Zhao

This is a bug in tree-ssa-math-opts.c, when applying the widening mul
optimization, the compiler needs to check whether the operand is in a
ABNORMAL PHI, if YES, we should avoid the transformation.

	PR tree-optimization/111407

gcc/ChangeLog:

	* tree-ssa-math-opts.c (convert_mult_to_widen): Avoid the transform
	when one of the operands is subject to abnormal coalescing.

gcc/testsuite/ChangeLog:

	* gcc.dg/pr111407.c: New test.

(cherry picked from commit 4aca1cfd6235090e48a53dab734437740671bbf3)

bootstraped and regression tested on both aarch64 and x86.

Okay for commit to GCC10?

thanks.

Qing
---
 gcc/testsuite/gcc.dg/pr111407.c | 21 +++++++++++++++++++++
 gcc/tree-ssa-math-opts.c        |  8 ++++++++
 2 files changed, 29 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/pr111407.c

diff --git a/gcc/testsuite/gcc.dg/pr111407.c b/gcc/testsuite/gcc.dg/pr111407.c
new file mode 100644
index 000000000000..a171074753f9
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr111407.c
@@ -0,0 +1,21 @@
+/* PR tree-optimization/111407*/
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+enum { SEND_TOFILE } __sigsetjmp();
+void fclose();
+void foldergets();
+void sendpart_stats(int *p1, int a1, int b1) {
+ int *a = p1;
+ fclose();
+ p1 = 0;
+ long t = b1;
+ if (__sigsetjmp()) {
+   {
+     long t1 = a1;
+     a1+=1;
+     fclose(a1*(long)t1);
+   }
+ }
+ if (p1)
+   fclose();
+}
diff --git a/gcc/tree-ssa-math-opts.c b/gcc/tree-ssa-math-opts.c
index dd0b8c6f0577..47981da20e05 100644
--- a/gcc/tree-ssa-math-opts.c
+++ b/gcc/tree-ssa-math-opts.c
@@ -2543,6 +2543,14 @@ convert_mult_to_widen (gimple *stmt, gimple_stmt_iterator *gsi)
   if (!is_widening_mult_p (stmt, &type1, &rhs1, &type2, &rhs2))
     return false;
 
+  /* if any one of rhs1 and rhs2 is subject to abnormal coalescing,
+     avoid the tranform. */
+  if ((TREE_CODE (rhs1) == SSA_NAME
+       && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (rhs1))
+      || (TREE_CODE (rhs2) == SSA_NAME
+	  && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (rhs2)))
+    return false;
+
   to_mode = SCALAR_INT_TYPE_MODE (type);
   from_mode = SCALAR_INT_TYPE_MODE (type1);
   if (to_mode == from_mode)
-- 
2.31.1


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

* Re: [PATCH][Backport][GCC10] Fix SSA corruption due to widening_mul opt on conflict across an abnormal edge [PR111407]
  2024-04-01 13:35 [PATCH][Backport][GCC10] Fix SSA corruption due to widening_mul opt on conflict across an abnormal edge [PR111407] Qing Zhao
@ 2024-04-02  7:06 ` Richard Biener
  2024-04-02 13:29   ` Qing Zhao
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Biener @ 2024-04-02  7:06 UTC (permalink / raw)
  To: Qing Zhao; +Cc: gcc-patches, pinskia

On Mon, Apr 1, 2024 at 3:36 PM Qing Zhao <qing.zhao@oracle.com> wrote:
>
> This is a bug in tree-ssa-math-opts.c, when applying the widening mul
> optimization, the compiler needs to check whether the operand is in a
> ABNORMAL PHI, if YES, we should avoid the transformation.
>
>         PR tree-optimization/111407
>
> gcc/ChangeLog:
>
>         * tree-ssa-math-opts.c (convert_mult_to_widen): Avoid the transform
>         when one of the operands is subject to abnormal coalescing.
>
> gcc/testsuite/ChangeLog:
>
>         * gcc.dg/pr111407.c: New test.
>
> (cherry picked from commit 4aca1cfd6235090e48a53dab734437740671bbf3)
>
> bootstraped and regression tested on both aarch64 and x86.
>
> Okay for commit to GCC10?

Note the GCC 10 branch is closed.  If the patch boostraps/tests on the
11, 12 and 13
branches it is OK there.  You do not need approval to backport fixes
for _regressions_
if the patch cherry-picks without major edits and boostraps/tests OK.

Thanks,
Richard.

> thanks.
>
> Qing
> ---
>  gcc/testsuite/gcc.dg/pr111407.c | 21 +++++++++++++++++++++
>  gcc/tree-ssa-math-opts.c        |  8 ++++++++
>  2 files changed, 29 insertions(+)
>  create mode 100644 gcc/testsuite/gcc.dg/pr111407.c
>
> diff --git a/gcc/testsuite/gcc.dg/pr111407.c b/gcc/testsuite/gcc.dg/pr111407.c
> new file mode 100644
> index 000000000000..a171074753f9
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/pr111407.c
> @@ -0,0 +1,21 @@
> +/* PR tree-optimization/111407*/
> +/* { dg-do compile } */
> +/* { dg-options "-O2" } */
> +enum { SEND_TOFILE } __sigsetjmp();
> +void fclose();
> +void foldergets();
> +void sendpart_stats(int *p1, int a1, int b1) {
> + int *a = p1;
> + fclose();
> + p1 = 0;
> + long t = b1;
> + if (__sigsetjmp()) {
> +   {
> +     long t1 = a1;
> +     a1+=1;
> +     fclose(a1*(long)t1);
> +   }
> + }
> + if (p1)
> +   fclose();
> +}
> diff --git a/gcc/tree-ssa-math-opts.c b/gcc/tree-ssa-math-opts.c
> index dd0b8c6f0577..47981da20e05 100644
> --- a/gcc/tree-ssa-math-opts.c
> +++ b/gcc/tree-ssa-math-opts.c
> @@ -2543,6 +2543,14 @@ convert_mult_to_widen (gimple *stmt, gimple_stmt_iterator *gsi)
>    if (!is_widening_mult_p (stmt, &type1, &rhs1, &type2, &rhs2))
>      return false;
>
> +  /* if any one of rhs1 and rhs2 is subject to abnormal coalescing,
> +     avoid the tranform. */
> +  if ((TREE_CODE (rhs1) == SSA_NAME
> +       && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (rhs1))
> +      || (TREE_CODE (rhs2) == SSA_NAME
> +         && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (rhs2)))
> +    return false;
> +
>    to_mode = SCALAR_INT_TYPE_MODE (type);
>    from_mode = SCALAR_INT_TYPE_MODE (type1);
>    if (to_mode == from_mode)
> --
> 2.31.1
>

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

* Re: [PATCH][Backport][GCC10] Fix SSA corruption due to widening_mul opt on conflict across an abnormal edge [PR111407]
  2024-04-02  7:06 ` Richard Biener
@ 2024-04-02 13:29   ` Qing Zhao
  0 siblings, 0 replies; 3+ messages in thread
From: Qing Zhao @ 2024-04-02 13:29 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches, pinskia

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



On Apr 2, 2024, at 03:06, Richard Biener <richard.guenther@gmail.com> wrote:

On Mon, Apr 1, 2024 at 3:36 PM Qing Zhao <qing.zhao@oracle.com<mailto:qing.zhao@oracle.com>> wrote:

This is a bug in tree-ssa-math-opts.c, when applying the widening mul
optimization, the compiler needs to check whether the operand is in a
ABNORMAL PHI, if YES, we should avoid the transformation.

       PR tree-optimization/111407

gcc/ChangeLog:

       * tree-ssa-math-opts.c (convert_mult_to_widen): Avoid the transform
       when one of the operands is subject to abnormal coalescing.

gcc/testsuite/ChangeLog:

       * gcc.dg/pr111407.c: New test.

(cherry picked from commit 4aca1cfd6235090e48a53dab734437740671bbf3)

bootstraped and regression tested on both aarch64 and x86.

Okay for commit to GCC10?

Note the GCC 10 branch is closed.  If the patch boostraps/tests on the
11, 12 and 13
branches it is OK there.  You do not need approval to backport fixes
for _regressions_
if the patch cherry-picks without major edits and boostraps/tests OK.

Thanks for the info.

I will commit the patches for GCC11, 12, and 13 soon.

Qing

Thanks,
Richard.

thanks.

Qing
---
gcc/testsuite/gcc.dg/pr111407.c | 21 +++++++++++++++++++++
gcc/tree-ssa-math-opts.c        |  8 ++++++++
2 files changed, 29 insertions(+)
create mode 100644 gcc/testsuite/gcc.dg/pr111407.c

diff --git a/gcc/testsuite/gcc.dg/pr111407.c b/gcc/testsuite/gcc.dg/pr111407.c
new file mode 100644
index 000000000000..a171074753f9
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr111407.c
@@ -0,0 +1,21 @@
+/* PR tree-optimization/111407*/
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+enum { SEND_TOFILE } __sigsetjmp();
+void fclose();
+void foldergets();
+void sendpart_stats(int *p1, int a1, int b1) {
+ int *a = p1;
+ fclose();
+ p1 = 0;
+ long t = b1;
+ if (__sigsetjmp()) {
+   {
+     long t1 = a1;
+     a1+=1;
+     fclose(a1*(long)t1);
+   }
+ }
+ if (p1)
+   fclose();
+}
diff --git a/gcc/tree-ssa-math-opts.c b/gcc/tree-ssa-math-opts.c
index dd0b8c6f0577..47981da20e05 100644
--- a/gcc/tree-ssa-math-opts.c
+++ b/gcc/tree-ssa-math-opts.c
@@ -2543,6 +2543,14 @@ convert_mult_to_widen (gimple *stmt, gimple_stmt_iterator *gsi)
  if (!is_widening_mult_p (stmt, &type1, &rhs1, &type2, &rhs2))
    return false;

+  /* if any one of rhs1 and rhs2 is subject to abnormal coalescing,
+     avoid the tranform. */
+  if ((TREE_CODE (rhs1) == SSA_NAME
+       && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (rhs1))
+      || (TREE_CODE (rhs2) == SSA_NAME
+         && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (rhs2)))
+    return false;
+
  to_mode = SCALAR_INT_TYPE_MODE (type);
  from_mode = SCALAR_INT_TYPE_MODE (type1);
  if (to_mode == from_mode)
--
2.31.1


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

end of thread, other threads:[~2024-04-02 13:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-01 13:35 [PATCH][Backport][GCC10] Fix SSA corruption due to widening_mul opt on conflict across an abnormal edge [PR111407] Qing Zhao
2024-04-02  7:06 ` Richard Biener
2024-04-02 13:29   ` Qing Zhao

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