From patchwork Thu Jul 13 08:52:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 107626 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp1935460qge; Thu, 13 Jul 2017 01:54:07 -0700 (PDT) X-Received: by 10.98.207.2 with SMTP id b2mr60205761pfg.16.1499936047295; Thu, 13 Jul 2017 01:54:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499936047; cv=none; d=google.com; s=arc-20160816; b=auPTEmJm/KxZEbdhVcQ3T3topG/VDZI2FEmOa5RMDbplWB/qLVnsHQTcI61gP/sysZ qj9wGwYNzeSYp2sJMhhDJDsddtC0ZgY1drWwdPF4PDIWXql1N+vlJV9QOprceX3J+/Fd WOs9TpusJZ2EmC0RaYyL4+XdACJEM0DRiUe9k2k1MJSLooPhVHeDjdpWeEss+8ZJ/ESf fTV0M2rSI6aGqgNMGhXSubQnQOx36JoNN/SNvNwXyN6xO9XYqtpQSM3taBJKVtm6Jhn2 3cc1OB3lPlS2L19PMUR0RnJcc7AvGYz7UyMrCNR1zbbj2zDrsGf2tNDQfDWu1aTaRL4P uikw== 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=d8SQ8o5FYKESZseoZAPmegiry43RJt0ZsORobWotHZk=; b=Y9Tby5csZToG+Ci1cHnpTvTRNiCWVRDvlUsTYpgH1qaJlaZzJLSfdf3MAnhmnxb7xZ EXjCsUwZfV1Qq51RnGKUxdEKyDr0dSZ9Df8C7aypGjPE/cyH4rGMXNqnjNE6udDi6A9y Du4jM9F1axQxWChMEdl8i7KNvQI5fI9HYD9cLUMzBoFNKIj4ekqwd1RWXtE+5ZZEk4xu cLPzinoNgJ16uSD6F9kYpB6DNrZHlvAMjvyu6D5rsOdOh1o++p3vaGsLinhXPMyeFiAq +Lxq873HLt2NbsKqQQpqGRWTyQr2d8Mb6ZZla5/nDu+Ir0ycD3NgE1M+6Os1KHKWqbwI Nmxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.b=CcK4yesP; spf=pass (google.com: domain of gcc-patches-return-458031-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-458031-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 e127si3758126pgc.44.2017.07.13.01.54.07 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Jul 2017 01:54:07 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-458031-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=CcK4yesP; spf=pass (google.com: domain of gcc-patches-return-458031-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-458031-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=IUX3FBNGJ6fEERj3U+Z9xmJoptjsV QfofbuBiJo5dqOUgANM4ocir0FobqrhIzbtdwtvQ2t63Sy7+r+k00Tca3tS/YI97 grOSWdbG2zg9Q81aVUokjpVseHkGMJCxzs+CB3qYCVSUp4Y1//eNL/rPd897Cq3F GsZEExRrPaAGWA= 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=YM/LbJx1raqTlfCRZFKJ7iUIe54=; b=CcK 4yesPYuFHQeUXPvyeB4nDEfApCKkaaeRrZwoXjJIOE3XQDAKrFP6sul2/9WCOqmx 3V1zKfKR/ZaAKofnGoUEmQu+ubVZNYnkfEZkQA13z55pG/Ia2DA2NLS8D2WPd2qq 4stG65lHs8khYQtAja3Wg+R7rbY5nxdJY0mEAW/I= Received: (qmail 84253 invoked by alias); 13 Jul 2017 08:52:58 -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 82892 invoked by uid 89); 13 Jul 2017 08:52:57 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=1009 X-HELO: mail-wm0-f52.google.com Received: from mail-wm0-f52.google.com (HELO mail-wm0-f52.google.com) (74.125.82.52) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 13 Jul 2017 08:52:53 +0000 Received: by mail-wm0-f52.google.com with SMTP id i127so18289157wma.0 for ; Thu, 13 Jul 2017 01:52:52 -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=d8SQ8o5FYKESZseoZAPmegiry43RJt0ZsORobWotHZk=; b=iBh6ldP9B/vnUaiUHeqgnUjZ+6Lt9fiOvfF9kNF0rvFi0uybktOwqO2YKcCOuY9/94 m/s01z1/vuiJXVxFVL6YNBbUIiVzmc4nvSLxTcQ0BOUkHpH0SpWq/QpTaiQJv/0R46Z/ O7oT9KIpZOiVS9drIVnAy+l9ASa5Mr9K+v135G4oCl8bOiee2oF7IVV6LU6AGzQg+FPk KgSsVB1z2gn9ExaOWUQ7tYMpryqkU9XwNbuEFdab2g8Nq4ODTATRnIhAF7RxYkRkGMQi R1cDlSyQS97UY/0zqwI1MlqiTmloi22PAmIOeUIZgPDv+g6nULBGE0NrfV5YFzE+L6Zl 29lA== X-Gm-Message-State: AIVw110HRIZCgeF9bZBPt8SIhziJzYejwAN54HMCV71aWeveixUU9uLW 8zt7pf0c6j/vQM+PbYpkqw== X-Received: by 10.28.142.133 with SMTP id q127mr1173983wmd.4.1499935970978; Thu, 13 Jul 2017 01:52:50 -0700 (PDT) Received: from localhost (92.40.249.184.threembb.co.uk. [92.40.249.184]) by smtp.gmail.com with ESMTPSA id n2sm6338898wmd.19.2017.07.13.01.52.49 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 13 Jul 2017 01:52:50 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@linaro.org Subject: [40/77] Use scalar_int_mode for extraction_insn fields References: <8760ewohsv.fsf@linaro.org> Date: Thu, 13 Jul 2017 09:52:48 +0100 In-Reply-To: <8760ewohsv.fsf@linaro.org> (Richard Sandiford's message of "Thu, 13 Jul 2017 09:35:44 +0100") Message-ID: <87d194hg67.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 insv, extv and eztzv modify or read a field in a register or memory. The field always has a scalar integer mode, while the register or memory either has a scalar integer mode or BLKmode. The mode of the bit position is also a scalar integer. This patch uses the type system to make that explicit. 2017-07-13 Richard Sandiford Alan Hayward David Sherwood gcc/ * optabs-query.h (extraction_insn::struct_mode): Change type to opt_scalar_int_mode and update comment. (extraction_insn::field_mode): Change type to scalar_int_mode. (extraction_insn::pos_mode): Likewise. * combine.c (make_extraction): Update accordingly. * optabs-query.c (get_traditional_extraction_insn): Likewise. (get_optab_extraction_insn): Likewise. * recog.c (simplify_while_replacing): Likewise. * expmed.c (narrow_bit_field_mem): Chane the type of the mode parameter to opt_scalar_int_mode. Index: gcc/optabs-query.h =================================================================== --- gcc/optabs-query.h 2017-02-23 19:54:15.000000000 +0000 +++ gcc/optabs-query.h 2017-07-13 09:18:42.162518990 +0100 @@ -141,16 +141,17 @@ struct extraction_insn enum insn_code icode; /* The mode that the structure operand should have. This is byte_mode - when using the legacy insv, extv and extzv patterns to access memory. */ - machine_mode struct_mode; + when using the legacy insv, extv and extzv patterns to access memory. + If no mode is given, the structure is a BLKmode memory. */ + opt_scalar_int_mode struct_mode; /* The mode of the field to be inserted or extracted, and by extension the mode of the insertion or extraction itself. */ - machine_mode field_mode; + scalar_int_mode field_mode; /* The mode of the field's bit position. This is only important when the position is variable rather than constant. */ - machine_mode pos_mode; + scalar_int_mode pos_mode; }; bool get_best_reg_extraction_insn (extraction_insn *, Index: gcc/combine.c =================================================================== --- gcc/combine.c 2017-07-13 09:18:39.584734236 +0100 +++ gcc/combine.c 2017-07-13 09:18:42.160519154 +0100 @@ -7632,7 +7632,7 @@ make_extraction (machine_mode mode, rtx if (get_best_reg_extraction_insn (&insn, pattern, GET_MODE_BITSIZE (inner_mode), mode)) { - wanted_inner_reg_mode = insn.struct_mode; + wanted_inner_reg_mode = *insn.struct_mode; pos_mode = insn.pos_mode; extraction_mode = insn.field_mode; } Index: gcc/optabs-query.c =================================================================== --- gcc/optabs-query.c 2017-07-13 09:18:30.902501597 +0100 +++ gcc/optabs-query.c 2017-07-13 09:18:42.161519072 +0100 @@ -100,9 +100,14 @@ get_traditional_extraction_insn (extract pos_mode = word_mode; insn->icode = icode; - insn->field_mode = field_mode; - insn->struct_mode = (type == ET_unaligned_mem ? byte_mode : struct_mode); - insn->pos_mode = pos_mode; + insn->field_mode = as_a (field_mode); + if (type == ET_unaligned_mem) + insn->struct_mode = byte_mode; + else if (struct_mode == BLKmode) + insn->struct_mode = opt_scalar_int_mode (); + else + insn->struct_mode = as_a (struct_mode); + insn->pos_mode = as_a (pos_mode); return true; } @@ -126,12 +131,17 @@ get_optab_extraction_insn (struct extrac const struct insn_data_d *data = &insn_data[icode]; + machine_mode pos_mode = data->operand[pos_op].mode; + if (pos_mode == VOIDmode) + pos_mode = word_mode; + insn->icode = icode; - insn->field_mode = mode; - insn->struct_mode = (type == ET_unaligned_mem ? BLKmode : mode); - insn->pos_mode = data->operand[pos_op].mode; - if (insn->pos_mode == VOIDmode) - insn->pos_mode = word_mode; + insn->field_mode = as_a (mode); + if (type == ET_unaligned_mem) + insn->struct_mode = opt_scalar_int_mode (); + else + insn->struct_mode = insn->field_mode; + insn->pos_mode = as_a (pos_mode); return true; } Index: gcc/recog.c =================================================================== --- gcc/recog.c 2017-07-13 09:18:39.591733644 +0100 +++ gcc/recog.c 2017-07-13 09:18:42.162518990 +0100 @@ -663,25 +663,18 @@ simplify_while_replacing (rtx *loc, rtx MEM_ADDR_SPACE (XEXP (x, 0))) && !MEM_VOLATILE_P (XEXP (x, 0))) { - machine_mode wanted_mode = VOIDmode; int pos = INTVAL (XEXP (x, 2)); - + machine_mode new_mode = is_mode; if (GET_CODE (x) == ZERO_EXTRACT && targetm.have_extzv ()) - { - wanted_mode = insn_data[targetm.code_for_extzv].operand[1].mode; - if (wanted_mode == VOIDmode) - wanted_mode = word_mode; - } + new_mode = insn_data[targetm.code_for_extzv].operand[1].mode; else if (GET_CODE (x) == SIGN_EXTRACT && targetm.have_extv ()) - { - wanted_mode = insn_data[targetm.code_for_extv].operand[1].mode; - if (wanted_mode == VOIDmode) - wanted_mode = word_mode; - } + new_mode = insn_data[targetm.code_for_extv].operand[1].mode; + scalar_int_mode wanted_mode = (new_mode == VOIDmode + ? word_mode + : as_a (new_mode)); /* If we have a narrower mode, we can do something. */ - if (wanted_mode != VOIDmode - && GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode)) + if (GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode)) { int offset = pos / BITS_PER_UNIT; rtx newmem; Index: gcc/expmed.c =================================================================== --- gcc/expmed.c 2017-07-13 09:18:41.678559010 +0100 +++ gcc/expmed.c 2017-07-13 09:18:42.161519072 +0100 @@ -409,31 +409,32 @@ flip_storage_order (machine_mode mode, r return result; } -/* Adjust bitfield memory MEM so that it points to the first unit of mode - MODE that contains a bitfield of size BITSIZE at bit position BITNUM. - If MODE is BLKmode, return a reference to every byte in the bitfield. - Set *NEW_BITNUM to the bit position of the field within the new memory. */ +/* If MODE is set, adjust bitfield memory MEM so that it points to the + first unit of mode MODE that contains a bitfield of size BITSIZE at + bit position BITNUM. If MODE is not set, return a BLKmode reference + to every byte in the bitfield. Set *NEW_BITNUM to the bit position + of the field within the new memory. */ static rtx -narrow_bit_field_mem (rtx mem, machine_mode mode, +narrow_bit_field_mem (rtx mem, opt_scalar_int_mode mode, unsigned HOST_WIDE_INT bitsize, unsigned HOST_WIDE_INT bitnum, unsigned HOST_WIDE_INT *new_bitnum) { - if (mode == BLKmode) + if (mode.exists ()) + { + unsigned int unit = GET_MODE_BITSIZE (*mode); + *new_bitnum = bitnum % unit; + HOST_WIDE_INT offset = (bitnum - *new_bitnum) / BITS_PER_UNIT; + return adjust_bitfield_address (mem, *mode, offset); + } + else { *new_bitnum = bitnum % BITS_PER_UNIT; HOST_WIDE_INT offset = bitnum / BITS_PER_UNIT; HOST_WIDE_INT size = ((*new_bitnum + bitsize + BITS_PER_UNIT - 1) / BITS_PER_UNIT); - return adjust_bitfield_address_size (mem, mode, offset, size); - } - else - { - unsigned int unit = GET_MODE_BITSIZE (mode); - *new_bitnum = bitnum % unit; - HOST_WIDE_INT offset = (bitnum - *new_bitnum) / BITS_PER_UNIT; - return adjust_bitfield_address (mem, mode, offset); + return adjust_bitfield_address_size (mem, BLKmode, offset, size); } }