return expand_divmod (mod_p, code, mode, op0, op1, target, unsignedp);
}
+/* Return true if EXP has a range of values [0..1], false
+ otherwise. This works for constants and ssa names, calling back into the ranger. */
+static bool
+expr_has_boolean_range (tree exp, gimple *stmt)
+{
+ /* An integral type with a single bit of precision. */
+ if (INTEGRAL_TYPE_P (TREE_TYPE (exp))
+ && TYPE_UNSIGNED (TREE_TYPE (exp))
+ && TYPE_PRECISION (TREE_TYPE (exp)) == 1)
+ return true;
+
+ /* Signed 1 bit integers are not boolean ranges. */
+ if (!INTEGRAL_TYPE_P (TREE_TYPE (exp))
+ || TYPE_PRECISION (TREE_TYPE (exp)) <= 1)
+ return false;
+
+ if (TREE_CODE (exp) == SSA_NAME)
+ return ssa_name_has_boolean_range (exp, stmt);
+ if (TREE_CODE (exp) == INTEGER_CST)
+ return wi::leu_p (wi::to_wide (exp), 1);
+ return false;
+}
+
rtx
expand_expr_real_2 (const_sepops ops, rtx target, machine_mode tmode,
enum expand_modifier modifier)
/* Expand X*Y as X&-Y when Y must be zero or one. */
if (SCALAR_INT_MODE_P (mode))
{
- bool gimple_zero_one_valued_p (tree, tree (*)(tree));
- bool bit0_p = gimple_zero_one_valued_p (treeop0, nullptr);
- bool bit1_p = gimple_zero_one_valued_p (treeop1, nullptr);
+ bool bit0_p = expr_has_boolean_range (treeop0, currently_expanding_gimple_stmt);
+ bool bit1_p = expr_has_boolean_range (treeop1, currently_expanding_gimple_stmt);
/* Expand X*Y as X&Y when both X and Y must be zero or one. */
if (bit0_p && bit1_p)
return get_known_nonzero_bits_1 (name);
}
-/* Return TRUE is OP, an SSA_NAME has a range of values [0..1], false
- otherwise.
+/* Return TRUE is OP, an SSA_NAME has a range of values [0..1] at the
+ STMT, false otherwise.
This can be because it is a boolean type, any unsigned integral
type with a single bit of precision, or has known range of [0..1]
via range analysis. */
bool
-ssa_name_has_boolean_range (tree op)
+ssa_name_has_boolean_range (tree op, gimple *stmt)
{
gcc_assert (TREE_CODE (op) == SSA_NAME);
&& (TYPE_PRECISION (TREE_TYPE (op)) > 1))
{
int_range<2> r;
- if (get_range_query (cfun)->range_of_expr (r, op)
+ if (get_range_query (cfun)->range_of_expr (r, op, stmt)
&& r == range_true_and_false (TREE_TYPE (op)))
return true;
extern void set_bitmask (tree, const wide_int &value, const wide_int &mask);
extern wide_int get_nonzero_bits (const_tree);
extern wide_int get_known_nonzero_bits (const_tree);
-extern bool ssa_name_has_boolean_range (tree);
+extern bool ssa_name_has_boolean_range (tree, gimple * = nullptr);
extern void init_ssanames (struct function *, int);
extern void fini_ssanames (struct function *);
extern void ssanames_print_statistics (void);