On 10/26/25 5:20 PM, Andrew Pinski wrote:
In r14-6418-gacbfb8b9495b, the detection of boolean range was moved
over to use gimple_zero_one_valued_p but now that we can use the full ranger
during expand, let's use that instead. Adds a new helper function called
expr_has_boolean_range.  This calls ssa_name_has_boolean_range when there
is an ssa name; otherwise checks the constant value for boolean[0,1].

An example is:
```
unsigned f(unsigned b, unsigned c, unsigned d)
{
   if (b <= 1)
     return b * c;
   return d;
}
```
Where before this would not try to expand as `c & -b` but we know that b has 
[0,1] range,
this will expand as `c & -b` for many targets.

Bootstrapped and tested on x86_64-linux-gnu.

gcc/ChangeLog:

        * expr.cc (expr_has_boolean_range): New function.
        (expand_expr_real_2): Use expr_has_boolean_range instead of
        gimple_zero_one_valued_p.
        * tree-ssanames.cc (ssa_name_has_boolean_range): Update to take
        a gimple STMT.
        * tree-ssanames.h (ssa_name_has_boolean_range): Update for the new
        argument and default to nullptr.
OK with a comment nit fixed:

+/* Return TRUE is OP, an EXP has a range of values [0..1], false
+   otherwise. This works for constants and ssa names, calling back into the 
ranger.  */
I think this is "Return true if EXP has ...."

Jeff

Reply via email to