public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix another ICE with complex assignment (PR middle-end/83608)
@ 2017-12-30 19:35 Jakub Jelinek
  2017-12-31  7:46 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2017-12-30 19:35 UTC (permalink / raw)
  To: Richard Biener, Jeff Law; +Cc: gcc-patches

Hi!

The comment on convert_modes says:
   Both modes may be floating, or both integer.
but as the testcase shows, with a MEM_REF with a different mode class
than a VAR_DECL as its operand we can end up with e.g. floating point vs.
integral mode etc. and convert_modes doesn't handle those cases.

This patch uses simplify_gen_subreg in those case first.

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

2017-12-30  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/83608
	* expr.c (store_expr_with_bounds): Use simplify_gen_subreg instead of
	convert_modes if target mode has the right side, but different mode
	class.

	* g++.dg/opt/pr83608.C: New test.

--- gcc/expr.c.jj	2017-12-30 14:35:52.095877981 +0100
+++ gcc/expr.c	2017-12-30 14:36:06.268882813 +0100
@@ -5638,8 +5638,21 @@ store_expr_with_bounds (tree exp, rtx ta
   if (CONSTANT_P (temp) && GET_MODE (temp) == VOIDmode
       && TREE_CODE (exp) != ERROR_MARK
       && GET_MODE (target) != TYPE_MODE (TREE_TYPE (exp)))
-    temp = convert_modes (GET_MODE (target), TYPE_MODE (TREE_TYPE (exp)),
-			  temp, TYPE_UNSIGNED (TREE_TYPE (exp)));
+    {
+      if (GET_MODE_CLASS (GET_MODE (target))
+	  != GET_MODE_CLASS (TYPE_MODE (TREE_TYPE (exp)))
+	  && GET_MODE_BITSIZE (GET_MODE (target))
+	     == GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (exp))))
+	{
+	  rtx t = simplify_gen_subreg (GET_MODE (target), temp,
+				       TYPE_MODE (TREE_TYPE (exp)), 0);
+	  if (t)
+	    temp = t;
+	}
+      if (GET_MODE (temp) == VOIDmode)
+	temp = convert_modes (GET_MODE (target), TYPE_MODE (TREE_TYPE (exp)),
+			      temp, TYPE_UNSIGNED (TREE_TYPE (exp)));
+    }
 
   /* If value was not generated in the target, store it there.
      Convert the value to TARGET's type first if necessary and emit the
--- gcc/testsuite/g++.dg/opt/pr83608.C.jj	2017-12-30 14:36:52.323898522 +0100
+++ gcc/testsuite/g++.dg/opt/pr83608.C	2017-12-30 14:00:12.811195532 +0100
@@ -0,0 +1,28 @@
+// PR middle-end/83608
+// { dg-do compile }
+// { dg-options "-O2" }
+
+template <typename> class B;
+template <> struct B<float>
+{
+  float foo () { return __real__ b; }
+  _Complex double b;
+};
+
+void bar (int);
+
+template <class T>
+void
+baz ()
+{
+  B<T> h;
+  T *a = (T *) &h;
+  a[0] = a[1] = 6;
+  h.foo () ? void () : bar (7);
+}
+
+int
+main ()
+{
+  baz<float> ();
+}

	Jakub

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

* Re: [PATCH] Fix another ICE with complex assignment (PR middle-end/83608)
  2017-12-30 19:35 [PATCH] Fix another ICE with complex assignment (PR middle-end/83608) Jakub Jelinek
@ 2017-12-31  7:46 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2017-12-31  7:46 UTC (permalink / raw)
  To: Jakub Jelinek, Jeff Law; +Cc: gcc-patches

On December 30, 2017 8:35:09 PM GMT+01:00, Jakub Jelinek <jakub@redhat.com> wrote:
>Hi!
>
>The comment on convert_modes says:
>   Both modes may be floating, or both integer.
>but as the testcase shows, with a MEM_REF with a different mode class
>than a VAR_DECL as its operand we can end up with e.g. floating point
>vs.
>integral mode etc. and convert_modes doesn't handle those cases.
>
>This patch uses simplify_gen_subreg in those case first.
>
>Bootstrapped/regtested on x86_64-linux and i686-linux, ok for
>trunk/7.3?

OK. 

Richard. 

>2017-12-30  Jakub Jelinek  <jakub@redhat.com>
>
>	PR middle-end/83608
>	* expr.c (store_expr_with_bounds): Use simplify_gen_subreg instead of
>	convert_modes if target mode has the right side, but different mode
>	class.
>
>	* g++.dg/opt/pr83608.C: New test.
>
>--- gcc/expr.c.jj	2017-12-30 14:35:52.095877981 +0100
>+++ gcc/expr.c	2017-12-30 14:36:06.268882813 +0100
>@@ -5638,8 +5638,21 @@ store_expr_with_bounds (tree exp, rtx ta
>   if (CONSTANT_P (temp) && GET_MODE (temp) == VOIDmode
>       && TREE_CODE (exp) != ERROR_MARK
>       && GET_MODE (target) != TYPE_MODE (TREE_TYPE (exp)))
>-    temp = convert_modes (GET_MODE (target), TYPE_MODE (TREE_TYPE
>(exp)),
>-			  temp, TYPE_UNSIGNED (TREE_TYPE (exp)));
>+    {
>+      if (GET_MODE_CLASS (GET_MODE (target))
>+	  != GET_MODE_CLASS (TYPE_MODE (TREE_TYPE (exp)))
>+	  && GET_MODE_BITSIZE (GET_MODE (target))
>+	     == GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (exp))))
>+	{
>+	  rtx t = simplify_gen_subreg (GET_MODE (target), temp,
>+				       TYPE_MODE (TREE_TYPE (exp)), 0);
>+	  if (t)
>+	    temp = t;
>+	}
>+      if (GET_MODE (temp) == VOIDmode)
>+	temp = convert_modes (GET_MODE (target), TYPE_MODE (TREE_TYPE (exp)),
>+			      temp, TYPE_UNSIGNED (TREE_TYPE (exp)));
>+    }
> 
>   /* If value was not generated in the target, store it there.
>     Convert the value to TARGET's type first if necessary and emit the
>--- gcc/testsuite/g++.dg/opt/pr83608.C.jj	2017-12-30 14:36:52.323898522
>+0100
>+++ gcc/testsuite/g++.dg/opt/pr83608.C	2017-12-30 14:00:12.811195532
>+0100
>@@ -0,0 +1,28 @@
>+// PR middle-end/83608
>+// { dg-do compile }
>+// { dg-options "-O2" }
>+
>+template <typename> class B;
>+template <> struct B<float>
>+{
>+  float foo () { return __real__ b; }
>+  _Complex double b;
>+};
>+
>+void bar (int);
>+
>+template <class T>
>+void
>+baz ()
>+{
>+  B<T> h;
>+  T *a = (T *) &h;
>+  a[0] = a[1] = 6;
>+  h.foo () ? void () : bar (7);
>+}
>+
>+int
>+main ()
>+{
>+  baz<float> ();
>+}
>
>	Jakub

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

end of thread, other threads:[~2017-12-31  7:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-30 19:35 [PATCH] Fix another ICE with complex assignment (PR middle-end/83608) Jakub Jelinek
2017-12-31  7:46 ` Richard Biener

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