From patchwork Thu Jul 13 08:45:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 107605 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp1929529qge; Thu, 13 Jul 2017 01:46:28 -0700 (PDT) X-Received: by 10.84.217.134 with SMTP id p6mr8942516pli.196.1499935588547; Thu, 13 Jul 2017 01:46:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499935588; cv=none; d=google.com; s=arc-20160816; b=bx78tOjY9Z3LEMyfln7morsS1Y3ZG1jnxFhIjoLojQI+i3WgKl9YkxDJuRkDHfvC0I HgqzZsgbtaC2a9oAoXb00HrxD80aQu8tLDbtg6GSiYoFaYn7pEwF8M1TbhIJUE7013RS BG4CZDHeAazoJiPrX8pVIMMWsLy1xrZhQ5Xl8j42R3oACQzQ9g1w9muIYNPy42uA5TlN jAefUnQtcUs51mKVzyS/DvUy2qC3EVwZnGE2xDENNJbAlqxApuj5Lf3UYng6KPK7tFbY FXLVUQxNwwvFURCTDe+6G3lVn6P0KPA9enw7Vjq5x5HyNZZvudzfB5Jd0TfyofevPthJ e3Vg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:message-id:in-reply-to:date:references :subject:mail-followup-to:to:from:delivered-to:sender:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :mailing-list:dkim-signature:domainkey-signature :arc-authentication-results; bh=hEaAYZDkfYmMz/HxxhL3ZaaHHQ5A2GC40J/DTO4EfFY=; b=j7JzKzD17mbOjU3z62slCZi1CjoHrhcl013OEKxTolJeax11cjs+uJ7WKQXU8qfx1z 5VrPC0kMLsOqbkOfBfgCHSEJMabLF8/ZEJphd//PuwlPwDiWsdocLoKWlzaa2e0yDT9a AZPoMXQM4q9sMg9TtN/lFieC/gxs6zTkTCtMWXpN7JKqT0gSeXvBNS7DPjG1FhwkoINd 0GOqDErsUCqepJKRlZb1HeRPsYw91CF5VZBSVgZWYavjavlzhqUTpcryzAsQVWEWaDRI 0i6IpmSXY/ZrTgXmaNBjSiEPFUpne6He6PW4Mw/2VK8fjLNbOWZWnc959MsWV4l3Jyl9 eOnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.b=tz2ng0nd; spf=pass (google.com: domain of gcc-patches-return-458009-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-458009-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id n6si3865654pgf.284.2017.07.13.01.46.28 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Jul 2017 01:46:28 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-458009-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.b=tz2ng0nd; spf=pass (google.com: domain of gcc-patches-return-458009-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-458009-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:references:date:in-reply-to:message-id:mime-version :content-type; q=dns; s=default; b=QMxM4D/pDk7OgDH7NEHj+RxdEbFP/ vsxouoSnc+i8fF7D62asXAeRd+XodZ0vttvFkXHPWvILRvaXNIumQnrIFosqrEDu GLHcO6IcxdDRSDmVsvQv3zWNUIvlqCszxK9VWsN80i/Cc690FkoDWJola0lYiSe6 UgH23wZx52uvEw= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:references:date:in-reply-to:message-id:mime-version :content-type; s=default; bh=ZIuykm5rvGnQK4P1baYYhMx/M+Y=; b=tz2 ng0ndJ8AWlFJF31I1Ow0uUjOUVjSxCBPezceec2r2WEHlAhYOEoYqMsUAl5nDZlG vU6V20heyyMiujkcK11tSCeNsldHZaCFvqbjotBcpfFgeBjXIMEZmB3aptO33pyK bpjcYCshlkPsNhf9UhM92anyETHA2xXwhOdFGxVY= Received: (qmail 24471 invoked by alias); 13 Jul 2017 08:45:51 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 10342 invoked by uid 89); 13 Jul 2017 08:45:43 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=nominal X-HELO: mail-wr0-f170.google.com Received: from mail-wr0-f170.google.com (HELO mail-wr0-f170.google.com) (209.85.128.170) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 13 Jul 2017 08:45:40 +0000 Received: by mail-wr0-f170.google.com with SMTP id 77so49586041wrb.1 for ; Thu, 13 Jul 2017 01:45:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:mail-followup-to:subject:references:date :in-reply-to:message-id:user-agent:mime-version; bh=hEaAYZDkfYmMz/HxxhL3ZaaHHQ5A2GC40J/DTO4EfFY=; b=YTkMi6e0f/9/OMWIfdPa9VIOTytU2yROeeIV6ptmTM6C+UmFj1l/IPbvMZj96bwBlO gR/36+5eUfZSwWhY2M5C+jzh1+7Z/9a8+Ja7n5IQe2i1Z/rFCwh9C35u8946Dd0iechk fSBnfvFHds1FXkDo/zwHfSII8nRPba+ms4WiZdX8Lda7wPSMK/S0YbjBAh63HMtkuDEh 9bodCuhiJ58OXR5Uycmn0EqkryyHMh7VWQ9b4qjgkYh/81De+wUYYEGNrjFCsX11VvS7 ewE90+60/3CHKjGkOERBzPhdW1eQPtk7t5s6xep4BOjfBaOUOv4Usk05Ibkio84J41U6 GS0g== X-Gm-Message-State: AIVw1114M4UpL+vthoy4FhzlKN8RsCAVHmRtYHiAS87xnQ18jI6DBdsO CtEbIc1+FZbsRCCdDETR6g== X-Received: by 10.223.173.140 with SMTP id w12mr943773wrc.4.1499935536908; Thu, 13 Jul 2017 01:45:36 -0700 (PDT) Received: from localhost (92.40.249.184.threembb.co.uk. [92.40.249.184]) by smtp.gmail.com with ESMTPSA id z195sm6035320wmz.28.2017.07.13.01.45.35 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 13 Jul 2017 01:45:35 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@linaro.org Subject: [19/77] Add a smallest_int_mode_for_size helper function References: <8760ewohsv.fsf@linaro.org> Date: Thu, 13 Jul 2017 09:45:34 +0100 In-Reply-To: <8760ewohsv.fsf@linaro.org> (Richard Sandiford's message of "Thu, 13 Jul 2017 09:35:44 +0100") Message-ID: <87vamwk9n5.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 This patch adds a wrapper around smallest_mode_for_size for cases in which the mode class is MODE_INT. Unlike (int_)mode_for_size, smallest_mode_for_size always returns a mode of the specified class, asserting if no such mode exists. smallest_int_mode_for_size therefore returns a scalar_int_mode rather than an opt_scalar_int_mode. 2017-07-13 Richard Sandiford Alan Hayward David Sherwood gcc/ * machmode.h (smallest_mode_for_size): Fix formatting. (smallest_int_mode_for_size): New function. * cfgexpand.c (expand_debug_expr): Use smallest_int_mode_for_size instead of smallest_mode_for_size. * combine.c (make_extraction): Likewise. * config/arc/arc.c (arc_expand_movmem): Likewise. * config/arm/arm.c (arm_expand_divmod_libfunc): Likewise. * config/i386/i386.c (ix86_get_mask_mode): Likewise. * config/s390/s390.c (s390_expand_insv): Likewise. * config/sparc/sparc.c (assign_int_registers): Likewise. * config/spu/spu.c (spu_function_value): Likewise. (spu_function_arg): Likewise. * coverage.c (get_gcov_type): Likewise. (get_gcov_unsigned_t): Likewise. * dse.c (find_shift_sequence): Likewise. * expmed.c (store_bit_field_1): Likewise. * expr.c (convert_move): Likewise. (store_field): Likewise. * internal-fn.c (expand_arith_overflow): Likewise. * optabs-query.c (get_best_extraction_insn): Likewise. * optabs.c (expand_twoval_binop_libfunc): Likewise. * stor-layout.c (layout_type): Likewise. (initialize_sizetypes): Likewise. * targhooks.c (default_get_mask_mode): Likewise. * tree-ssa-loop-manip.c (canonicalize_loop_ivs): Likewise. Index: gcc/machmode.h =================================================================== --- gcc/machmode.h 2017-07-13 09:18:30.083577588 +0100 +++ gcc/machmode.h 2017-07-13 09:18:30.902501597 +0100 @@ -589,9 +589,16 @@ float_mode_for_size (unsigned int size) /* Similar to mode_for_size, but find the smallest mode for a given width. */ -extern machine_mode smallest_mode_for_size (unsigned int, - enum mode_class); +extern machine_mode smallest_mode_for_size (unsigned int, enum mode_class); +/* Find the narrowest integer mode that contains at least SIZE bits. + Such a mode must exist. */ + +inline scalar_int_mode +smallest_int_mode_for_size (unsigned int size) +{ + return as_a (smallest_mode_for_size (size, MODE_INT)); +} /* Return an integer mode of exactly the same size as the input mode. */ Index: gcc/cfgexpand.c =================================================================== --- gcc/cfgexpand.c 2017-07-13 09:18:30.028582691 +0100 +++ gcc/cfgexpand.c 2017-07-13 09:18:30.888502896 +0100 @@ -4495,7 +4495,7 @@ expand_debug_expr (tree exp) { if (mode1 == VOIDmode) /* Bitfield. */ - mode1 = smallest_mode_for_size (bitsize, MODE_INT); + mode1 = smallest_int_mode_for_size (bitsize); if (bitpos >= BITS_PER_UNIT) { op0 = adjust_address_nv (op0, mode1, bitpos / BITS_PER_UNIT); Index: gcc/combine.c =================================================================== --- gcc/combine.c 2017-07-13 09:18:30.031582413 +0100 +++ gcc/combine.c 2017-07-13 09:18:30.889502803 +0100 @@ -7611,7 +7611,7 @@ make_extraction (machine_mode mode, rtx { /* Be careful not to go beyond the extracted object and maintain the natural alignment of the memory. */ - wanted_inner_mode = smallest_mode_for_size (len, MODE_INT); + wanted_inner_mode = smallest_int_mode_for_size (len); while (pos % GET_MODE_BITSIZE (wanted_inner_mode) + len > GET_MODE_BITSIZE (wanted_inner_mode)) wanted_inner_mode = *GET_MODE_WIDER_MODE (wanted_inner_mode); Index: gcc/config/arc/arc.c =================================================================== --- gcc/config/arc/arc.c 2017-07-13 09:18:19.018705510 +0100 +++ gcc/config/arc/arc.c 2017-07-13 09:18:30.890502711 +0100 @@ -7974,7 +7974,7 @@ arc_expand_movmem (rtx *operands) while (piece > size) piece >>= 1; - mode = smallest_mode_for_size (piece * BITS_PER_UNIT, MODE_INT); + mode = smallest_int_mode_for_size (piece * BITS_PER_UNIT); /* If we don't re-use temporaries, the scheduler gets carried away, and the register pressure gets unnecessarily high. */ if (0 && tmpx[i] && GET_MODE (tmpx[i]) == mode) Index: gcc/config/arm/arm.c =================================================================== --- gcc/config/arm/arm.c 2017-07-13 09:18:26.899879373 +0100 +++ gcc/config/arm/arm.c 2017-07-13 09:18:30.892502525 +0100 @@ -31096,8 +31096,8 @@ arm_expand_divmod_libfunc (rtx libfunc, if (mode == SImode) gcc_assert (!TARGET_IDIV); - machine_mode libval_mode = smallest_mode_for_size (2 * GET_MODE_BITSIZE (mode), - MODE_INT); + scalar_int_mode libval_mode + = smallest_int_mode_for_size (2 * GET_MODE_BITSIZE (mode)); rtx libval = emit_library_call_value (libfunc, NULL_RTX, LCT_CONST, libval_mode, 2, Index: gcc/config/i386/i386.c =================================================================== --- gcc/config/i386/i386.c 2017-07-13 09:18:30.054580279 +0100 +++ gcc/config/i386/i386.c 2017-07-13 09:18:30.896502154 +0100 @@ -51320,11 +51320,11 @@ ix86_get_mask_mode (unsigned nunits, uns || (TARGET_AVX512VL && (vector_size == 32 || vector_size == 16))) { if (elem_size == 4 || elem_size == 8 || TARGET_AVX512BW) - return smallest_mode_for_size (nunits, MODE_INT); + return smallest_int_mode_for_size (nunits); } - machine_mode elem_mode - = smallest_mode_for_size (elem_size * BITS_PER_UNIT, MODE_INT); + scalar_int_mode elem_mode + = smallest_int_mode_for_size (elem_size * BITS_PER_UNIT); gcc_assert (elem_size * nunits == vector_size); Index: gcc/config/s390/s390.c =================================================================== --- gcc/config/s390/s390.c 2017-07-13 09:18:30.075578330 +0100 +++ gcc/config/s390/s390.c 2017-07-13 09:18:30.898501968 +0100 @@ -6182,7 +6182,7 @@ s390_expand_insv (rtx dest, rtx op1, rtx return true; } - smode = smallest_mode_for_size (bitsize, MODE_INT); + smode = smallest_int_mode_for_size (bitsize); smode_bsize = GET_MODE_BITSIZE (smode); mode_bsize = GET_MODE_BITSIZE (mode); Index: gcc/config/sparc/sparc.c =================================================================== --- gcc/config/sparc/sparc.c 2017-07-13 09:18:19.134692649 +0100 +++ gcc/config/sparc/sparc.c 2017-07-13 09:18:30.899501876 +0100 @@ -6761,8 +6761,8 @@ assign_int_registers (HOST_WIDE_INT bitp the latter case we may pick up unwanted bits. It's not a problem at the moment but may wish to revisit. */ if (intoffset % BITS_PER_WORD != 0) - mode = smallest_mode_for_size (BITS_PER_WORD - intoffset % BITS_PER_WORD, - MODE_INT); + mode = smallest_int_mode_for_size (BITS_PER_WORD + - intoffset % BITS_PER_WORD); else mode = word_mode; Index: gcc/config/spu/spu.c =================================================================== --- gcc/config/spu/spu.c 2017-07-13 09:18:30.077578145 +0100 +++ gcc/config/spu/spu.c 2017-07-13 09:18:30.899501876 +0100 @@ -3808,8 +3808,7 @@ spu_function_value (const_tree type, con { if (byte_size < 4) byte_size = 4; - smode = - smallest_mode_for_size (byte_size * BITS_PER_UNIT, MODE_INT); + smode = smallest_int_mode_for_size (byte_size * BITS_PER_UNIT); RTVEC_ELT (v, n) = gen_rtx_EXPR_LIST (VOIDmode, gen_rtx_REG (smode, FIRST_RETURN_REGNUM + n), @@ -3847,7 +3846,7 @@ spu_function_arg (cumulative_args_t cum_ rtx gr_reg; if (byte_size < 4) byte_size = 4; - smode = smallest_mode_for_size (byte_size * BITS_PER_UNIT, MODE_INT); + smode = smallest_int_mode_for_size (byte_size * BITS_PER_UNIT); gr_reg = gen_rtx_EXPR_LIST (VOIDmode, gen_rtx_REG (smode, FIRST_ARG_REGNUM + *cum), const0_rtx); Index: gcc/coverage.c =================================================================== --- gcc/coverage.c 2017-06-07 07:42:16.503137200 +0100 +++ gcc/coverage.c 2017-07-13 09:18:30.899501876 +0100 @@ -143,8 +143,8 @@ static void coverage_obj_finish (vec 32 ? 64 : 32, MODE_INT); + scalar_int_mode mode + = smallest_int_mode_for_size (LONG_LONG_TYPE_SIZE > 32 ? 64 : 32); return lang_hooks.types.type_for_mode (mode, false); } @@ -153,7 +153,7 @@ get_gcov_type (void) static tree get_gcov_unsigned_t (void) { - machine_mode mode = smallest_mode_for_size (32, MODE_INT); + scalar_int_mode mode = smallest_int_mode_for_size (32); return lang_hooks.types.type_for_mode (mode, true); } Index: gcc/dse.c =================================================================== --- gcc/dse.c 2017-07-13 09:18:30.078578052 +0100 +++ gcc/dse.c 2017-07-13 09:18:30.900501783 +0100 @@ -1573,7 +1573,7 @@ find_shift_sequence (int access_size, int shift, bool speed, bool require_cst) { machine_mode store_mode = GET_MODE (store_info->mem); - machine_mode new_mode; + scalar_int_mode new_mode; rtx read_reg = NULL; /* Some machines like the x86 have shift insns for each size of @@ -1583,14 +1583,15 @@ find_shift_sequence (int access_size, justify the value we want to read but is available in one insn on the machine. */ - FOR_EACH_MODE_FROM (new_mode, - smallest_mode_for_size (access_size * BITS_PER_UNIT, - MODE_INT)) + opt_scalar_int_mode new_mode_iter; + FOR_EACH_MODE_FROM (new_mode_iter, + smallest_int_mode_for_size (access_size * BITS_PER_UNIT)) { rtx target, new_reg, new_lhs; rtx_insn *shift_seq, *insn; int cost; + new_mode = *new_mode_iter; if (GET_MODE_BITSIZE (new_mode) > BITS_PER_WORD) break; Index: gcc/expmed.c =================================================================== --- gcc/expmed.c 2017-07-13 09:18:30.080577867 +0100 +++ gcc/expmed.c 2017-07-13 09:18:30.900501783 +0100 @@ -898,7 +898,7 @@ store_bit_field_1 (rtx str_rtx, unsigned is not allowed. */ fieldmode = GET_MODE (value); if (fieldmode == VOIDmode) - fieldmode = smallest_mode_for_size (nwords * BITS_PER_WORD, MODE_INT); + fieldmode = smallest_int_mode_for_size (nwords * BITS_PER_WORD); last = get_last_insn (); for (i = 0; i < nwords; i++) Index: gcc/expr.c =================================================================== --- gcc/expr.c 2017-07-13 09:18:30.083577588 +0100 +++ gcc/expr.c 2017-07-13 09:18:30.901501690 +0100 @@ -346,8 +346,8 @@ convert_move (rtx to, rtx from, int unsi xImode for all MODE_PARTIAL_INT modes they use, but no others. */ if (GET_MODE_CLASS (to_mode) == MODE_PARTIAL_INT) { - machine_mode full_mode - = smallest_mode_for_size (GET_MODE_BITSIZE (to_mode), MODE_INT); + scalar_int_mode full_mode + = smallest_int_mode_for_size (GET_MODE_BITSIZE (to_mode)); gcc_assert (convert_optab_handler (trunc_optab, to_mode, full_mode) != CODE_FOR_nothing); @@ -361,8 +361,8 @@ convert_move (rtx to, rtx from, int unsi if (GET_MODE_CLASS (from_mode) == MODE_PARTIAL_INT) { rtx new_from; - machine_mode full_mode - = smallest_mode_for_size (GET_MODE_BITSIZE (from_mode), MODE_INT); + scalar_int_mode full_mode + = smallest_int_mode_for_size (GET_MODE_BITSIZE (from_mode)); convert_optab ctab = unsignedp ? zext_optab : sext_optab; enum insn_code icode; @@ -6841,8 +6841,8 @@ store_field (rtx target, HOST_WIDE_INT b if (GET_CODE (temp) == PARALLEL) { HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp)); - machine_mode temp_mode - = smallest_mode_for_size (size * BITS_PER_UNIT, MODE_INT); + scalar_int_mode temp_mode + = smallest_int_mode_for_size (size * BITS_PER_UNIT); rtx temp_target = gen_reg_rtx (temp_mode); emit_group_store (temp_target, temp, TREE_TYPE (exp), size); temp = temp_target; @@ -6913,7 +6913,7 @@ store_field (rtx target, HOST_WIDE_INT b word size, we need to load the value (see again store_bit_field). */ if (GET_MODE (temp) == BLKmode && bitsize <= BITS_PER_WORD) { - machine_mode temp_mode = smallest_mode_for_size (bitsize, MODE_INT); + scalar_int_mode temp_mode = smallest_int_mode_for_size (bitsize); temp = extract_bit_field (temp, bitsize, 0, 1, NULL_RTX, temp_mode, temp_mode, false, NULL); } Index: gcc/internal-fn.c =================================================================== --- gcc/internal-fn.c 2017-07-13 09:18:29.217658709 +0100 +++ gcc/internal-fn.c 2017-07-13 09:18:30.902501597 +0100 @@ -2159,7 +2159,7 @@ expand_arith_overflow (enum tree_code co if (orig_precres == precres && precop <= BITS_PER_WORD) { int p = MAX (min_precision, precop); - machine_mode m = smallest_mode_for_size (p, MODE_INT); + scalar_int_mode m = smallest_int_mode_for_size (p); tree optype = build_nonstandard_integer_type (GET_MODE_PRECISION (m), uns0_p && uns1_p && unsr_p); @@ -2201,7 +2201,7 @@ expand_arith_overflow (enum tree_code co if (orig_precres == precres) { int p = MAX (prec0, prec1); - machine_mode m = smallest_mode_for_size (p, MODE_INT); + scalar_int_mode m = smallest_int_mode_for_size (p); tree optype = build_nonstandard_integer_type (GET_MODE_PRECISION (m), uns0_p && uns1_p && unsr_p); Index: gcc/optabs-query.c =================================================================== --- gcc/optabs-query.c 2017-07-13 09:18:22.934277946 +0100 +++ gcc/optabs-query.c 2017-07-13 09:18:30.902501597 +0100 @@ -193,13 +193,15 @@ get_best_extraction_insn (extraction_ins unsigned HOST_WIDE_INT struct_bits, machine_mode field_mode) { - machine_mode mode = smallest_mode_for_size (struct_bits, MODE_INT); - FOR_EACH_MODE_FROM (mode, mode) + opt_scalar_int_mode mode_iter; + FOR_EACH_MODE_FROM (mode_iter, smallest_int_mode_for_size (struct_bits)) { + scalar_int_mode mode = *mode_iter; if (get_extraction_insn (insn, pattern, type, mode)) { - FOR_EACH_MODE_FROM (mode, mode) + FOR_EACH_MODE_FROM (mode_iter, mode) { + mode = *mode_iter; if (GET_MODE_SIZE (mode) > GET_MODE_SIZE (field_mode) || TRULY_NOOP_TRUNCATION_MODES_P (insn->field_mode, field_mode)) Index: gcc/optabs.c =================================================================== --- gcc/optabs.c 2017-07-13 09:18:30.085577402 +0100 +++ gcc/optabs.c 2017-07-13 09:18:30.903501504 +0100 @@ -2083,8 +2083,7 @@ expand_twoval_binop_libfunc (optab binop /* The value returned by the library function will have twice as many bits as the nominal MODE. */ - libval_mode = smallest_mode_for_size (2 * GET_MODE_BITSIZE (mode), - MODE_INT); + libval_mode = smallest_int_mode_for_size (2 * GET_MODE_BITSIZE (mode)); start_sequence (); libval = emit_library_call_value (libfunc, NULL_RTX, LCT_CONST, libval_mode, 2, Index: gcc/stor-layout.c =================================================================== --- gcc/stor-layout.c 2017-07-13 09:18:30.086577310 +0100 +++ gcc/stor-layout.c 2017-07-13 09:18:30.905501319 +0100 @@ -2131,12 +2131,15 @@ layout_type (tree type) case BOOLEAN_TYPE: case INTEGER_TYPE: case ENUMERAL_TYPE: - SET_TYPE_MODE (type, - smallest_mode_for_size (TYPE_PRECISION (type), MODE_INT)); - TYPE_SIZE (type) = bitsize_int (GET_MODE_BITSIZE (TYPE_MODE (type))); - /* Don't set TYPE_PRECISION here, as it may be set by a bitfield. */ - TYPE_SIZE_UNIT (type) = size_int (GET_MODE_SIZE (TYPE_MODE (type))); - break; + { + scalar_int_mode mode + = smallest_int_mode_for_size (TYPE_PRECISION (type)); + SET_TYPE_MODE (type, mode); + TYPE_SIZE (type) = bitsize_int (GET_MODE_BITSIZE (mode)); + /* Don't set TYPE_PRECISION here, as it may be set by a bitfield. */ + TYPE_SIZE_UNIT (type) = size_int (GET_MODE_SIZE (mode)); + break; + } case REAL_TYPE: { @@ -2581,8 +2584,7 @@ initialize_sizetypes (void) bprecision = MIN (precision + LOG2_BITS_PER_UNIT + 1, MAX_FIXED_MODE_SIZE); - bprecision - = GET_MODE_PRECISION (smallest_mode_for_size (bprecision, MODE_INT)); + bprecision = GET_MODE_PRECISION (smallest_int_mode_for_size (bprecision)); if (bprecision > HOST_BITS_PER_DOUBLE_INT) bprecision = HOST_BITS_PER_DOUBLE_INT; @@ -2597,17 +2599,18 @@ initialize_sizetypes (void) TYPE_UNSIGNED (bitsizetype) = 1; /* Now layout both types manually. */ - SET_TYPE_MODE (sizetype, smallest_mode_for_size (precision, MODE_INT)); + scalar_int_mode mode = smallest_int_mode_for_size (precision); + SET_TYPE_MODE (sizetype, mode); SET_TYPE_ALIGN (sizetype, GET_MODE_ALIGNMENT (TYPE_MODE (sizetype))); TYPE_SIZE (sizetype) = bitsize_int (precision); - TYPE_SIZE_UNIT (sizetype) = size_int (GET_MODE_SIZE (TYPE_MODE (sizetype))); + TYPE_SIZE_UNIT (sizetype) = size_int (GET_MODE_SIZE (mode)); set_min_and_max_values_for_integral_type (sizetype, precision, UNSIGNED); - SET_TYPE_MODE (bitsizetype, smallest_mode_for_size (bprecision, MODE_INT)); + mode = smallest_int_mode_for_size (bprecision); + SET_TYPE_MODE (bitsizetype, mode); SET_TYPE_ALIGN (bitsizetype, GET_MODE_ALIGNMENT (TYPE_MODE (bitsizetype))); TYPE_SIZE (bitsizetype) = bitsize_int (bprecision); - TYPE_SIZE_UNIT (bitsizetype) - = size_int (GET_MODE_SIZE (TYPE_MODE (bitsizetype))); + TYPE_SIZE_UNIT (bitsizetype) = size_int (GET_MODE_SIZE (mode)); set_min_and_max_values_for_integral_type (bitsizetype, bprecision, UNSIGNED); /* Create the signed variants of *sizetype. */ Index: gcc/targhooks.c =================================================================== --- gcc/targhooks.c 2017-07-13 09:18:27.468824773 +0100 +++ gcc/targhooks.c 2017-07-13 09:18:30.905501319 +0100 @@ -1177,8 +1177,8 @@ default_autovectorize_vector_sizes (void default_get_mask_mode (unsigned nunits, unsigned vector_size) { unsigned elem_size = vector_size / nunits; - machine_mode elem_mode - = smallest_mode_for_size (elem_size * BITS_PER_UNIT, MODE_INT); + scalar_int_mode elem_mode + = smallest_int_mode_for_size (elem_size * BITS_PER_UNIT); machine_mode vector_mode; gcc_assert (elem_size * nunits == vector_size); Index: gcc/tree-ssa-loop-manip.c =================================================================== --- gcc/tree-ssa-loop-manip.c 2017-07-02 09:32:32.142745257 +0100 +++ gcc/tree-ssa-loop-manip.c 2017-07-13 09:18:30.905501319 +0100 @@ -1513,7 +1513,6 @@ canonicalize_loop_ivs (struct loop *loop gcond *stmt; edge exit = single_dom_exit (loop); gimple_seq stmts; - machine_mode mode; bool unsigned_p = false; for (psi = gsi_start_phis (loop->header); @@ -1540,7 +1539,7 @@ canonicalize_loop_ivs (struct loop *loop precision = TYPE_PRECISION (type); } - mode = smallest_mode_for_size (precision, MODE_INT); + scalar_int_mode mode = smallest_int_mode_for_size (precision); precision = GET_MODE_PRECISION (mode); type = build_nonstandard_integer_type (precision, unsigned_p);