[PATCH] tree-optimization: Query ranger on edge for niter bound expressions

determine_value_range only queried ranger when VAR was an SSA_NAME.
However, number_of_iterations_exit_assumptions calls
expand_simple_operations on the IV bases before asking for the range.
This can expose simple GENERIC expressions, including conversions, even
when the original value had an SSA_NAME with useful range information.

Ranger can analyze such expressions at a program point or edge, so query
it for integral bound expressions on the loop preheader edge rather than
restricting the query to SSA_NAMEs.  This lets niter analysis recover the
narrower range for value-preserving conversions such as uint8_t to int,
while still handling non-value-preserving conversions and wrapping
expressions conservatively.

The new test covers a direct converted uint8_t bound, a masked uint16_t
bound whose useful range comes from ranger, a guarded uint16_t bound
whose range is context-sensitive, a non-value-preserving uint8_t to
int8_t conversion, and a wrapping unsigned expression.

Bootstrapped and regression tested on aarch64-unknown-linux-gnu.

gcc/ChangeLog:

	* tree-ssa-loop-niter.cc (determine_value_range): Query ranger
	for integral expressions, not only SSA_NAMEs.  Query ranges on the
	loop preheader edge.

gcc/testsuite/ChangeLog:

	* gcc.target/aarch64/sve2/niter-convert-range.c: New test.
2 files changed