From 0d97e6d1fd7ca63c5b9aba845c4bb2bb7e508b93 Mon Sep 17 00:00:00 2001 From: rsandifo Date: Wed, 1 Nov 2017 13:30:34 +0000 Subject: [PATCH] Add an is_narrower_int_mode helper function This patch adds a function for testing whether an arbitrary mode X is an integer mode that is narrower than integer mode Y. This is useful for code like expand_float and expand_fix that could in principle handle vectors as well as scalars. 2017-11-01 Richard Sandiford Alan Hayward David Sherwood gcc/ * machmode.h (is_narrower_int_mode): New function * optabs.c (expand_float, expand_fix): Use it. * dwarf2out.c (rotate_loc_descriptor): Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@254305 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 8 ++++++++ gcc/dwarf2out.c | 3 +-- gcc/machmode.h | 11 +++++++++++ gcc/optabs.c | 4 ++-- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index bdd6b73ae4f..b9b5ddd75b3 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -2,6 +2,14 @@ Alan Hayward David Sherwood + * machmode.h (is_narrower_int_mode): New function + * optabs.c (expand_float, expand_fix): Use it. + * dwarf2out.c (rotate_loc_descriptor): Likewise. + +2017-11-01 Richard Sandiford + Alan Hayward + David Sherwood + * rtl.h (narrower_subreg_mode): New function. * ira-color.c (update_costs_from_allocno): Use it. diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c index 1a15c96f3c5..734476750e8 100644 --- a/gcc/dwarf2out.c +++ b/gcc/dwarf2out.c @@ -14547,8 +14547,7 @@ rotate_loc_descriptor (rtx rtl, scalar_int_mode mode, dw_loc_descr_ref op0, op1, ret, mask[2] = { NULL, NULL }; int i; - if (GET_MODE (rtlop1) != VOIDmode - && GET_MODE_BITSIZE (GET_MODE (rtlop1)) < GET_MODE_BITSIZE (mode)) + if (is_narrower_int_mode (GET_MODE (rtlop1), mode)) rtlop1 = gen_rtx_ZERO_EXTEND (mode, rtlop1); op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode, VAR_INIT_STATUS_INITIALIZED); diff --git a/gcc/machmode.h b/gcc/machmode.h index f5e5baaec80..f53e7b359f7 100644 --- a/gcc/machmode.h +++ b/gcc/machmode.h @@ -893,6 +893,17 @@ is_complex_float_mode (machine_mode mode, T *cmode) return false; } +/* Return true if MODE is a scalar integer mode with a precision + smaller than LIMIT's precision. */ + +inline bool +is_narrower_int_mode (machine_mode mode, scalar_int_mode limit) +{ + scalar_int_mode int_mode; + return (is_a (mode, &int_mode) + && GET_MODE_PRECISION (int_mode) < GET_MODE_PRECISION (limit)); +} + namespace mode_iterator { /* Start mode iterator *ITER at the first mode in class MCLASS, if any. */ diff --git a/gcc/optabs.c b/gcc/optabs.c index 7cf4d8e4280..8f7089ef0f1 100644 --- a/gcc/optabs.c +++ b/gcc/optabs.c @@ -4811,7 +4811,7 @@ expand_float (rtx to, rtx from, int unsignedp) rtx value; convert_optab tab = unsignedp ? ufloat_optab : sfloat_optab; - if (GET_MODE_PRECISION (GET_MODE (from)) < GET_MODE_PRECISION (SImode)) + if (is_narrower_int_mode (GET_MODE (from), SImode)) from = convert_to_mode (SImode, from, unsignedp); libfunc = convert_optab_libfunc (tab, GET_MODE (to), GET_MODE (from)); @@ -4993,7 +4993,7 @@ expand_fix (rtx to, rtx from, int unsignedp) that the mode of TO is at least as wide as SImode, since those are the only library calls we know about. */ - if (GET_MODE_PRECISION (GET_MODE (to)) < GET_MODE_PRECISION (SImode)) + if (is_narrower_int_mode (GET_MODE (to), SImode)) { target = gen_reg_rtx (SImode); -- 2.11.4.GIT