diff mbox series

[v1] Genmatch: Fix ICE for binary phi cfg mismatching [PR116795]

Message ID 20240922104925.2058537-1-pan2.li@intel.com
State New
Headers show
Series [v1] Genmatch: Fix ICE for binary phi cfg mismatching [PR116795] | expand

Commit Message

Li, Pan2 Sept. 22, 2024, 10:49 a.m. UTC
From: Pan Li <pan2.li@intel.com>

This patch would like to fix one ICE when try to match the binary
phi for below cfg.  We check the first edge of the Phi block comes
from b0, instead of check the only one edge of b1 comes from the
b0 too.  Thus, it will result in some code to be recog as .SAT_SUB
but it is not, and finally result the verify_ssa failure.

+------+
| b0:  |
| def  |       +-----+
| ...  |       | b1: |
| cond |------>| def |
+------+       | ... |
   |           +-----+
   |              |
   |              |
   v              |
+-----+           |
| b2: |           |
| Phi |<----------+
+-----+

The below test suites are passed for this patch.
* The rv64gcv fully regression test.
* The x86 bootstrap test.
* The x86 fully regression test.

	PR target/116795

gcc/ChangeLog:

	* gimple-match-head.cc (match_cond_with_binary_phi): Fix the
	incorrect cfg check as b0->b1 in above example.

gcc/testsuite/ChangeLog:

	* gcc.dg/torture/pr116795-1.c: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
---
 gcc/gimple-match-head.cc                  |  2 +-
 gcc/testsuite/gcc.dg/torture/pr116795-1.c | 14 ++++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr116795-1.c

Comments

Richard Biener Sept. 23, 2024, 7:26 a.m. UTC | #1
On Sun, Sep 22, 2024 at 12:50 PM <pan2.li@intel.com> wrote:
>
> From: Pan Li <pan2.li@intel.com>
>
> This patch would like to fix one ICE when try to match the binary
> phi for below cfg.  We check the first edge of the Phi block comes
> from b0, instead of check the only one edge of b1 comes from the
> b0 too.  Thus, it will result in some code to be recog as .SAT_SUB
> but it is not, and finally result the verify_ssa failure.
>
> +------+
> | b0:  |
> | def  |       +-----+
> | ...  |       | b1: |
> | cond |------>| def |
> +------+       | ... |
>    |           +-----+
>    |              |
>    |              |
>    v              |
> +-----+           |
> | b2: |           |
> | Phi |<----------+
> +-----+
>
> The below test suites are passed for this patch.
> * The rv64gcv fully regression test.
> * The x86 bootstrap test.
> * The x86 fully regression test.

OK.

Thanks,
Richard.

>         PR target/116795
>
> gcc/ChangeLog:
>
>         * gimple-match-head.cc (match_cond_with_binary_phi): Fix the
>         incorrect cfg check as b0->b1 in above example.
>
> gcc/testsuite/ChangeLog:
>
>         * gcc.dg/torture/pr116795-1.c: New test.
>
> Signed-off-by: Pan Li <pan2.li@intel.com>
> ---
>  gcc/gimple-match-head.cc                  |  2 +-
>  gcc/testsuite/gcc.dg/torture/pr116795-1.c | 14 ++++++++++++++
>  2 files changed, 15 insertions(+), 1 deletion(-)
>  create mode 100644 gcc/testsuite/gcc.dg/torture/pr116795-1.c
>
> diff --git a/gcc/gimple-match-head.cc b/gcc/gimple-match-head.cc
> index b63b66e9485..b5d4a71ddc5 100644
> --- a/gcc/gimple-match-head.cc
> +++ b/gcc/gimple-match-head.cc
> @@ -402,7 +402,7 @@ match_cond_with_binary_phi (gphi *phi, tree *true_arg, tree *false_arg)
>    if (EDGE_COUNT (pred_b0->succs) == 2
>        && EDGE_COUNT (pred_b1->succs) == 1
>        && EDGE_COUNT (pred_b1->preds) == 1
> -      && pred_b0 == EDGE_PRED (gimple_bb (phi), 0)->src)
> +      && pred_b0 == EDGE_PRED (pred_b1, 0)->src)
>      /*
>       * +------+
>       * | b0:  |
> diff --git a/gcc/testsuite/gcc.dg/torture/pr116795-1.c b/gcc/testsuite/gcc.dg/torture/pr116795-1.c
> new file mode 100644
> index 00000000000..629bdf4bacd
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/torture/pr116795-1.c
> @@ -0,0 +1,14 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O3" } */
> +
> +volatile int a, b;
> +int c;
> +int main() {
> +  unsigned e = 0;
> +  for (; e < 2; e++) {
> +    a && b;
> +    if (c)
> +      e = -(c ^ e);
> +  }
> +  return 0;
> +}
> --
> 2.43.0
>
diff mbox series

Patch

diff --git a/gcc/gimple-match-head.cc b/gcc/gimple-match-head.cc
index b63b66e9485..b5d4a71ddc5 100644
--- a/gcc/gimple-match-head.cc
+++ b/gcc/gimple-match-head.cc
@@ -402,7 +402,7 @@  match_cond_with_binary_phi (gphi *phi, tree *true_arg, tree *false_arg)
   if (EDGE_COUNT (pred_b0->succs) == 2
       && EDGE_COUNT (pred_b1->succs) == 1
       && EDGE_COUNT (pred_b1->preds) == 1
-      && pred_b0 == EDGE_PRED (gimple_bb (phi), 0)->src)
+      && pred_b0 == EDGE_PRED (pred_b1, 0)->src)
     /*
      * +------+
      * | b0:  |
diff --git a/gcc/testsuite/gcc.dg/torture/pr116795-1.c b/gcc/testsuite/gcc.dg/torture/pr116795-1.c
new file mode 100644
index 00000000000..629bdf4bacd
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr116795-1.c
@@ -0,0 +1,14 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O3" } */
+
+volatile int a, b;
+int c;
+int main() {
+  unsigned e = 0;
+  for (; e < 2; e++) {
+    a && b;
+    if (c)
+      e = -(c ^ e);
+  }
+  return 0;
+}