optimize_stmt turns if (b == 5) into if (0 == 5) when b has a [0, 1]
range. We're already calling simplify_stmt which takes care of this.
Remove the code.
I've run this patch through my .ii harness and there's one file with
different assembly, and it's because we fold one more conditional :).
OK pending further tests?
gcc/ChangeLog:
* tree-ssa-dom.cc (dom_opt_dom_walker::optimize_stmt): Remove the
boolean range special case.
gcc/testsuite/ChangeLog:
* gcc.dg/tree-ssa/ssa-dom-simplify-4.c: New test.
---
.../gcc.dg/tree-ssa/ssa-dom-simplify-4.c | 30 +++++++++++++++++++
gcc/tree-ssa-dom.cc | 25 ----------------
2 files changed, 30 insertions(+), 25 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-simplify-4.c
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-simplify-4.c
b/gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-simplify-4.c
new file mode 100644
index 00000000000..67f548f2f08
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-simplify-4.c
@@ -0,0 +1,30 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fgimple -fno-tree-vrp -fdump-tree-dom2" } */
+
+/* b is 0 or 1, so the test against 5 is false. */
+
+void frob (void);
+
+void __GIMPLE (ssa,startwith("dom"))
+f (int x, int y)
+{
+ _Bool b;
+ int i;
+
+ __BB(2):
+ b_1 = x_2(D) < y_3(D);
+ i_4 = (int) b_1;
+ if (i_4 == 5)
+ goto __BB3;
+ else
+ goto __BB4;
+
+ __BB(3):
+ frob ();
+ goto __BB4;
+
+ __BB(4):
+ return;
+}
+
+/* { dg-final { scan-tree-dump "Folding predicate i_4 == 5 to 0" "dom2" } } */
diff --git a/gcc/tree-ssa-dom.cc b/gcc/tree-ssa-dom.cc
index 490eddc37c3..f48be8d68dd 100644
--- a/gcc/tree-ssa-dom.cc
+++ b/gcc/tree-ssa-dom.cc
@@ -2325,31 +2325,6 @@ dom_opt_dom_walker::optimize_stmt (basic_block bb,
gimple_stmt_iterator *si,
}
}
- if (gimple_code (stmt) == GIMPLE_COND)
- {
- tree lhs = gimple_cond_lhs (stmt);
- tree rhs = gimple_cond_rhs (stmt);
-
- /* If the LHS has a range [0..1] and the RHS has a range ~[0..1],
- then this conditional is computable at compile time. We can just
- shove either 0 or 1 into the LHS, mark the statement as modified
- and all the right things will just happen below.
-
- Note this would apply to any case where LHS has a range
- narrower than its type implies and RHS is outside that
- narrower range. Future work. */
- if (TREE_CODE (lhs) == SSA_NAME
- && ssa_name_has_boolean_range (lhs)
- && TREE_CODE (rhs) == INTEGER_CST
- && ! (integer_zerop (rhs) || integer_onep (rhs)))
- {
- gimple_cond_set_lhs (as_a <gcond *> (stmt),
- fold_convert (TREE_TYPE (lhs),
- integer_zero_node));
- gimple_set_modified (stmt, true);
- }
- }
-
update_stmt_if_modified (stmt);
eliminate_redundant_computations (si, m_const_and_copies,
m_avail_exprs_stack);
--
2.53.0