From 01d5fb4588a29d89411fcc53dd10416bf55859c0 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Tue, 30 Jul 2019 11:27:37 -0400
Subject: [PATCH 42/96] FIXME: simplify
 region_model::add_any_constraints_from_ssa_def_stmt

---
 gcc/analyzer/region-model.cc | 122 ++++++++++++++++++++-----------------------
 1 file changed, 57 insertions(+), 65 deletions(-)

diff --git a/gcc/analyzer/region-model.cc b/gcc/analyzer/region-model.cc
index 9681660..791165f 100644
--- a/gcc/analyzer/region-model.cc
+++ b/gcc/analyzer/region-model.cc
@@ -3711,75 +3711,67 @@ region_model::add_any_constraints_from_ssa_def_stmt (tree lhs,
   if (rhs != boolean_false_node)
     return;
 
+  if (op != NE_EXPR && op != EQ_EXPR)
+    return;
+
+  /* We have either
+     - "LHS != false" (i.e. LHS is true), or
+     - "LHS == false" (i.e. LHS is false).  */
+  bool is_true = op == NE_EXPR;
+
   gimple *def_stmt = SSA_NAME_DEF_STMT (lhs);
-  if (gassign *assign = dyn_cast<gassign *> (def_stmt))
+  gassign *assign = dyn_cast<gassign *> (def_stmt);
+  if (!assign)
+    return;
+
+  enum tree_code rhs_code = gimple_assign_rhs_code (assign);
+
+  switch (rhs_code)
     {
-      enum tree_code rhs_code = gimple_assign_rhs_code (assign);
-      /* If we have "LHS != false", i.e. LHS is true... */
-      if (op == NE_EXPR)
-	{
-	  switch (rhs_code)
-	    {
-	    default:
-	      break;
-	    case BIT_AND_EXPR:
-	      {
-		/* ...and "LHS == (rhs1 & rhs2) i.e. "(rhs1 & rhs2)" is true
-		   then both rhs1 and rhs2 must be true.  */
-		tree rhs1 = gimple_assign_rhs1 (assign);
-		tree rhs2 = gimple_assign_rhs2 (assign);
-		add_constraint (rhs1, NE_EXPR, boolean_false_node, ctxt);
-		add_constraint (rhs2, NE_EXPR, boolean_false_node, ctxt);
-	      }
-	      break;
+    default:
+      break;
+    case BIT_AND_EXPR:
+      {
+	if (is_true)
+	  {
+	    /* ...and "LHS == (rhs1 & rhs2) i.e. "(rhs1 & rhs2)" is true
+	       then both rhs1 and rhs2 must be true.  */
+	    tree rhs1 = gimple_assign_rhs1 (assign);
+	    tree rhs2 = gimple_assign_rhs2 (assign);
+	    add_constraint (rhs1, NE_EXPR, boolean_false_node, ctxt);
+	    add_constraint (rhs2, NE_EXPR, boolean_false_node, ctxt);
+	  }
+      }
+      break;
 
-	    case EQ_EXPR:
-	    case NE_EXPR:
-	      {
-		/* ...and "LHS == (rhs1 OP rhs2)"
-		   then rhs1 OP rhs2 must be true.  */
-		tree rhs1 = gimple_assign_rhs1 (assign);
-		tree rhs2 = gimple_assign_rhs2 (assign);
-		add_constraint (rhs1, rhs_code, rhs2, ctxt);
-	      }
-	      break;
-	    }
-	}
+    case BIT_IOR_EXPR:
+      {
+	if (!is_true)
+	  {
+	    /* ...and "LHS == (rhs1 | rhs2)
+	       i.e. "(rhs1 | rhs2)" is false
+	       then both rhs1 and rhs2 must be false.  */
+	    tree rhs1 = gimple_assign_rhs1 (assign);
+	    tree rhs2 = gimple_assign_rhs2 (assign);
+	    add_constraint (rhs1, EQ_EXPR, boolean_false_node, ctxt);
+	    add_constraint (rhs2, EQ_EXPR, boolean_false_node, ctxt);
+	  }
+      }
+      break;
 
-      /* If we have "LHS == false", i.e. LHS is false... */
-      if (op == EQ_EXPR)
-	{
-	  switch (rhs_code)
-	    {
-	    default:
-	      break;
-	    case BIT_IOR_EXPR:
-	      {
-		/* ...and "LHS == (rhs1 | rhs2)
-		   i.e. "(rhs1 | rhs2)" is false
-		   then both rhs1 and rhs2 must be false.  */
-		tree rhs1 = gimple_assign_rhs1 (assign);
-		tree rhs2 = gimple_assign_rhs2 (assign);
-		add_constraint (rhs1, EQ_EXPR, boolean_false_node, ctxt);
-		add_constraint (rhs2, EQ_EXPR, boolean_false_node, ctxt);
-		//gcc_unreachable ();
-	      }
-	      break;
-	    case EQ_EXPR:
-	    case NE_EXPR:
-	      {
-		/* ...and hence "false == (rhs1 OP rhs2)"
-		   then rhs1 OP rhs2 must be false.  */
-		tree rhs1 = gimple_assign_rhs1 (assign);
-		tree rhs2 = gimple_assign_rhs2 (assign);
-		add_constraint (rhs1,
-				invert_tree_comparison (rhs_code,
-							false /* honor_nans */),
-				rhs2, ctxt);
-	      }
-	      break;
-	    }
-	}
+    case EQ_EXPR:
+    case NE_EXPR:
+      {
+	/* ...and "LHS == (rhs1 OP rhs2)"
+	   then rhs1 OP rhs2 must have the same logical value as LHS.  */
+	tree rhs1 = gimple_assign_rhs1 (assign);
+	tree rhs2 = gimple_assign_rhs2 (assign);
+	if (!is_true)
+	  rhs_code
+	    = invert_tree_comparison (rhs_code, false /* honor_nans */);
+	add_constraint (rhs1, rhs_code, rhs2, ctxt);
+      }
+      break;
     }
 }
 
-- 
1.8.5.3

