&& TREE_CODE (op1) == INTEGER_CST)
code = maybe_optimize_mod_cmp (code, &op0, &op1);
+ /* Optimize (x - y) < 0 into x < y if x - y has undefined overflow. */
+ if (!TYPE_UNSIGNED (TREE_TYPE (op0))
+ && (code == LT_EXPR || code == LE_EXPR
+ || code == GT_EXPR || code == GE_EXPR)
+ && integer_zerop (op1)
+ && TREE_CODE (op0) == SSA_NAME)
+ maybe_optimize_sub_cmp_0 (code, &op0, &op1);
+
last2 = last = get_last_insn ();
extract_true_false_edges_from_block (bb, &true_edge, &false_edge);
#include "ccmp.h"
#include "gimple-fold.h"
#include "rtx-vector-builder.h"
+#include "tree-pretty-print.h"
+#include "flags.h"
/* If this is nonzero, we do not bother generating VOLATILE
*arg1 = c4;
return code == EQ_EXPR ? LE_EXPR : GT_EXPR;
}
+
+/* Optimize x - y < 0 into x < 0 if x - y has undefined overflow. */
+
+void
+maybe_optimize_sub_cmp_0 (enum tree_code code, tree *arg0, tree *arg1)
+{
+ gcc_checking_assert (code == GT_EXPR || code == GE_EXPR
+ || code == LT_EXPR || code == LE_EXPR);
+ gcc_checking_assert (integer_zerop (*arg1));
+
+ if (!optimize)
+ return;
+
+ gimple *stmt = get_def_for_expr (*arg0, MINUS_EXPR);
+ if (stmt == NULL)
+ return;
+
+ tree treeop0 = gimple_assign_rhs1 (stmt);
+ tree treeop1 = gimple_assign_rhs2 (stmt);
+ if (!TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (treeop0)))
+ return;
+
+ if (issue_strict_overflow_warning (WARN_STRICT_OVERFLOW_COMPARISON))
+ warning_at (gimple_location (stmt), OPT_Wstrict_overflow,
+ "assuming signed overflow does not occur when "
+ "simplifying %<X - Y %s 0%> to %<X %s Y%>",
+ op_symbol_code (code), op_symbol_code (code));
+
+ *arg0 = treeop0;
+ *arg1 = treeop1;
+}
\f
/* Generate code to calculate OPS, and exploded expression
using a store-flag instruction and return an rtx for the result.
}
}
+ /* Optimize (x - y) < 0 into x < y if x - y has undefined overflow. */
+ if (!unsignedp
+ && (ops->code == LT_EXPR || ops->code == LE_EXPR
+ || ops->code == GT_EXPR || ops->code == GE_EXPR)
+ && integer_zerop (arg1)
+ && TREE_CODE (arg0) == SSA_NAME)
+ maybe_optimize_sub_cmp_0 (ops->code, &arg0, &arg1);
+
/* Get the rtx comparison code to use. We know that EXP is a comparison
operation of some type. Some comparisons against 1 and -1 can be
converted to comparisons with zero. Do so here so that the tests
extern tree byte_representation (tree, tree *, tree *, tree *);
extern enum tree_code maybe_optimize_mod_cmp (enum tree_code, tree *, tree *);
+extern void maybe_optimize_sub_cmp_0 (enum tree_code, tree *, tree *);
/* Two different ways of generating switch statements. */
extern int try_casesi (tree, tree, tree, tree, rtx, rtx, rtx, profile_probability);