From patchwork Tue Jan 12 06:22:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kugan Vivekanandarajah X-Patchwork-Id: 59600 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp2550720lbb; Mon, 11 Jan 2016 22:23:27 -0800 (PST) X-Received: by 10.98.68.193 with SMTP id m62mr31730930pfi.153.1452579807771; Mon, 11 Jan 2016 22:23:27 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id hp4si25734042pad.113.2016.01.11.22.23.27 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Jan 2016 22:23:27 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-418738-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; spf=pass (google.com: domain of gcc-patches-return-418738-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-418738-patch=linaro.org@gcc.gnu.org; dkim=pass header.i=@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 :subject:to:cc:message-id:date:mime-version:content-type; q=dns; s=default; b=hf/VuZZuchKt/rqFiOl7X6zbKYsX0+verfJfvy4T37W+Oq+YXD NQu3ImDZurKsQTNuBlXAkjETraTgdIqXanIMm5bKfZPkpSEyC0EcG/xIx+c/5fXk tOQmi7q9NOloES5xddAg8qBPPdLCFhYKZF6Ee0GNd7MIGk1/fsHBSRDEA= 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 :subject:to:cc:message-id:date:mime-version:content-type; s= default; bh=fbNYYsgpddcqdIW3N8xw0qQqruU=; b=oy7YtbPmyUGcYsz2OuV2 Bq6EKQVcQ+wDM0Nj5oma37UcNsNAKwed0V+BhtpxnyZe+NgE0DGiAEBCYXU9aZ9w +YfIIQOOJC6WeCWM0LVK6mUFg0IPSWdWetKS79waE6XDop3gKwdt601NBcuZNXCG 6m8yuk2eBaaRuAFT8hIcCd0= Received: (qmail 92031 invoked by alias); 12 Jan 2016 06:23:14 -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 92016 invoked by uid 89); 12 Jan 2016 06:23:13 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=1, 26, 20160112, 2016-01-12 X-HELO: mail-pa0-f47.google.com Received: from mail-pa0-f47.google.com (HELO mail-pa0-f47.google.com) (209.85.220.47) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Tue, 12 Jan 2016 06:23:11 +0000 Received: by mail-pa0-f47.google.com with SMTP id uo6so317728441pac.1 for ; Mon, 11 Jan 2016 22:23:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:subject:to:cc:message-id:date:user-agent :mime-version:content-type; bh=OBAbezi5y+tMAXXVIloWf3Vs5pWO9R2obf4AklJTV+8=; b=eWrs5sAeyML1lNhjs9St8qqztTVO2oRGxcwTeI+XlcTSKmU+BONPZh78N+X39cnUBU hGW9T5dFEFHEFAs2Givm1Lbv4iDDoAPAy7TkvdCc5dC+wEc1YDsEx3Gjp2qmfVD/St7O GEWrL4E3FwzyS2HiMDotc0yQN84dLCuMCkWttRf4ga2iTkwXTd3V/AsWZrC8HjCD/R0C VefkD1kUJpQuD+1VybhJdybCAZ6feLXyOpqZ4Vmdt7in9rkEKu8NDUHYVrsl+s2M/E42 g7/SpNg149y0v34j7TK56cBu0f34WZYu1aMzucTo95eFHdKCjgnMk8JMM8aAsx7+WLU5 npaw== X-Gm-Message-State: ALoCoQlWsWlV4IXYoxSsm3W23bzEJhy/4+aNPg+ZXPiIIJ5f49NONseq+B3cbwem9qyAlOQdvXhy903jWXpFBEILbt/NfAffQA== X-Received: by 10.66.124.232 with SMTP id ml8mr49068265pab.98.1452579789719; Mon, 11 Jan 2016 22:23:09 -0800 (PST) Received: from [10.1.1.5] (58-6-183-210.dyn.iinet.net.au. [58.6.183.210]) by smtp.googlemail.com with ESMTPSA id v26sm27397747pfi.56.2016.01.11.22.23.07 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 11 Jan 2016 22:23:08 -0800 (PST) From: kugan Subject: [RFC][ARM][PR67714] signed char is zero-extended instead of sign-extended To: "gcc-patches@gcc.gnu.org" Cc: Jeff Law , Jim Wilson Message-ID: <56949BBA.60006@linaro.org> Date: Tue, 12 Jan 2016 17:22:50 +1100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0 MIME-Version: 1.0 X-IsSubscribed: yes When promote_function_mode and promote_ssa_mode changes the sign differently, following is the cause for the problem in PR67714. _8 = fn1D.5055 (); f_13 = _8; function returns -15 and in _8 it is sign extended. In the second statement, we say that the value is SUBREG_PROMOTED and promoted sign in unsigned which is wrong. When the value in _8 had come other ways than function call it would be correct (as it would be zero extended). Attached patch checks that and uses the correct promoted sign in this case. The problem with the approach is, when you the following piece of code, we can still fail. But, I dont think I will ever happen. Any thoughts? _8 = fn1D.5055 (); _9 = _8 f_13 = _9; This is similar to PR65932 where sign change in PROMOTE_MODE causes problem for parameter. But need a different fix there. Regression tested on arm-none-linux-gnu with no new regression. I also bootstrapped regression tested (on an earlier version of trunk) for x86_64-none-linux-gnu with no new regressions. If this OK, I will do a full testing again. Comments? Thanks, Kugan gcc/ChangeLog: 2016-01-12 Kugan Vivekanandarajah * expr.c (expand_expr_real_1): Fix promoted sign in SUBREG_PRMOTED for SSA_NAME when rhs has a value returned from function call. gcc/testsuite/ChangeLog: 2016-01-12 Kugan Vivekanandarajah * gcc.target/arm/pr67714.c: New test. diff --git a/gcc/expr.c b/gcc/expr.c index bd43dc4..6a2b3c0 100644 --- a/gcc/expr.c +++ b/gcc/expr.c @@ -9710,7 +9710,25 @@ expand_expr_real_1 (tree exp, rtx target, machine_mode tmode, gimple_call_fntype (g), 2); else - pmode = promote_ssa_mode (ssa_name, &unsignedp); + { + tree rhs; + gimple *stmt; + /* When this is a SSA copy from a value returned from a + function call, use the corect promoted sign for SUBREG_PROMOTED_P + (PR67714). */ + if (code == SSA_NAME + && is_gimple_assign (g) + && (rhs = gimple_assign_rhs1 (g)) + && TREE_CODE (rhs) == SSA_NAME + && (stmt = SSA_NAME_DEF_STMT (rhs)) + && gimple_code (stmt) == GIMPLE_CALL + && !gimple_call_internal_p (stmt)) + pmode = promote_function_mode (type, mode, &unsignedp, + gimple_call_fntype (stmt), + 2); + else + pmode = promote_ssa_mode (ssa_name, &unsignedp); + } gcc_assert (GET_MODE (decl_rtl) == pmode); temp = gen_lowpart_SUBREG (mode, decl_rtl); diff --git a/gcc/testsuite/gcc.target/arm/pr67714.c b/gcc/testsuite/gcc.target/arm/pr67714.c index e69de29..355b559 100644 --- a/gcc/testsuite/gcc.target/arm/pr67714.c +++ b/gcc/testsuite/gcc.target/arm/pr67714.c @@ -0,0 +1,26 @@ + +/* PR target/67714 */ +/* { dg-do-run } */ +/* { dg-options "-O1" } */ + +unsigned int b; +int c; + +signed char fn1 () +{ + signed char d; + for (int i = 0; i < 1; i++) + d = -15; + return d; +} + +int main() +{ + for (c = 0; c < 1; c++) + b = 0; + char e = fn1(); + signed char f = e ^ b; + __builtin_printf("checksum = %x\n", (int)f); + if ((int)f != 0xfffffff1) + __builtin_abort (); +}