re PR tree-optimization/53239 (VRP vs named value return opt)

PR tree-optimization/53239
	* tree-vrp.c (get_value_range): Set VR of
	SSA_NAME_IS_DEFAULT_DEF of DECL_BY_REFERENCE RESULT_DECL
	to nonnull.

	* g++.dg/opt/vrp3.C: New test.
	* g++.dg/opt/vrp3-aux.cc: New file.
	* g++.dg/opt/vrp3.h: New file.

From-SVN: r187241
This commit is contained in:
Jakub Jelinek 2012-05-07 15:33:27 +02:00 committed by Jakub Jelinek
parent bd93e76326
commit 2fb3f74005
6 changed files with 105 additions and 9 deletions

View File

@ -1,3 +1,10 @@
2012-05-07 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/53239
* tree-vrp.c (get_value_range): Set VR of
SSA_NAME_IS_DEFAULT_DEF of DECL_BY_REFERENCE RESULT_DECL
to nonnull.
2012-05-07 Richard Guenther <rguenther@suse.de>
PR tree-optimization/53195

View File

@ -1,3 +1,10 @@
2012-05-07 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/53239
* g++.dg/opt/vrp3.C: New test.
* g++.dg/opt/vrp3-aux.cc: New file.
* g++.dg/opt/vrp3.h: New file.
2012-05-07 Tobias Burnus <burnus@net-b.de>
Backport from mainline:

View File

@ -0,0 +1,21 @@
// { dg-do compile }
// { dg-options "" }
#include "vrp3.h"
R::R ()
{
r1 = r2 = 1;
}
R::R (int n, int d)
{
r1 = n;
r2 = d;
}
int
R::compare (R const &r, R const &s)
{
return (int) (r.r1 * s.r2 - s.r1 * r.r2);
}

View File

@ -0,0 +1,47 @@
// PR tree-optimization/53239
// { dg-do run }
// { dg-options "-O2" }
// { dg-additional-sources "vrp3-aux.cc" }
#include "vrp3.h"
struct M
{
M (R m);
R val;
static int compare (M const &, M const &);
};
inline M const &
min (M const & t1, M const & t2)
{
return R::compare (t1.val, t2.val) < 0 ? t1 : t2;
}
M::M (R m)
{
val = m;
}
M
test (M *x)
{
M n (R (0, 0));
for (int i = 0; i < 2; i++)
{
M p = x[i];
n = min (n, p);
}
if (n.val.r2 != 2 || n.val.r1 != 1)
__builtin_abort ();
return n;
}
int
main ()
{
M x[2] = { M (R (1, 2)), M (R (1, 1)) };
test (x);
}

View File

@ -0,0 +1,9 @@
struct R
{
long long r1, r2;
void copy (R const &r) { r1 = r.r1; r2 = r.r2; }
R ();
explicit R (int, int);
R (R const &r) { copy (r); }
static int compare (R const &, R const &);
};

View File

@ -695,17 +695,22 @@ get_value_range (const_tree var)
/* If VAR is a default definition of a parameter, the variable can
take any value in VAR's type. */
sym = SSA_NAME_VAR (var);
if (SSA_NAME_IS_DEFAULT_DEF (var)
&& TREE_CODE (sym) == PARM_DECL)
if (SSA_NAME_IS_DEFAULT_DEF (var))
{
/* Try to use the "nonnull" attribute to create ~[0, 0]
anti-ranges for pointers. Note that this is only valid with
default definitions of PARM_DECLs. */
if (POINTER_TYPE_P (TREE_TYPE (sym))
&& nonnull_arg_p (sym))
if (TREE_CODE (sym) == PARM_DECL)
{
/* Try to use the "nonnull" attribute to create ~[0, 0]
anti-ranges for pointers. Note that this is only valid with
default definitions of PARM_DECLs. */
if (POINTER_TYPE_P (TREE_TYPE (sym))
&& nonnull_arg_p (sym))
set_value_range_to_nonnull (vr, TREE_TYPE (sym));
else
set_value_range_to_varying (vr);
}
else if (TREE_CODE (sym) == RESULT_DECL
&& DECL_BY_REFERENCE (sym))
set_value_range_to_nonnull (vr, TREE_TYPE (sym));
else
set_value_range_to_varying (vr);
}
return vr;