On Thu, Jan 19, 2023 at 10:19 AM Jan-Benedict Glaw <jbg...@lug-owl.de> wrote: > > On Thu, 2022-12-22 17:42:16 +0000, Andrew Carlotti via Gcc-patches > <gcc-patches@gcc.gnu.org> wrote: > > New patch below, bootstrapped and regression tested on > > aarch64-unknown-linux-gnu and x86_64-pc-linux-gnu - ok to merge? > > > diff --git a/gcc/tree-ssa-loop-niter.cc b/gcc/tree-ssa-loop-niter.cc > > index > > fece876099c1687569d6351e7d2416ea6acae5b5..ce2441f2a6dbdf2d8fe42755d5d1abd8a631bb5c > > 100644 > > --- a/gcc/tree-ssa-loop-niter.cc > > +++ b/gcc/tree-ssa-loop-niter.cc > > @@ -42,6 +42,7 @@ along with GCC; see the file COPYING3. If not see > > #include "tree-chrec.h" > > #include "tree-scalar-evolution.h" > > #include "tree-dfa.h" > > +#include "internal-fn.h" > > #include "gimple-range.h" > > > > > > @@ -2198,6 +2199,224 @@ number_of_iterations_popcount (loop_p loop, edge > > exit, > > return true; > > } > > > > +/* Return an expression that counts the leading/trailing zeroes of src. > > + > > + If define_at_zero is true, then the built expression will be defined to > > + return the precision of src when src == 0 (using either a conditional > > + expression or a suitable internal function). > > + Otherwise, we can elide the conditional expression and let src = 0 > > invoke > > + undefined behaviour. */ > > + > > +static tree > > +build_cltz_expr (tree src, bool leading, bool define_at_zero) > > +{ > [...] > > + > > + tree call; > > + if (use_ifn) > > + { > > + call = build_call_expr_internal_loc (UNKNOWN_LOCATION, ifn, > > + integer_type_node, 1, src); > > + int val; > > + scalar_int_mode mode = SCALAR_INT_TYPE_MODE (utype); > ^^^^^^^^^^^^^^^^^^^^ > > This will give us a new unused variable warning.
I wonder if hardening the defaults.h macros like #define CLZ_DEFINED_VALUE_AT_ZERO(MODE, VALUE) (((MODE), (VALUE)), 0) fixes that and makes sense (also to avoid losing side-effects for the arguments) Richard. > > + int optab_defined_at_zero > > + = leading ? CLZ_DEFINED_VALUE_AT_ZERO (mode, val) > > + : CTZ_DEFINED_VALUE_AT_ZERO (mode, val); > > + if (define_at_zero && !(optab_defined_at_zero == 2 && val == prec)) > > + { > > + tree is_zero = fold_build2 (NE_EXPR, boolean_type_node, src, > > + build_zero_cst (TREE_TYPE (src))); > > + call = fold_build3(COND_EXPR, integer_type_node, is_zero, call, > > + build_int_cst (integer_type_node, prec)); > > + } > > + } > > MfG, JBG > > --