From patchwork Wed Jan 11 09:59:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 62933 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 455DB385B522 for ; Wed, 11 Jan 2023 10:00:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 455DB385B522 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1673431212; bh=LZJphaVWDWAUVOjz5vsGSLJ8WD9henjpURPwnUCWGxg=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=p+7E8o2CN/tc8SQgSGPz1RRtpNF7FN+NaSvNv3PXLgJ1xoAjkW4Daz/mg1/RebAmF JWGZOBctrJItUT+f1Ud0sBcsiY8p3XHmdUV2qy586OwcIPG3yR7ebH7UsLj6iKRXAC hqLiafuw9nHNXyOeIquKLvCtIOXSQn8oCwSzx2ug= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by sourceware.org (Postfix) with ESMTPS id 7294E3858289 for ; Wed, 11 Jan 2023 09:59:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7294E3858289 Received: by mail-wm1-x330.google.com with SMTP id j16-20020a05600c1c1000b003d9ef8c274bso7835965wms.0 for ; Wed, 11 Jan 2023 01:59:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=LZJphaVWDWAUVOjz5vsGSLJ8WD9henjpURPwnUCWGxg=; b=JwjLrf2CMB2DMTyqwe+PoLRiDvt4xKDhHBQPiHDV5WkGCGcUi+toxqYzBOBHjQzogA 2zslN2psBJwQJbV40gSXrl/4UrImUfJrlycXlfjwjxSD1MJVRLigcbNRb5WEOM59bAmP KsinwGurBJvPONVIbu3lArA4E4sLAcEenXZ7mvlP7nJ9A+MEMuW0fCYeQytFQ5Deb5mx MixkQwLdfMw1hVW1gTuVpcVqpalsRF43tRnEGv+VCnIRhw/uq4vzQMJK0W046+bPeEx2 j0ONeVOmggSM+J4M6QCOCwI7uq3XjRXQ/Jy3xSYMkYvmR/okBGOa8Wf2NK7SO6PzYpi7 OjmQ== X-Gm-Message-State: AFqh2kqe8k3l4qKUwPRPQZ4JszbCG4Zz2FDqUarrZaGJC2koevn0h+5Z /V4ahj31F/u1LKWjB/JmDKwFCRFJAgJV+hY0 X-Google-Smtp-Source: AMrXdXvy3Nu3PZTPDnbcp6UXauRfmSGiwGItNRmXyjkbt0Oehpit/2MgL/COk391cwf6g9GBHnvF9g== X-Received: by 2002:a05:600c:5c8:b0:3d1:4145:b3b with SMTP id p8-20020a05600c05c800b003d141450b3bmr53262783wmd.9.1673431180703; Wed, 11 Jan 2023 01:59:40 -0800 (PST) Received: from fomalhaut.localnet ([2a01:e0a:8d5:d990:e654:e8ff:fe8f:2ce6]) by smtp.gmail.com with ESMTPSA id p16-20020a05600c469000b003d9b87296a9sm24623953wmo.25.2023.01.11.01.59.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Jan 2023 01:59:40 -0800 (PST) X-Google-Original-From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix PR tree-optimization/108199 Date: Wed, 11 Jan 2023 10:59:39 +0100 Message-ID: <2889898.e9J7NaK4W3@fomalhaut> MIME-Version: 1.0 X-Spam-Status: No, score=-10.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: , X-Patchwork-Original-From: Eric Botcazou via Gcc-patches From: Eric Botcazou Reply-To: Eric Botcazou Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi, this fixes the problematic interaction between bitfields, unions, SSO and SRA. Tested on x86-64/Linux and SPARC/Solaris, OK for all active branches? 2023-01-11 Eric Botcazou Andreas Krebbel PR tree-optimization/108199 * tree-sra.cc (sra_modify_expr): Deal with reverse storage order for bit-field references. 2023-01-11 Eric Botcazou * gcc.dg/sso-17.c: New test. diff --git a/gcc/tree-sra.cc b/gcc/tree-sra.cc index f0182a45485..ad0c738645d 100644 --- a/gcc/tree-sra.cc +++ b/gcc/tree-sra.cc @@ -3858,7 +3858,23 @@ sra_modify_expr (tree *expr, gimple_stmt_iterator *gsi, bool write) } } else - *expr = repl; + { + /* If we are going to replace a scalar field in a structure with + reverse storage order by a stand-alone scalar, we are going to + effectively byte-swap the scalar and we also need to byte-swap + the portion of it represented by the bit-field. */ + if (bfr && REF_REVERSE_STORAGE_ORDER (bfr)) + { + REF_REVERSE_STORAGE_ORDER (bfr) = 0; + TREE_OPERAND (bfr, 2) + = size_binop (MINUS_EXPR, TYPE_SIZE (TREE_TYPE (repl)), + size_binop (PLUS_EXPR, TREE_OPERAND (bfr, 1), + TREE_OPERAND (bfr, 2))); + } + + *expr = repl; + } + sra_stats.exprs++; } else if (write && access->grp_to_be_debug_replaced)