+2008-01-23 Paolo Bonzini <bonzini@gnu.org>
+
+ PR tree-optimization/38932
+ * fold-const.c (fold_unary_ignore_overflow): New.
+ * tree.h (fold_unary_ignore_overflow): Declare.
+ * tree-ssa-ccp.c (ccp_fold): Use fold_unary_ignore_overflow.
+ * tree-ssa-sccvn.c (visit_reference_op_load,
+ simplify_unary_expression): Likewise.
+
2009-01-22 Adam Nemet <anemet@caviumnetworks.com>
* c-decl.c (finish_struct): Move code to set DECL_PACKED after
} /* switch (code) */
}
+
+/* If the operation was a conversion do _not_ mark a resulting constant
+ with TREE_OVERFLOW if the original constant was not. These conversions
+ have implementation defined behavior and retaining the TREE_OVERFLOW
+ flag here would confuse later passes such as VRP. */
+tree
+fold_unary_ignore_overflow (enum tree_code code, tree type, tree op0)
+{
+ tree res = fold_unary (code, type, op0);
+ if (res
+ && TREE_CODE (res) == INTEGER_CST
+ && TREE_CODE (op0) == INTEGER_CST
+ && CONVERT_EXPR_CODE_P (code))
+ TREE_OVERFLOW (res) = TREE_OVERFLOW (op0);
+
+ return res;
+}
+
/* Fold a binary expression of code CODE and type TYPE with operands
OP0 and OP1, containing either a MIN-MAX or a MAX-MIN combination.
Return the folded expression if folding is successful. Otherwise,
+2008-01-23 Paolo Bonzini <bonzini@gnu.org>
+
+ PR tree-optimization/38932
+ * gcc.dg/pr38932.c: New.
+
2009-01-23 Revital Eres <eres@il.ibm.com>
* gcc.dg/sms-7.c: Fix test.
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+/* This variable needed only to exercise FRE instead of CCP. */
+unsigned char g;
+
+extern void abort();
+
+void f (long long int p)
+{
+ g = 255;
+ if (p >= (-9223372036854775807LL - 1) - (signed char) g)
+ p = 1;
+
+ if (p)
+ abort ();
+}
+
+
so this should almost always return a simplified RHS. */
tree lhs = gimple_assign_lhs (stmt);
tree op0 = gimple_assign_rhs1 (stmt);
- tree res;
/* Simplify the operand down to a constant. */
if (TREE_CODE (op0) == SSA_NAME)
return op0;
}
- res = fold_unary (subcode, gimple_expr_type (stmt), op0);
-
- /* If the operation was a conversion do _not_ mark a
- resulting constant with TREE_OVERFLOW if the original
- constant was not. These conversions have implementation
- defined behavior and retaining the TREE_OVERFLOW flag
- here would confuse later passes such as VRP. */
- if (res
- && TREE_CODE (res) == INTEGER_CST
- && TREE_CODE (op0) == INTEGER_CST
- && CONVERT_EXPR_CODE_P (subcode))
- TREE_OVERFLOW (res) = TREE_OVERFLOW (op0);
-
- return res;
+ return fold_unary_ignore_overflow (subcode,
+ gimple_expr_type (stmt), op0);
}
case GIMPLE_BINARY_RHS:
tree tem = valueize_expr (vn_get_expr_for (TREE_OPERAND (val, 0)));
if ((CONVERT_EXPR_P (tem)
|| TREE_CODE (tem) == VIEW_CONVERT_EXPR)
- && (tem = fold_unary (TREE_CODE (val), TREE_TYPE (val), tem)))
+ && (tem = fold_unary_ignore_overflow (TREE_CODE (val),
+ TREE_TYPE (val), tem)))
val = tem;
}
result = val;
fold_defer_overflow_warnings ();
result = fold_binary (gimple_assign_rhs_code (stmt),
- TREE_TYPE (gimple_get_lhs (stmt)), op0, op1);
+ TREE_TYPE (gimple_get_lhs (stmt)), op0, op1);
if (result)
STRIP_USELESS_TYPE_CONVERSION (result);
if (op0 == orig_op0)
return NULL_TREE;
- result = fold_unary (gimple_assign_rhs_code (stmt),
- gimple_expr_type (stmt), op0);
+ result = fold_unary_ignore_overflow (gimple_assign_rhs_code (stmt),
+ gimple_expr_type (stmt), op0);
if (result)
{
STRIP_USELESS_TYPE_CONVERSION (result);
extern tree fold (tree);
extern tree fold_unary (enum tree_code, tree, tree);
+extern tree fold_unary_ignore_overflow (enum tree_code, tree, tree);
extern tree fold_binary (enum tree_code, tree, tree, tree);
extern tree fold_ternary (enum tree_code, tree, tree, tree, tree);
extern tree fold_build1_stat (enum tree_code, tree, tree MEM_STAT_DECL);