diff mbox

Fix self-comparison folding when honoring NaNs (PR tree-optimization/70317)

Message ID 20160321202137.GI3017@tucnak.redhat.com
State New
Headers show

Commit Message

Jakub Jelinek March 21, 2016, 8:21 p.m. UTC
Hi!

HONOR_NANS when called on a tree or its type handles properly
vector/complex element modes, but HONOR_NANS (TYPE_MODE (TREE_TYPE (...)))
does not.

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

2016-03-21  Marc Glisse  <marc.glisse@inria.fr>
	    Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/70317
	* match.pd (cmp @0 @0): Pass @0 instead of TYPE_MODE (TREE_TYPE (@0))
	to HONOR_NANS.

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


	Jakub

Comments

Jeff Law March 21, 2016, 8:43 p.m. UTC | #1
On 03/21/2016 02:21 PM, Jakub Jelinek wrote:
> Hi!
>
> HONOR_NANS when called on a tree or its type handles properly
> vector/complex element modes, but HONOR_NANS (TYPE_MODE (TREE_TYPE (...)))
> does not.
>
> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
> trunk?
>
> 2016-03-21  Marc Glisse  <marc.glisse@inria.fr>
> 	    Jakub Jelinek  <jakub@redhat.com>
>
> 	PR tree-optimization/70317
> 	* match.pd (cmp @0 @0): Pass @0 instead of TYPE_MODE (TREE_TYPE (@0))
> 	to HONOR_NANS.
>
> 	* gcc.dg/pr70317.c: New test.
Presumably this is the need to look at the mode of the inner type for 
vectors, right?

OK.

jeff
Jakub Jelinek March 21, 2016, 8:50 p.m. UTC | #2
On Mon, Mar 21, 2016 at 02:43:23PM -0600, Jeff Law wrote:
> On 03/21/2016 02:21 PM, Jakub Jelinek wrote:
> >Hi!
> >
> >HONOR_NANS when called on a tree or its type handles properly
> >vector/complex element modes, but HONOR_NANS (TYPE_MODE (TREE_TYPE (...)))
> >does not.
> >
> >Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
> >trunk?
> >
> >2016-03-21  Marc Glisse  <marc.glisse@inria.fr>
> >	    Jakub Jelinek  <jakub@redhat.com>
> >
> >	PR tree-optimization/70317
> >	* match.pd (cmp @0 @0): Pass @0 instead of TYPE_MODE (TREE_TYPE (@0))
> >	to HONOR_NANS.
> >
> >	* gcc.dg/pr70317.c: New test.
> Presumably this is the need to look at the mode of the inner type for
> vectors, right?

HONOR_NANS (tree t) is HONOR_NANS (element_mode (t)), where element_mode is
  if (!TYPE_P (t))
    t = TREE_TYPE (t);
  if (VECTOR_TYPE_P (t) || TREE_CODE (t) == COMPLEX_TYPE)
    t = TREE_TYPE (t);
  return TYPE_MODE (t);

	Jakub
diff mbox

Patch

--- gcc/match.pd.jj	2016-03-17 12:43:28.000000000 +0100
+++ gcc/match.pd	2016-03-21 17:45:36.332282052 +0100
@@ -1866,7 +1866,7 @@  DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
  (simplify
   (cmp @0 @0)
   (if (! FLOAT_TYPE_P (TREE_TYPE (@0))
-       || ! HONOR_NANS (TYPE_MODE (TREE_TYPE (@0))))
+       || ! HONOR_NANS (@0))
    { constant_boolean_node (true, type); }
    (if (cmp != EQ_EXPR)
     (eq @0 @0)))))
@@ -1875,7 +1875,7 @@  DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
   (cmp @0 @0)
   (if (cmp != NE_EXPR
        || ! FLOAT_TYPE_P (TREE_TYPE (@0))
-       || ! HONOR_NANS (TYPE_MODE (TREE_TYPE (@0))))
+       || ! HONOR_NANS (@0))
    { constant_boolean_node (false, type); })))
 (for cmp (unle unge uneq)
  (simplify
--- gcc/testsuite/gcc.dg/pr70317.c.jj	2016-03-21 17:43:47.167760535 +0100
+++ gcc/testsuite/gcc.dg/pr70317.c	2016-03-21 17:44:47.634941590 +0100
@@ -0,0 +1,26 @@ 
+/* PR tree-optimization/70317 */
+/* { dg-do compile } */
+/* { dg-skip-if "No NaN support" { spu*-*-* vax*-*-* pdp11*-*-* } } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+typedef double V __attribute__((vector_size (256)));
+typedef __typeof ((V) {} < (V) {}) T;
+T a, b;
+
+__attribute__((noinline, noclone, optimize ("finite-math-only"))) void
+foo (V *x)
+{
+  V z = *x;
+  a = z <= z;
+}
+
+/* { dg-final { scan-tree-dump "a\[^\n\r]*= . -1, -1," "optimized" } } */
+
+__attribute__((noinline, noclone, optimize ("no-finite-math-only"))) void
+bar (V *x)
+{
+  V z = *x;
+  b = z <= z;
+}
+
+/* { dg-final { scan-tree-dump-not "b\[^\n\r]*= . -1, -1," "optimized" } } */