diff mbox

[C++] Fix ICEs with #pragma GCC ivdep (PR c++/79379)

Message ID 20170206193002.GM1849@tucnak
State New
Headers show

Commit Message

Jakub Jelinek Feb. 6, 2017, 7:30 p.m. UTC
Hi!

#pragma GCC ivdep can make it through into potential_constant_expression_1
as the following testcase shows.  As it is just a hint to the compiler,
I think it isn't needed to make loops with that pragma non-constexpr, so
the patch just ignores the hint for determination of what is a potential
constant expression and ditto in cxx_eval_constant_expression.  The pragma
is represented by ANNOTATE_EXPR with first operand being the condition
of the loop and second operand annot_expr_ivdep_kind.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2017-02-06  Jakub Jelinek  <jakub@redhat.com>

	PR c++/79379
	* constexpr.c (cxx_eval_constant_expression): Handle ANNOTATE_EXPR.
	(potential_constant_expression_1): Likewise.

	* g++.dg/cpp1y/constexpr-79379.C: New test.


	Jakub

Comments

Jason Merrill Feb. 6, 2017, 7:54 p.m. UTC | #1
OK.

On Mon, Feb 6, 2017 at 2:30 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> Hi!
>
> #pragma GCC ivdep can make it through into potential_constant_expression_1
> as the following testcase shows.  As it is just a hint to the compiler,
> I think it isn't needed to make loops with that pragma non-constexpr, so
> the patch just ignores the hint for determination of what is a potential
> constant expression and ditto in cxx_eval_constant_expression.  The pragma
> is represented by ANNOTATE_EXPR with first operand being the condition
> of the loop and second operand annot_expr_ivdep_kind.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
>
> 2017-02-06  Jakub Jelinek  <jakub@redhat.com>
>
>         PR c++/79379
>         * constexpr.c (cxx_eval_constant_expression): Handle ANNOTATE_EXPR.
>         (potential_constant_expression_1): Likewise.
>
>         * g++.dg/cpp1y/constexpr-79379.C: New test.
>
> --- gcc/cp/constexpr.c.jj       2017-02-03 23:35:37.000000000 +0100
> +++ gcc/cp/constexpr.c  2017-02-06 16:00:21.903921006 +0100
> @@ -4518,6 +4518,14 @@ cxx_eval_constant_expression (const cons
>          *non_constant_p = true;
>        return t;
>
> +    case ANNOTATE_EXPR:
> +      gcc_assert (tree_to_uhwi (TREE_OPERAND (t, 1)) == annot_expr_ivdep_kind);
> +      r = cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 0),
> +                                       lval,
> +                                       non_constant_p, overflow_p,
> +                                       jump_target);
> +      break;
> +
>      default:
>        if (STATEMENT_CODE_P (TREE_CODE (t)))
>         {
> @@ -5689,6 +5697,10 @@ potential_constant_expression_1 (tree t,
>         return false;
>        }
>
> +    case ANNOTATE_EXPR:
> +      gcc_assert (tree_to_uhwi (TREE_OPERAND (t, 1)) == annot_expr_ivdep_kind);
> +      return RECUR (TREE_OPERAND (t, 0), rval);
> +
>      default:
>        if (objc_is_property_ref (t))
>         return false;
> --- gcc/testsuite/g++.dg/cpp1y/constexpr-79379.C.jj     2017-02-06 16:09:30.457863715 +0100
> +++ gcc/testsuite/g++.dg/cpp1y/constexpr-79379.C        2017-02-06 16:08:49.000000000 +0100
> @@ -0,0 +1,19 @@
> +// PR c++/79379
> +// { dg-do compile { target c++14 } }
> +// { dg-options "-O2" }
> +
> +template <int N>
> +constexpr int
> +foo (int x)
> +{
> +  int q[64] = { 0 }, r = 0;
> +#pragma GCC ivdep
> +  for (int i = 0; i < x; ++i)
> +    q[i] += 2;
> +  for (int i = 0; i < x; ++i)
> +    r += q[i];
> +  return r + N;
> +}
> +
> +constexpr int a = foo<0> (17);
> +static_assert (a == 34, "");
>
>         Jakub
diff mbox

Patch

--- gcc/cp/constexpr.c.jj	2017-02-03 23:35:37.000000000 +0100
+++ gcc/cp/constexpr.c	2017-02-06 16:00:21.903921006 +0100
@@ -4518,6 +4518,14 @@  cxx_eval_constant_expression (const cons
         *non_constant_p = true;
       return t;
 
+    case ANNOTATE_EXPR:
+      gcc_assert (tree_to_uhwi (TREE_OPERAND (t, 1)) == annot_expr_ivdep_kind);
+      r = cxx_eval_constant_expression (ctx, TREE_OPERAND (t, 0),
+					lval,
+					non_constant_p, overflow_p,
+					jump_target);
+      break;
+
     default:
       if (STATEMENT_CODE_P (TREE_CODE (t)))
 	{
@@ -5689,6 +5697,10 @@  potential_constant_expression_1 (tree t,
 	return false;
       }
 
+    case ANNOTATE_EXPR:
+      gcc_assert (tree_to_uhwi (TREE_OPERAND (t, 1)) == annot_expr_ivdep_kind);
+      return RECUR (TREE_OPERAND (t, 0), rval);
+
     default:
       if (objc_is_property_ref (t))
 	return false;
--- gcc/testsuite/g++.dg/cpp1y/constexpr-79379.C.jj	2017-02-06 16:09:30.457863715 +0100
+++ gcc/testsuite/g++.dg/cpp1y/constexpr-79379.C	2017-02-06 16:08:49.000000000 +0100
@@ -0,0 +1,19 @@ 
+// PR c++/79379
+// { dg-do compile { target c++14 } }
+// { dg-options "-O2" }
+
+template <int N>
+constexpr int
+foo (int x)
+{
+  int q[64] = { 0 }, r = 0;
+#pragma GCC ivdep
+  for (int i = 0; i < x; ++i)
+    q[i] += 2;
+  for (int i = 0; i < x; ++i)
+    r += q[i];
+  return r + N;
+}
+
+constexpr int a = foo<0> (17);
+static_assert (a == 34, "");