diff mbox series

[PR86097] Generate correctly typed compare in canonicalize_loop_ivs

Message ID 20180620143733.iwb4jbgihhf3iqaz@localhost.localdomain
State New
Headers show
Series [PR86097] Generate correctly typed compare in canonicalize_loop_ivs | expand

Commit Message

Tom de Vries June 20, 2018, 2:37 p.m. UTC
Hi,

Consider the test-case from the patch. When compiled with "-O2
-ftree-parallelize-loops=2 -fno-tree-dce", it ICEs like this:
...
error: mismatching comparison operand types
signed int
unsigned int
if (ivtmp_32 < 3)
during GIMPLE pass: parloops
pr86097.c:4:1: internal compiler error: verify_gimple failed
...

The comparison with signed int and unsigned int operands is generated during
the call to canonicalize_loop_ivs in the parloops pass.

Parloops calls canonicalize_loop_ivs with nit (the number of loop iterations)
set to (unsigned int)3. Then canonicalize_loop_ivs decides to use a canonical
iv of type signed int.  At the end of canonicalize_loop_ivs, the comparison
between the unsigned nit and the signed iv is constructed.

This patch fixes the ICE by ensuring that nit is casted to the iv type in this
case.

Bootstrapped and reg-tested on x86_64.

OK for trunk?

Thanks,
- Tom

Generate correctly typed compare in canonicalize_loop_ivs

2018-06-20  Tom de Vries  <tdevries@suse.de>

	PR tree-optimization/86097
	* tree-ssa-loop-manip.c (canonicalize_loop_ivs): Also convert *nit to
	iv type if signedness of iv type is not the same as that of *nit.

	* gcc.dg/autopar/pr86097.c: New test.

---
 gcc/testsuite/gcc.dg/autopar/pr86097.c | 31 +++++++++++++++++++++++++++++++
 gcc/tree-ssa-loop-manip.c              |  3 ++-
 2 files changed, 33 insertions(+), 1 deletion(-)

Comments

Richard Biener June 20, 2018, 2:39 p.m. UTC | #1
On Wed, 20 Jun 2018, Tom de Vries wrote:

> Hi,
> 
> Consider the test-case from the patch. When compiled with "-O2
> -ftree-parallelize-loops=2 -fno-tree-dce", it ICEs like this:
> ...
> error: mismatching comparison operand types
> signed int
> unsigned int
> if (ivtmp_32 < 3)
> during GIMPLE pass: parloops
> pr86097.c:4:1: internal compiler error: verify_gimple failed
> ...
> 
> The comparison with signed int and unsigned int operands is generated during
> the call to canonicalize_loop_ivs in the parloops pass.
> 
> Parloops calls canonicalize_loop_ivs with nit (the number of loop iterations)
> set to (unsigned int)3. Then canonicalize_loop_ivs decides to use a canonical
> iv of type signed int.  At the end of canonicalize_loop_ivs, the comparison
> between the unsigned nit and the signed iv is constructed.
> 
> This patch fixes the ICE by ensuring that nit is casted to the iv type in this
> case.
> 
> Bootstrapped and reg-tested on x86_64.
> 
> OK for trunk?

OK.

Thanks,
Richard.

> Thanks,
> - Tom
> 
> Generate correctly typed compare in canonicalize_loop_ivs
> 
> 2018-06-20  Tom de Vries  <tdevries@suse.de>
> 
> 	PR tree-optimization/86097
> 	* tree-ssa-loop-manip.c (canonicalize_loop_ivs): Also convert *nit to
> 	iv type if signedness of iv type is not the same as that of *nit.
> 
> 	* gcc.dg/autopar/pr86097.c: New test.
> 
> ---
>  gcc/testsuite/gcc.dg/autopar/pr86097.c | 31 +++++++++++++++++++++++++++++++
>  gcc/tree-ssa-loop-manip.c              |  3 ++-
>  2 files changed, 33 insertions(+), 1 deletion(-)
> 
> diff --git a/gcc/testsuite/gcc.dg/autopar/pr86097.c b/gcc/testsuite/gcc.dg/autopar/pr86097.c
> new file mode 100644
> index 00000000000..b48e87b8bf9
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/autopar/pr86097.c
> @@ -0,0 +1,31 @@
> +/* { dg-options "-O2 -ftree-parallelize-loops=2 -fno-tree-dce -Wno-aggressive-loop-optimizations" } */
> +int rp, vd;
> +
> +void
> +p5 (int cd)
> +{
> +  while (cd != 0)
> +    {
> +      for (rp = 0; rp < 4; ++rp)
> +        for (vd = 0; vd < 1; ++vd)
> +          {
> + g0:
> +            ;
> +          }
> +
> +      ++rp;
> +    }
> +
> +  while (rp < 2)
> +    {
> +      for (cd = 0; cd < 1; ++cd)
> +        for (rp = 1; rp != 0; ++rp)
> +          {
> +          }
> +
> +      ++rp;
> +    }
> +
> +  if (cd != 0)
> +    goto g0;
> +}
> diff --git a/gcc/tree-ssa-loop-manip.c b/gcc/tree-ssa-loop-manip.c
> index bf425afd436..5acee6c98f3 100644
> --- a/gcc/tree-ssa-loop-manip.c
> +++ b/gcc/tree-ssa-loop-manip.c
> @@ -1542,7 +1542,8 @@ canonicalize_loop_ivs (struct loop *loop, tree *nit, bool bump_in_latch)
>    precision = GET_MODE_PRECISION (mode);
>    type = build_nonstandard_integer_type (precision, unsigned_p);
>  
> -  if (original_precision != precision)
> +  if (original_precision != precision
> +      || TYPE_UNSIGNED (TREE_TYPE (*nit)) != unsigned_p)
>      {
>        *nit = fold_convert (type, *nit);
>        *nit = force_gimple_operand (*nit, &stmts, true, NULL_TREE);
> 
>
diff mbox series

Patch

diff --git a/gcc/testsuite/gcc.dg/autopar/pr86097.c b/gcc/testsuite/gcc.dg/autopar/pr86097.c
new file mode 100644
index 00000000000..b48e87b8bf9
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/autopar/pr86097.c
@@ -0,0 +1,31 @@ 
+/* { dg-options "-O2 -ftree-parallelize-loops=2 -fno-tree-dce -Wno-aggressive-loop-optimizations" } */
+int rp, vd;
+
+void
+p5 (int cd)
+{
+  while (cd != 0)
+    {
+      for (rp = 0; rp < 4; ++rp)
+        for (vd = 0; vd < 1; ++vd)
+          {
+ g0:
+            ;
+          }
+
+      ++rp;
+    }
+
+  while (rp < 2)
+    {
+      for (cd = 0; cd < 1; ++cd)
+        for (rp = 1; rp != 0; ++rp)
+          {
+          }
+
+      ++rp;
+    }
+
+  if (cd != 0)
+    goto g0;
+}
diff --git a/gcc/tree-ssa-loop-manip.c b/gcc/tree-ssa-loop-manip.c
index bf425afd436..5acee6c98f3 100644
--- a/gcc/tree-ssa-loop-manip.c
+++ b/gcc/tree-ssa-loop-manip.c
@@ -1542,7 +1542,8 @@  canonicalize_loop_ivs (struct loop *loop, tree *nit, bool bump_in_latch)
   precision = GET_MODE_PRECISION (mode);
   type = build_nonstandard_integer_type (precision, unsigned_p);
 
-  if (original_precision != precision)
+  if (original_precision != precision
+      || TYPE_UNSIGNED (TREE_TYPE (*nit)) != unsigned_p)
     {
       *nit = fold_convert (type, *nit);
       *nit = force_gimple_operand (*nit, &stmts, true, NULL_TREE);