From patchwork Wed Jul 11 22:11:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 942723 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-481390-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="n61MTyD7"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41QtZF49F2z9s01 for ; Thu, 12 Jul 2018 08:11:15 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; q=dns; s=default; b=rUnwAQeti7tOwaWdVmkzvRF11fu8E /uKRK+s9dcVmUe2l+XozZElAS/7ilQhqX2jAKnFs4nCs+QCxAIkF9cxkPBnlR3lu LjjTbDJg254YGVLifklOjn0mYp0y1eyZIUlW0LVS1lfUjkZ3eH83QdVHdhdOXUDP QOv5GxrD8697GY= 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:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; s=default; bh=cP3+zn8cKL0qyw4OtIYCmtVJ4PE=; b=n61 MTyD7/+O0Mxe1wh7hHTX2ZtMhUL93Ht9KuovWHivGfLKZFjaa/gI8CIatsJ2iDnD bsATrxRAmuTiDj+t209bEAhTJrkrnfYD4i8yEzr7Qsnr+n0eASx6cODaeG8q2YJp Rh1cR3Fytd3Jg/8QtBqDMFyllCflTr0dKMm0cSwo= Received: (qmail 60304 invoked by alias); 11 Jul 2018 22:11:09 -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 60003 invoked by uid 89); 11 Jul 2018 22:11:08 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-10.9 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=uf, UD:jj, UD:c.jj, smarts X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 11 Jul 2018 22:11:06 +0000 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7AC5E3084038; Wed, 11 Jul 2018 22:11:05 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-117-71.ams2.redhat.com [10.36.117.71]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1BE765C23B; Wed, 11 Jul 2018 22:11:04 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id w6BMB2nS022693; Thu, 12 Jul 2018 00:11:03 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id w6BMB0C2022692; Thu, 12 Jul 2018 00:11:00 +0200 Date: Thu, 12 Jul 2018 00:11:00 +0200 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix store-merging wrong-code issue (PR tree-optimization/86492) Message-ID: <20180711221100.GL7166@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.2 (2017-12-15) X-IsSubscribed: yes Hi! The following testcase is a similar issue to PR84503 and the fix is similar, because coalesce_immediate_stores temporarily sorts the stores on ascending bitpos and if stores are merged, the merged store is emitted in the location of the latest of the stores, we need to verify that there is no overlap with other stores that are originally before that latest store from those we are considering and overlaps the set of stores we are considering to merge. In that case we need to punt and not merge (unless we do smarts like prove overlap between just some of the stores and force reordering). Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk and 8.2? 2018-07-11 Jakub Jelinek PR tree-optimization/86492 * gimple-ssa-store-merging.c (imm_store_chain_info::coalesce_immediate_stores): Call check_no_overlap even for the merge_overlapping case. Formatting fix. * gcc.c-torture/execute/pr86492.c: New test. Jakub --- gcc/gimple-ssa-store-merging.c.jj 2018-06-13 10:05:53.000000000 +0200 +++ gcc/gimple-ssa-store-merging.c 2018-07-11 19:24:12.084120206 +0200 @@ -2702,7 +2702,12 @@ imm_store_chain_info::coalesce_immediate { /* Only allow overlapping stores of constants. */ if (info->rhs_code == INTEGER_CST - && merged_store->stores[0]->rhs_code == INTEGER_CST) + && merged_store->stores[0]->rhs_code == INTEGER_CST + && check_no_overlap (m_store_info, i, INTEGER_CST, + MAX (merged_store->last_order, info->order), + MAX (merged_store->start + + merged_store->width, + info->bitpos + info->bitsize))) { merged_store->merge_overlapping (info); goto done; @@ -2732,10 +2737,8 @@ imm_store_chain_info::coalesce_immediate info->ops_swapped_p = true; } if (check_no_overlap (m_store_info, i, info->rhs_code, - MAX (merged_store->last_order, - info->order), - MAX (merged_store->start - + merged_store->width, + MAX (merged_store->last_order, info->order), + MAX (merged_store->start + merged_store->width, info->bitpos + info->bitsize))) { /* Turn MEM_REF into BIT_INSERT_EXPR for bit-field stores. */ --- gcc/testsuite/gcc.c-torture/execute/pr86492.c.jj 2018-07-11 19:40:27.760122514 +0200 +++ gcc/testsuite/gcc.c-torture/execute/pr86492.c 2018-07-11 19:40:13.460107841 +0200 @@ -0,0 +1,34 @@ +/* PR tree-optimization/86492 */ + +union U +{ + unsigned int r; + struct S + { + unsigned int a:12; + unsigned int b:4; + unsigned int c:16; + } f; +}; + +__attribute__((noipa)) unsigned int +foo (unsigned int x) +{ + union U u; + u.r = 0; + u.f.c = x; + u.f.b = 0xe; + return u.r; +} + +int +main () +{ + union U u; + if (__CHAR_BIT__ * __SIZEOF_INT__ != 32 || sizeof (u.r) != sizeof (u.f)) + return 0; + u.r = foo (0x72); + if (u.f.a != 0 || u.f.b != 0xe || u.f.c != 0x72) + __builtin_abort (); + return 0; +}