From db61b7f923b769142156eab047c94b04bb7adaae Mon Sep 17 00:00:00 2001 From: Richard Sandiford Date: Wed, 30 Aug 2017 11:19:39 +0000 Subject: [66/77] Use scalar_mode for constant integers This patch treats the mode associated with an integer constant as a scalar_mode. We can't use the more natural-sounding scalar_int_mode because we also use (const_int 0) for bounds-checking modes. (It might be worth adding a bounds-specific code instead, but that's for another day.) This exposes a latent bug in simplify_immed_subreg, which for vectors of CONST_WIDE_INTs would pass the vector mode rather than the element mode to rtx_mode_t. I think the: /* We can get a 0 for an error mark. */ || GET_MODE_CLASS (mode) == MODE_VECTOR_INT || GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT in immed_double_const is dead. trunc_int_mode (via gen_int_mode) would go on to ICE if the mode fitted in a HWI, and surely plenty of other code would be confused to see a const_int be interpreted as a vector. We should instead be using CONST0_RTX (mode) if we need a safe constant for a particular mode. We didn't try to make these functions take scalar_mode arguments because in many cases that would be too invasive at this stage. Maybe it would become feasible in future. Also, the long-term direction should probably be to add modes to constant integers rather than have then as VOIDmode odd-ones-out. That would remove the need for rtx_mode_t and thus remove the question whether they should use scalar_int_mode, scalar_mode or machine_mode. The patch also uses scalar_mode for the CONST_DOUBLE handling in loc_descriptor. In that case the mode can legitimately be either floating-point or integral. 2017-08-30 Richard Sandiford Alan Hayward David Sherwood gcc/ * emit-rtl.c (immed_double_const): Use is_a instead of separate mode class checks. Do not allow vector modes here. (immed_wide_int_const): Use as_a . * explow.c (trunc_int_for_mode): Likewise. * rtl.h (wi::int_traits::get_precision): Likewise. (wi::shwi): Likewise. (wi::min_value): Likewise. (wi::max_value): Likewise. * dwarf2out.c (loc_descriptor): Likewise. * simplify-rtx.c (simplify_immed_subreg): Fix rtx_mode_t argument for CONST_WIDE_INT. Co-Authored-By: Alan Hayward Co-Authored-By: David Sherwood From-SVN: r251517 --- gcc/rtl.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'gcc/rtl.h') diff --git a/gcc/rtl.h b/gcc/rtl.h index 7363bd6..b8ba49f 100644 --- a/gcc/rtl.h +++ b/gcc/rtl.h @@ -2120,8 +2120,7 @@ namespace wi inline unsigned int wi::int_traits ::get_precision (const rtx_mode_t &x) { - gcc_checking_assert (x.second != BLKmode && x.second != VOIDmode); - return GET_MODE_PRECISION (x.second); + return GET_MODE_PRECISION (as_a (x.second)); } inline wi::storage_ref @@ -2166,7 +2165,7 @@ namespace wi inline wi::hwi_with_prec wi::shwi (HOST_WIDE_INT val, machine_mode mode) { - return shwi (val, GET_MODE_PRECISION (mode)); + return shwi (val, GET_MODE_PRECISION (as_a (mode))); } /* Produce the smallest number that is represented in MODE. The precision @@ -2174,7 +2173,7 @@ wi::shwi (HOST_WIDE_INT val, machine_mode mode) inline wide_int wi::min_value (machine_mode mode, signop sgn) { - return min_value (GET_MODE_PRECISION (mode), sgn); + return min_value (GET_MODE_PRECISION (as_a (mode)), sgn); } /* Produce the largest number that is represented in MODE. The precision @@ -2182,7 +2181,7 @@ wi::min_value (machine_mode mode, signop sgn) inline wide_int wi::max_value (machine_mode mode, signop sgn) { - return max_value (GET_MODE_PRECISION (mode), sgn); + return max_value (GET_MODE_PRECISION (as_a (mode)), sgn); } extern void init_rtlanal (void); -- cgit v1.1