On Mon, 15 Sep 2025, Jakub Jelinek wrote:

> Hi!
> 
> The gcc.c-torture/compile/20111209-1.c testcase which uses
> typedef char* char_ptr32 __attribute__ ((mode(SI)));
> ICEs on s390x since my change to optimize extensions by cheaper of
> signed or unsigned extension if sign bit is known from VRP not to be set.
> 
> The problem is that get_range_pos_neg uses ranger into int_range_max
> and so ICEs on pointers.  All the other current callers call it from places
> where only scalar integral types can appear (scalar division/modulo,
> overflow ifns, etc.) I think, this spot was just testing SCALAR_INT_MODE_P.
> 
> The following patch adds check for INTEGRAL_TYPE_P, I think ranger will not
> do anything useful for pointers here anyway and what is a negative pointer
> is also fuzzy.  I've changed both get_range_pos_neg to punt on that and
> the caller, either of those changes are sufficient to fix the ICE, but I
> think it doesn't hurt to do it in both places.
> 
> Tested using cross to s390x and bootstrapped/regtested on x86_64-linux
> and i686-linux, ok for trunk?  Or if you want just one change, which one?
> My preference in that case would be to keep the tree.cc hunk.

OK (keeping both hunks)

Richard.

> 2025-09-15  Jakub Jelinek  <[email protected]>
> 
>       PR middle-end/121904
>       * tree.cc (get_range_pos_neg): Return 3 if arg doesn't have
>       scalar integral type.
>       * expr.cc (expand_expr_real_2) <CASE_CONVERT>: Only choose between
>       sign and zero extension based on costs for scalar integral inner
>       types.
> 
> --- gcc/tree.cc.jj    2025-09-09 16:44:40.141142156 +0200
> +++ gcc/tree.cc       2025-09-13 12:04:13.663756030 +0200
> @@ -14708,7 +14708,7 @@ verify_type (const_tree t)
>  int
>  get_range_pos_neg (tree arg, gimple *stmt)
>  {
> -  if (arg == error_mark_node)
> +  if (arg == error_mark_node || !INTEGRAL_TYPE_P (TREE_TYPE (arg)))
>      return 3;
>  
>    int prec = TYPE_PRECISION (TREE_TYPE (arg));
> --- gcc/expr.cc.jj    2025-09-10 12:33:06.962559553 +0200
> +++ gcc/expr.cc       2025-09-13 12:07:04.032445939 +0200
> @@ -9960,6 +9960,7 @@ expand_expr_real_2 (const_sepops ops, rt
>        else if (SCALAR_INT_MODE_P (GET_MODE (op0))
>              && optimize >= 2
>              && SCALAR_INT_MODE_P (mode)
> +            && INTEGRAL_TYPE_P (TREE_TYPE (treeop0))
>              && (GET_MODE_SIZE (as_a <scalar_int_mode> (mode))
>                  > GET_MODE_SIZE (as_a <scalar_int_mode> (GET_MODE (op0))))
>              && get_range_pos_neg (treeop0,
> 
>       Jakub
> 
> 

-- 
Richard Biener <[email protected]>
SUSE Software Solutions Germany GmbH,
Frankenstrasse 146, 90461 Nuernberg, Germany;
GF: Ivo Totev, Andrew McDonald, Werner Knoblich; (HRB 36809, AG Nuernberg)

Reply via email to