From patchwork Mon Jan 9 10:43:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 90385 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp18518qgi; Mon, 9 Jan 2017 02:46:53 -0800 (PST) X-Received: by 10.99.121.69 with SMTP id u66mr157873073pgc.96.1483958813548; Mon, 09 Jan 2017 02:46:53 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id f3si17568536pld.153.2017.01.09.02.46.53 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Jan 2017 02:46:53 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-445658-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; spf=pass (google.com: domain of gcc-patches-return-445658-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-445658-patch=linaro.org@gcc.gnu.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:date:message-id:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=jqtP2NlcVno2Qghz MlCfS8ZYkIg+2MdeliD2MZCOL7fJYbyagrJcEA1eruVpGN7T01GuNmZJkFEABftQ uSERlh3rY2ho8dJ7FkQujzrTsTTBC4BfPcNGzrNwIOPzrPK2Ck3Pki+95liZSHPc 4Lo/pCkl6MhuuTP96rtpIjz8cm8= 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:date:message-id:mime-version:content-type :content-transfer-encoding; s=default; bh=KDr8d80v1Z7k/4JUnGaEWi jzo3w=; b=U446kYNzYWHfwb4aq75/stTE/gTU04HQc7CfjrKDX1oQTbLgOK/+Rx qLhF0msDh6TYYBSgdDjQKMrYoULQWotKt61IKGosJ2doJjwLd/2NVs+sumna47My 4+1kLmMA1usEtfMxpdDDf0bJHtRAzU3kYpV+5GKKCZHpv7u5F3aQs= Received: (qmail 107751 invoked by alias); 9 Jan 2017 10:46:40 -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 107741 invoked by uid 89); 9 Jan 2017 10:46:39 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=Bc, bb, immune, Ba X-HELO: smtp.eu.adacore.com Received: from mel.act-europe.fr (HELO smtp.eu.adacore.com) (194.98.77.210) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 09 Jan 2017 10:46:29 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 53874826EC for ; Mon, 9 Jan 2017 11:46:27 +0100 (CET) Received: from smtp.eu.adacore.com ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id hpkNbuKN2IGU for ; Mon, 9 Jan 2017 11:46:27 +0100 (CET) Received: from polaris.localnet (bon31-6-88-161-99-133.fbx.proxad.net [88.161.99.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.eu.adacore.com (Postfix) with ESMTPSA id 0B3F3826CB for ; Mon, 9 Jan 2017 11:46:26 +0100 (CET) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [patch] Fix wrong code for return of small aggregates on big-endian Date: Mon, 09 Jan 2017 11:43 +0100 Message-ID: <22150809.kPoQm0lI1j@polaris> User-Agent: KMail/4.14.10 (Linux/3.16.7-53-desktop; KDE/4.14.9; x86_64; ; ) MIME-Version: 1.0 Hi, this is a regression present on all active branches for big-endian targets returning small aggregate types in registers under certain circumstances and when optimization is enabled: when the bitfield path of store_field is taken, the function ends up calling store_bit_field to store the value. Now the behavior of store_bit_field is awkward when the mode is BLKmode: it always takes its value from the lsb up to the word size but expects it left justified beyond it (see expmed.c:890 and below) and I missed that when I got rid of the stack temporaries that were originally generated in that case. Of course that's OK for little-endian targets but not for big-endian targets, and I have a couple of C++ testcases exposing the issue on SPARC 64-bit and a couple of Ada testcases exposing the issue on PowerPC with the SVR4 ABI (the Linux ABI is immune since it always returns on the stack); I think they cover all the cases in the problematic code. The attached fix was tested on a bunch of platforms: x86/Linux, x86-64/Linux, PowerPC/Linux, PowerPC64/Linux, PowerPC/VxWorks, Aarch64/Linux, SPARC/Solaris and SPARC64/Solaris with no regressions. OK for the mainline? other branches? 2017-01-09 Eric Botcazou * expr.c (store_field): In the bitfield case, if the value comes from a function call and is of an aggregate type returned in registers, do not modify the field mode; extract the value in all cases if the mode is BLKmode and the size is not larger than a word. 2017-01-09 Eric Botcazou * g++.dg/opt/call2.C: New test. * g++.dg/opt/call3.C: Likewise. * gnat.dg/array26.adb: New test. * gnat.dg/array26_pkg.ad[sb]: New helper. * gnat.dg/array27.adb: New test. * gnat.dg/array27_pkg.ad[sb]: New helper. * gnat.dg/array28.adb: New test. * gnat.dg/array28_pkg.ad[sb]: New helper. -- Eric Botcazou Index: expr.c =================================================================== --- expr.c (revision 244194) +++ expr.c (working copy) @@ -6888,33 +6888,30 @@ store_field (rtx target, HOST_WIDE_INT b if (GET_CODE (temp) == PARALLEL) { HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp)); - rtx temp_target; - if (mode == BLKmode || mode == VOIDmode) - mode = smallest_mode_for_size (size * BITS_PER_UNIT, MODE_INT); - temp_target = gen_reg_rtx (mode); + machine_mode temp_mode + = smallest_mode_for_size (size * BITS_PER_UNIT, MODE_INT); + rtx temp_target = gen_reg_rtx (temp_mode); emit_group_store (temp_target, temp, TREE_TYPE (exp), size); temp = temp_target; } - else if (mode == BLKmode) + + /* Handle calls that return BLKmode values in registers. */ + else if (mode == BLKmode && REG_P (temp) && TREE_CODE (exp) == CALL_EXPR) + { + rtx temp_target = gen_reg_rtx (GET_MODE (temp)); + copy_blkmode_from_reg (temp_target, temp, TREE_TYPE (exp)); + temp = temp_target; + } + + /* The behavior of store_bit_field is awkward when mode is BLKmode: + it always takes its value from the lsb up to the word size but + expects it left justified beyond it. At this point TEMP is left + justified so extract the value in the former case. */ + if (mode == BLKmode && bitsize <= BITS_PER_WORD) { - /* Handle calls that return BLKmode values in registers. */ - if (REG_P (temp) && TREE_CODE (exp) == CALL_EXPR) - { - rtx temp_target = gen_reg_rtx (GET_MODE (temp)); - copy_blkmode_from_reg (temp_target, temp, TREE_TYPE (exp)); - temp = temp_target; - } - else - { - HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp)); - rtx temp_target; - mode = smallest_mode_for_size (size * BITS_PER_UNIT, MODE_INT); - temp_target = gen_reg_rtx (mode); - temp_target - = extract_bit_field (temp, size * BITS_PER_UNIT, 0, 1, - temp_target, mode, mode, false); - temp = temp_target; - } + machine_mode temp_mode = smallest_mode_for_size (bitsize, MODE_INT); + temp = extract_bit_field (temp, bitsize, 0, 1, NULL_RTX, temp_mode, + temp_mode, false); } /* Store the value in the bitfield. */