https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111959
Bug ID: 111959
Summary: tree_single_nonnegative_warnv_p could use
tree_nonzero_bits for SSA_NAMES and int types
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Keywords: internal-improvement, missed-optimization
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Target Milestone: ---
I Noticed this while looking into PR 101590.
tree_single_nonnegative_warnv_p currently does:
case SSA_NAME:
/* Limit the depth of recursion to avoid quadratic behavior.
This is expected to catch almost all occurrences in practice.
If this code misses important cases that unbounded recursion
would not, passes that need this information could be revised
to provide it through dataflow propagation. */
return (!name_registered_for_update_p (t)
&& depth < param_max_ssa_name_query_depth
&& gimple_stmt_nonnegative_warnv_p (SSA_NAME_DEF_STMT (t),
strict_overflow_p, depth));
But we could/should use tree_nonzero_bits first to see if the info is already
cached somewhere. This might speed up things.
An example of where this would improve is:
```
int f(int a, int b)
{
if (a & ~0xff) __builtin_unreachable();
return a / (1<<b);
}
int f1(int a, int b)
{
if (a & ~0xff) __builtin_unreachable();
return a >>b;
}
```
There are other examples too.