From patchwork Mon May 25 10:32:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 1297257 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=adacore-com.20150623.gappssmtp.com header.i=@adacore-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=x/sycxGD; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49Vtj84q3Rz9sSd for ; Mon, 25 May 2020 20:33:15 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 38548383F870; Mon, 25 May 2020 10:33:12 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by sourceware.org (Postfix) with ESMTPS id D125638708EB for ; Mon, 25 May 2020 10:32:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D125638708EB Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=botcazou@adacore.com Received: by mail-wr1-x42e.google.com with SMTP id t18so2573811wru.6 for ; Mon, 25 May 2020 03:32:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=AKKxA5ltAJ3h/MGp4na8GUVD/MNryzQqA2OGQ01QfRY=; b=x/sycxGDetP3YsfnS8ZoJMZVjfuAY8gjyfIShwdwDUMleTVEfoRaY2M3qOrsgi6pw8 k4uGZmcZZwmGEjUK2QziHcxHHwyM0mTABoK+FAWLrhtIVStIond5Up/MXkj9u8K9fcqs sijUFBNfROk+eEGA6JQX77BTm5H9smqjZ6NDU//4Ar3i3sbbaa5VevNa7ApwvW8xm9it w+t+GCUyjG3B3aW6G/YBaA0PybanrQekNk5uYYoi/3RZNIcGMzpQV0kBFJgaICjT07Ym hg+g8YHcUSwk6OEAZ+94qrlw1SgH69OqYnUrpwKosSb9dcEeb91ui6bLhcCNJm9aRIuX Ej7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=AKKxA5ltAJ3h/MGp4na8GUVD/MNryzQqA2OGQ01QfRY=; b=ZH/4WtU0VRyq+do3rKIzk9GyEk54lxM8jfrvh7oCtimEv2vA/tvZDQstxbh8WPkYuA mzlV8xGsXRyZk+z3PGY0UwYr9X+/c8EI37F03HaXaY7pP2kIEP2MkEDXQQ+tm4j+e6Sg j7XRJPte/3IFhQShFvnSlR2RgiIlwtvURPmLZltGSscCG/qyWptrSn0XHB60Q7W6slqK 16UvSarLixEHayCspKahmzOto6BIHlhrM5w91Zo7bBRWwdwW8mst18y3DhUp5wYyrQ7o qGwx0bFSDdhdecwFfB8oAKCyTwo9FP+JlbCWyTSDWwBfX5uGBJbj0Ql/B7m2Z3j0YJkK bJyg== X-Gm-Message-State: AOAM5336OmuCXyyOelYV4gffQS+GFGt1Dfp7fkga7dJ72kvsYxty36NZ zcQZ/8b0q0+YrNiNQGFBJ1xKkUuRuXD8Rg== X-Google-Smtp-Source: ABdhPJx1XHvPi8o597DwFyw2egJQS/WijB4iUuxAVPexyrXjVkD9qjiS1hvlqmvUUe3Kdl3Vve7RFw== X-Received: by 2002:adf:f702:: with SMTP id r2mr15185031wrp.191.1590402773214; Mon, 25 May 2020 03:32:53 -0700 (PDT) Received: from polaris.localnet ([2a01:e0a:41b:9230:1a03:73ff:fe45:373a]) by smtp.gmail.com with ESMTPSA id b185sm352029wmd.3.2020.05.25.03.32.52 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 May 2020 03:32:52 -0700 (PDT) From: Eric Botcazou X-Google-Original-From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [patch] Fix internal error on store to FP component at -O2 Date: Mon, 25 May 2020 12:32:51 +0200 Message-ID: <2672026.bC0PhPkkHn@polaris> MIME-Version: 1.0 X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi, the attached Ada testcase triggers a GIMPLE verification failure at -O2 or above because the GIMPLE store merging pass generates a NOP_EXPR between a FP type and an integral type. This happens when the bit-field insertion path is taken for a FP field, which can happen in Ada for bit-packed record types. It is fixed by generating an intermediate VIEW_CONVERT_EXPR. The patch also tames a little the bit-field insertion path because, for bit-packed record types in Ada, you can end up with large bit-field regions, which results in a lot of mask-and-shifts instructions. Tested on x86-64/Linux, OK for the mainline? 2020-05-25 Eric Botcazou * gimple-ssa-store-merging.c (merged_store_group::can_be_merged_into): Only turn MEM_REFs into bit-field stores for small bit-field regions. (imm_store_chain_info::output_merged_store): Be prepared for sources with non-integral type in the bit-field insertion case. (pass_store_merging::process_store): Use MAX_BITSIZE_MODE_ANY_INT as the largest size for the bit-field case. 2020-05-25 Eric Botcazou * gnat.dg/opt84.adb: New test. diff --git a/gcc/gimple-ssa-store-merging.c b/gcc/gimple-ssa-store-merging.c index c8e1877f540..65e27f38fd4 100644 --- a/gcc/gimple-ssa-store-merging.c +++ b/gcc/gimple-ssa-store-merging.c @@ -1867,19 +1867,22 @@ merged_store_group::can_be_merged_into (store_immediate_info *info) if (stores[0]->rhs_code == BIT_INSERT_EXPR && info->rhs_code == INTEGER_CST) return true; - /* We can turn MEM_REF into BIT_INSERT_EXPR for bit-field stores. */ + /* We can turn MEM_REF into BIT_INSERT_EXPR for bit-field stores, but do it + only for small regions since this can generate a lot of instructions. */ if (info->rhs_code == MEM_REF && (stores[0]->rhs_code == INTEGER_CST || stores[0]->rhs_code == BIT_INSERT_EXPR) && info->bitregion_start == stores[0]->bitregion_start - && info->bitregion_end == stores[0]->bitregion_end) + && info->bitregion_end == stores[0]->bitregion_end + && info->bitregion_end - info->bitregion_start < MAX_BITSIZE_MODE_ANY_INT) return true; if (stores[0]->rhs_code == MEM_REF && (info->rhs_code == INTEGER_CST || info->rhs_code == BIT_INSERT_EXPR) && info->bitregion_start == stores[0]->bitregion_start - && info->bitregion_end == stores[0]->bitregion_end) + && info->bitregion_end == stores[0]->bitregion_end + && info->bitregion_end - info->bitregion_start < MAX_BITSIZE_MODE_ANY_INT) return true; return false; @@ -4172,6 +4175,15 @@ imm_store_chain_info::output_merged_store (merged_store_group *group) const HOST_WIDE_INT end_gap = (try_bitpos + try_size) - (info->bitpos + info->bitsize); tree tem = info->ops[0].val; + if (!INTEGRAL_TYPE_P (TREE_TYPE (tem))) + { + const unsigned HOST_WIDE_INT size + = tree_to_uhwi (TYPE_SIZE (TREE_TYPE (tem))); + tree integer_type + = build_nonstandard_integer_type (size, UNSIGNED); + tem = gimple_build (&seq, loc, VIEW_CONVERT_EXPR, + integer_type, tem); + } if (TYPE_PRECISION (TREE_TYPE (tem)) <= info->bitsize) { tree bitfield_type @@ -4788,7 +4800,7 @@ pass_store_merging::process_store (gimple *stmt) && bitsize.is_constant (&const_bitsize) && ((const_bitsize % BITS_PER_UNIT) != 0 || !multiple_p (bitpos, BITS_PER_UNIT)) - && const_bitsize <= 64) + && const_bitsize <= MAX_BITSIZE_MODE_ANY_INT) { /* Bypass a conversion to the bit-field type. */ if (!bit_not_p