+/* If STMT is a call, check the callee against a list of forbidden
+ predicate functions. If a match is found, look for uses of the
+ call result in condition statements that compare against zero.
+ For each such use, find the block targeted by the condition
+ statement for the nonzero result, and set the bit for this block
+ in the forbidden dominators bitmap. The purpose of this is to avoid
+ selecting a split point where we are likely to lose the chance
+ to optimize away an unused function call. */
+
+static void
+check_forbidden_calls (gimple stmt)
+{
+ imm_use_iterator use_iter;
+ use_operand_p use_p;
+ tree lhs;
+
+ /* At the moment, __builtin_constant_p is the only forbidden
+ predicate function call (see PR49642). */
+ if (!gimple_call_builtin_p (stmt, BUILT_IN_CONSTANT_P))
+ return;
+
+ lhs = gimple_call_lhs (stmt);
+
+ if (!lhs || TREE_CODE (lhs) != SSA_NAME)
+ return;
+
+ FOR_EACH_IMM_USE_FAST (use_p, use_iter, lhs)
+ {
+ tree op1;
+ basic_block use_bb, forbidden_bb;
+ enum tree_code code;
+ edge true_edge, false_edge;
+ gimple use_stmt = USE_STMT (use_p);
+
+ if (gimple_code (use_stmt) != GIMPLE_COND)
+ continue;
+
+ /* Assuming canonical form for GIMPLE_COND here, with constant
+ in second position. */
+ op1 = gimple_cond_rhs (use_stmt);
+ code = gimple_cond_code (use_stmt);
+ use_bb = gimple_bb (use_stmt);
+
+ extract_true_false_edges_from_block (use_bb, &true_edge, &false_edge);
+
+ /* We're only interested in comparisons that distinguish
+ unambiguously from zero. */
+ if (!integer_zerop (op1) || code == LE_EXPR || code == GE_EXPR)
+ continue;
+
+ if (code == EQ_EXPR)
+ forbidden_bb = false_edge->dest;
+ else
+ forbidden_bb = true_edge->dest;
+
+ bitmap_set_bit (forbidden_dominators, forbidden_bb->index);
+ }
+}
+
+/* If BB is dominated by any block in the forbidden dominators set,
+ return TRUE; else FALSE. */
+
+static bool
+dominated_by_forbidden (basic_block bb)
+{
+ unsigned dom_bb;
+ bitmap_iterator bi;
+
+ EXECUTE_IF_SET_IN_BITMAP (forbidden_dominators, 1, dom_bb, bi)
+ {
+ if (dominated_by_p (CDI_DOMINATORS, bb, BASIC_BLOCK (dom_bb)))
+ return true;
+ }
+
+ return false;
+}
+