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: 41873 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3229267wrt; Wed, 11 Jan 2023 02:00:34 -0800 (PST) X-Google-Smtp-Source: AMrXdXuy0H+vckMYhUeHpbZUhphhskhbMfSjCxl8Ec/MtTGTUheJ0pQUcltzmoiKRmksEbakZlxw X-Received: by 2002:a17:906:30c2:b0:7ae:c0b:a25c with SMTP id b2-20020a17090630c200b007ae0c0ba25cmr56937889ejb.13.1673431234397; Wed, 11 Jan 2023 02:00:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673431234; cv=none; d=google.com; s=arc-20160816; b=Cimr+qF7uKB4U1nBtAYDGUJlZ51Qk/1n6uimXJhcnUrgkNCG++GMw3a3Ue4L6lc0LB siBq4S1IdTRt0RutlES6oPhadGu4ijy2gnHDz6PQMHx5U7eJKQvgLV8O4KUXMo49lwgB Ah0Nm0bAv0tc2i3J0ZeJaUShJVHbHJHrQ9PrYPNDnxijHV/5BKsKN6hdGA0gTlwlBMCq ID+dlGRsp9TD+I7CtSRCB/TIsjTyGnAcOKi4Blf8vDmTBAEYLP3b4pYkzJhubKlYFrHW Pa4LZPObRq6fI1bYaiiACqkAcNGR0URn8xnYGqXKaNbt/RXLOZq8ecYr45Fw6h+E3SPn 6k6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=LZJphaVWDWAUVOjz5vsGSLJ8WD9henjpURPwnUCWGxg=; b=NTlCovDJBxjoXpqevdPFCFZG+mCIEllxlvNT6KscJA9naylWT5/DN0Q8U/GkMzz0jx cTfydcwxsra8Y/uBs1K1MbUHjUyVbjG1YW3ynVYzNwO2umHow/P/cluEeTL6hYpE3GrY 8XZ+Q9AWfafm9SepqeFsNkQRAjgcbdzotKLYnErzZ5TBG6yiKOEjv5qNLGPIgWOhekJ4 ZX2zPGPPTiqROZR0qlXUhy5mRBjKj9+ut9KrSMemSmLop0etr5X8PFIriARSo0dtIH/E sRP18AO/yUI69HPYilSLo51+0fOWJge4hPPiu0e0p1DnL0Kb8RNZl72z8Jhh0zScUQjf +RYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=GQYHcqyk; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id a16-20020aa7cf10000000b0046351fa4ae2si12874208edy.99.2023.01.11.02.00.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Jan 2023 02:00:34 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=GQYHcqyk; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 23A5B38582A3 for ; Wed, 11 Jan 2023 10:00:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 23A5B38582A3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1673431227; bh=LZJphaVWDWAUVOjz5vsGSLJ8WD9henjpURPwnUCWGxg=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=GQYHcqykD9wg5qQ4LAYOs9yfhiP1g+htW/lFprDneWzyjBb6pBoVYSuJrxbKrtBJ/ Bns8G9nO0dDczT+Fp2H4vXy6W9o36+j+xEMVeHF5VPX2iFWk85NgCMRSynXpKi5m0S cdtF+8CmO6fG9HRI28G0IX+Wh+Lulr6QBJqYd8eI= 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-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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754719829763034629?= X-GMAIL-MSGID: =?utf-8?q?1754719829763034629?= 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)