re PR middle-end/40747 (wrong code for int-is-in-range test at -O1 and above)

PR middle-end/40747
	* fold-const.c (fold_cond_expr_with_comparison): When folding
	< and <= to MIN, make sure the MIN uses the same type as the
	comparison's operands.

	* gcc.c-torture/execute/pr40747.c: New test.

From-SVN: r149681
This commit is contained in:
Jakub Jelinek 2009-07-15 13:23:22 +02:00 committed by Jakub Jelinek
parent bb116e722e
commit 4ff803147c
4 changed files with 58 additions and 20 deletions

View File

@ -1,3 +1,10 @@
2009-07-15 Jakub Jelinek <jakub@redhat.com>
PR middle-end/40747
* fold-const.c (fold_cond_expr_with_comparison): When folding
< and <= to MIN, make sure the MIN uses the same type as the
comparison's operands.
2009-07-12 Kai Tietz <kai.tietz@onevision.com>
* config/i386/cygming.h (TARGET_OS_CPP_BUILTINS): Define _X86_

View File

@ -5266,31 +5266,35 @@ fold_cond_expr_with_comparison (tree type, tree arg0, tree arg1, tree arg2)
return fold_build3 (COND_EXPR, type, arg0, arg1, arg2);
case LT_EXPR:
/* If C1 is C2 + 1, this is min(A, C2). */
/* If C1 is C2 + 1, this is min(A, C2), but use ARG00's type for
MIN_EXPR, to preserve the signedness of the comparison. */
if (! operand_equal_p (arg2, TYPE_MAX_VALUE (type),
OEP_ONLY_CONST)
&& operand_equal_p (arg01,
const_binop (PLUS_EXPR, arg2,
build_int_cst (type, 1), 0),
OEP_ONLY_CONST))
return pedantic_non_lvalue (fold_build2 (MIN_EXPR,
type,
fold_convert (type, arg1),
arg2));
{
tem = fold_build2 (MIN_EXPR, TREE_TYPE (arg00), arg00,
fold_convert (TREE_TYPE (arg00), arg2));
return pedantic_non_lvalue (fold_convert (type, tem));
}
break;
case LE_EXPR:
/* If C1 is C2 - 1, this is min(A, C2). */
/* If C1 is C2 - 1, this is min(A, C2), with the same care
as above. */
if (! operand_equal_p (arg2, TYPE_MIN_VALUE (type),
OEP_ONLY_CONST)
&& operand_equal_p (arg01,
const_binop (MINUS_EXPR, arg2,
build_int_cst (type, 1), 0),
OEP_ONLY_CONST))
return pedantic_non_lvalue (fold_build2 (MIN_EXPR,
type,
fold_convert (type, arg1),
arg2));
{
tem = fold_build2 (MIN_EXPR, TREE_TYPE (arg00), arg00,
fold_convert (TREE_TYPE (arg00), arg2));
return pedantic_non_lvalue (fold_convert (type, tem));
}
break;
case GT_EXPR:
@ -5302,11 +5306,11 @@ fold_cond_expr_with_comparison (tree type, tree arg0, tree arg1, tree arg2)
const_binop (MINUS_EXPR, arg2,
build_int_cst (type, 1), 0),
OEP_ONLY_CONST))
return pedantic_non_lvalue (fold_convert (type,
fold_build2 (MAX_EXPR, TREE_TYPE (arg00),
arg00,
fold_convert (TREE_TYPE (arg00),
arg2))));
{
tem = fold_build2 (MAX_EXPR, TREE_TYPE (arg00), arg00,
fold_convert (TREE_TYPE (arg00), arg2));
return pedantic_non_lvalue (fold_convert (type, tem));
}
break;
case GE_EXPR:
@ -5317,11 +5321,11 @@ fold_cond_expr_with_comparison (tree type, tree arg0, tree arg1, tree arg2)
const_binop (PLUS_EXPR, arg2,
build_int_cst (type, 1), 0),
OEP_ONLY_CONST))
return pedantic_non_lvalue (fold_convert (type,
fold_build2 (MAX_EXPR, TREE_TYPE (arg00),
arg00,
fold_convert (TREE_TYPE (arg00),
arg2))));
{
tem = fold_build2 (MAX_EXPR, TREE_TYPE (arg00), arg00,
fold_convert (TREE_TYPE (arg00), arg2));
return pedantic_non_lvalue (fold_convert (type, tem));
}
break;
case NE_EXPR:
break;

View File

@ -1,3 +1,8 @@
2009-07-15 Jakub Jelinek <jakub@redhat.com>
PR middle-end/40747
* gcc.c-torture/execute/pr40747.c: New test.
2009-07-14 Uros Bizjak <ubizjak@gmail.com>
* gcc.target/i386/sse-recip-vec.c: Move arrays out of test

View File

@ -0,0 +1,22 @@
/* PR middle-end/40747 */
extern void abort (void);
int
foo (int i)
{
return (i < 4 && i >= 0) ? i : 4;
}
int
main ()
{
if (foo (-1) != 4) abort ();
if (foo (0) != 0) abort ();
if (foo (1) != 1) abort ();
if (foo (2) != 2) abort ();
if (foo (3) != 3) abort ();
if (foo (4) != 4) abort ();
if (foo (5) != 4) abort ();
return 0;
}