x86: Fix up ix86_atomic_assign_expand_fenv [PR94780]

Message ID 20200427182550.GC2424@tucnak
State New
Headers show
Series
  • x86: Fix up ix86_atomic_assign_expand_fenv [PR94780]
Related show

Commit Message

Jakub Jelinek via Gcc-patches April 27, 2020, 6:25 p.m.
Hi!

This function, because it is sometimes called even outside of function
bodies, uses create_tmp_var_raw rather than create_tmp_var.  But in order
for that to work, when first referenced, the VAR_DECLs need to appear in a
TARGET_EXPR so that during gimplification the var gets the right
DECL_CONTEXT and is added to local decls.  Without that, e.g. tree-nested.c
ICEs on those.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?

2020-04-27  Jakub Jelinek  <jakub@redhat.com>

	PR target/94780
	* config/i386/i386.c (ix86_atomic_assign_expand_fenv): Use
	TARGET_EXPR instead of MODIFY_EXPR for first assignment to
	sw_var, exceptions_var, mxcsr_orig_var and mxcsr_mod_var.

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


	Jakub

Comments

Jakub Jelinek via Gcc-patches April 27, 2020, 7:13 p.m. | #1
On Mon, Apr 27, 2020 at 8:26 PM Jakub Jelinek <jakub@redhat.com> wrote:
>

> Hi!

>

> This function, because it is sometimes called even outside of function

> bodies, uses create_tmp_var_raw rather than create_tmp_var.  But in order

> for that to work, when first referenced, the VAR_DECLs need to appear in a

> TARGET_EXPR so that during gimplification the var gets the right

> DECL_CONTEXT and is added to local decls.  Without that, e.g. tree-nested.c

> ICEs on those.

>

> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for

> trunk?

>

> 2020-04-27  Jakub Jelinek  <jakub@redhat.com>

>

>         PR target/94780

>         * config/i386/i386.c (ix86_atomic_assign_expand_fenv): Use

>         TARGET_EXPR instead of MODIFY_EXPR for first assignment to

>         sw_var, exceptions_var, mxcsr_orig_var and mxcsr_mod_var.

>

>         * gcc.dg/pr94780.c: New test.


I don't know much about this part, but rubber-stamped OK.

Thanks,
Uros.

> --- gcc/config/i386/i386.c.jj   2020-04-27 14:31:09.126020786 +0200

> +++ gcc/config/i386/i386.c      2020-04-27 15:10:39.514407179 +0200

> @@ -22390,11 +22390,12 @@ ix86_atomic_assign_expand_fenv (tree *ho

>        *clear = build_call_expr (fnclex, 0);

>        tree sw_var = create_tmp_var_raw (short_unsigned_type_node);

>        tree fnstsw_call = build_call_expr (fnstsw, 0);

> -      tree sw_mod = build2 (MODIFY_EXPR, short_unsigned_type_node,

> -                           sw_var, fnstsw_call);

> +      tree sw_mod = build4 (TARGET_EXPR, short_unsigned_type_node, sw_var,

> +                           fnstsw_call, NULL_TREE, NULL_TREE);

>        tree exceptions_x87 = fold_convert (integer_type_node, sw_var);

> -      tree update_mod = build2 (MODIFY_EXPR, integer_type_node,

> -                               exceptions_var, exceptions_x87);

> +      tree update_mod = build4 (TARGET_EXPR, integer_type_node,

> +                               exceptions_var, exceptions_x87,

> +                               NULL_TREE, NULL_TREE);

>        *update = build2 (COMPOUND_EXPR, integer_type_node,

>                         sw_mod, update_mod);

>        tree update_fldenv = build_call_expr (fldenv, 1, fenv_addr);

> @@ -22407,15 +22408,17 @@ ix86_atomic_assign_expand_fenv (tree *ho

>        tree stmxcsr = get_ix86_builtin (IX86_BUILTIN_STMXCSR);

>        tree ldmxcsr = get_ix86_builtin (IX86_BUILTIN_LDMXCSR);

>        tree stmxcsr_hold_call = build_call_expr (stmxcsr, 0);

> -      tree hold_assign_orig = build2 (MODIFY_EXPR, unsigned_type_node,

> -                                     mxcsr_orig_var, stmxcsr_hold_call);

> +      tree hold_assign_orig = build4 (TARGET_EXPR, unsigned_type_node,

> +                                     mxcsr_orig_var, stmxcsr_hold_call,

> +                                     NULL_TREE, NULL_TREE);

>        tree hold_mod_val = build2 (BIT_IOR_EXPR, unsigned_type_node,

>                                   mxcsr_orig_var,

>                                   build_int_cst (unsigned_type_node, 0x1f80));

>        hold_mod_val = build2 (BIT_AND_EXPR, unsigned_type_node, hold_mod_val,

>                              build_int_cst (unsigned_type_node, 0xffffffc0));

> -      tree hold_assign_mod = build2 (MODIFY_EXPR, unsigned_type_node,

> -                                    mxcsr_mod_var, hold_mod_val);

> +      tree hold_assign_mod = build4 (TARGET_EXPR, unsigned_type_node,

> +                                    mxcsr_mod_var, hold_mod_val,

> +                                    NULL_TREE, NULL_TREE);

>        tree ldmxcsr_hold_call = build_call_expr (ldmxcsr, 1, mxcsr_mod_var);

>        tree hold_all = build2 (COMPOUND_EXPR, unsigned_type_node,

>                               hold_assign_orig, hold_assign_mod);

> @@ -22444,8 +22447,8 @@ ix86_atomic_assign_expand_fenv (tree *ho

>                             exceptions_assign);

>         }

>        else

> -       *update = build2 (MODIFY_EXPR, integer_type_node,

> -                         exceptions_var, exceptions_sse);

> +       *update = build4 (TARGET_EXPR, integer_type_node, exceptions_var,

> +                         exceptions_sse, NULL_TREE, NULL_TREE);

>        tree ldmxcsr_update_call = build_call_expr (ldmxcsr, 1, mxcsr_orig_var);

>        *update = build2 (COMPOUND_EXPR, void_type_node, *update,

>                         ldmxcsr_update_call);

> --- gcc/testsuite/gcc.dg/pr94780.c.jj   2020-04-27 15:25:48.916854107 +0200

> +++ gcc/testsuite/gcc.dg/pr94780.c      2020-04-27 15:25:05.921501837 +0200

> @@ -0,0 +1,13 @@

> +/* PR target/94780 */

> +/* { dg-do compile } */

> +/* { dg-options "-O2" } */

> +

> +_Atomic double x;

> +

> +double

> +foo (void)

> +{

> +  double bar () { return x; }

> +  x /= 3;

> +  return bar ();

> +}

>

>         Jakub

>

Patch

--- gcc/config/i386/i386.c.jj	2020-04-27 14:31:09.126020786 +0200
+++ gcc/config/i386/i386.c	2020-04-27 15:10:39.514407179 +0200
@@ -22390,11 +22390,12 @@  ix86_atomic_assign_expand_fenv (tree *ho
       *clear = build_call_expr (fnclex, 0);
       tree sw_var = create_tmp_var_raw (short_unsigned_type_node);
       tree fnstsw_call = build_call_expr (fnstsw, 0);
-      tree sw_mod = build2 (MODIFY_EXPR, short_unsigned_type_node,
-			    sw_var, fnstsw_call);
+      tree sw_mod = build4 (TARGET_EXPR, short_unsigned_type_node, sw_var,
+			    fnstsw_call, NULL_TREE, NULL_TREE);
       tree exceptions_x87 = fold_convert (integer_type_node, sw_var);
-      tree update_mod = build2 (MODIFY_EXPR, integer_type_node,
-				exceptions_var, exceptions_x87);
+      tree update_mod = build4 (TARGET_EXPR, integer_type_node,
+				exceptions_var, exceptions_x87,
+				NULL_TREE, NULL_TREE);
       *update = build2 (COMPOUND_EXPR, integer_type_node,
 			sw_mod, update_mod);
       tree update_fldenv = build_call_expr (fldenv, 1, fenv_addr);
@@ -22407,15 +22408,17 @@  ix86_atomic_assign_expand_fenv (tree *ho
       tree stmxcsr = get_ix86_builtin (IX86_BUILTIN_STMXCSR);
       tree ldmxcsr = get_ix86_builtin (IX86_BUILTIN_LDMXCSR);
       tree stmxcsr_hold_call = build_call_expr (stmxcsr, 0);
-      tree hold_assign_orig = build2 (MODIFY_EXPR, unsigned_type_node,
-				      mxcsr_orig_var, stmxcsr_hold_call);
+      tree hold_assign_orig = build4 (TARGET_EXPR, unsigned_type_node,
+				      mxcsr_orig_var, stmxcsr_hold_call,
+				      NULL_TREE, NULL_TREE);
       tree hold_mod_val = build2 (BIT_IOR_EXPR, unsigned_type_node,
 				  mxcsr_orig_var,
 				  build_int_cst (unsigned_type_node, 0x1f80));
       hold_mod_val = build2 (BIT_AND_EXPR, unsigned_type_node, hold_mod_val,
 			     build_int_cst (unsigned_type_node, 0xffffffc0));
-      tree hold_assign_mod = build2 (MODIFY_EXPR, unsigned_type_node,
-				     mxcsr_mod_var, hold_mod_val);
+      tree hold_assign_mod = build4 (TARGET_EXPR, unsigned_type_node,
+				     mxcsr_mod_var, hold_mod_val,
+				     NULL_TREE, NULL_TREE);
       tree ldmxcsr_hold_call = build_call_expr (ldmxcsr, 1, mxcsr_mod_var);
       tree hold_all = build2 (COMPOUND_EXPR, unsigned_type_node,
 			      hold_assign_orig, hold_assign_mod);
@@ -22444,8 +22447,8 @@  ix86_atomic_assign_expand_fenv (tree *ho
 			    exceptions_assign);
 	}
       else
-	*update = build2 (MODIFY_EXPR, integer_type_node,
-			  exceptions_var, exceptions_sse);
+	*update = build4 (TARGET_EXPR, integer_type_node, exceptions_var,
+			  exceptions_sse, NULL_TREE, NULL_TREE);
       tree ldmxcsr_update_call = build_call_expr (ldmxcsr, 1, mxcsr_orig_var);
       *update = build2 (COMPOUND_EXPR, void_type_node, *update,
 			ldmxcsr_update_call);
--- gcc/testsuite/gcc.dg/pr94780.c.jj	2020-04-27 15:25:48.916854107 +0200
+++ gcc/testsuite/gcc.dg/pr94780.c	2020-04-27 15:25:05.921501837 +0200
@@ -0,0 +1,13 @@ 
+/* PR target/94780 */
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+_Atomic double x;
+
+double
+foo (void)
+{
+  double bar () { return x; }
+  x /= 3;
+  return bar ();
+}