From patchwork Mon Sep 7 03:00:06 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kugan Vivekanandarajah X-Patchwork-Id: 514961 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 ADD59140321 for ; Mon, 7 Sep 2015 13:00:38 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=XaH+kOtP; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=cE84VxLwaQYqyL6N/ fbXpn1JtlsgAgyKH0E/IS1ijfdlJRN+LIndV+Qz7Lxmhf+sQjPDK2TWz2z96kb83 tW0q9B49XFexoJnGhrERyrkY1Mrf7DatDSKR4EgJxjWuE9nluJtKn3AVOHfK32V1 dtWD8y6JyQe1Y4q3Ch8DwE+iBA= 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 :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=scV0/hOzFy/tXFQ+Vi2osl8 uajE=; b=XaH+kOtPn8Q32lrtyKS7sM+q37c8tJ3U56wCi5E+SBBlXleWkelNpmM 42cTm26zKqSa9D8Yii4PV9jmAoOBWqId7+1+ibSx2zf35nwMY3q0XfnqFN1SVt6T TlmuHLzEdmvGzQS2LBCsVz5wucbYDf3BP2/mlzRvK3OqkzCAdd+E= Received: (qmail 80893 invoked by alias); 7 Sep 2015 03:00:28 -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 80540 invoked by uid 89); 7 Sep 2015 03:00:16 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pa0-f41.google.com Received: from mail-pa0-f41.google.com (HELO mail-pa0-f41.google.com) (209.85.220.41) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Mon, 07 Sep 2015 03:00:15 +0000 Received: by pacej10 with SMTP id ej10so794880pac.3 for ; Sun, 06 Sep 2015 20:00:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-type; bh=UMxkYX1z21V5brRPFznWD/vq5QqSIT6564RUpQPoOJ0=; b=SWFIUdyE+qTH6h1iHUwWgC4QdieuNl3/nhZBuJ6LctUso7lZ3FqPNJ9LyM4CPDxa99 Fin7MxAm0S5G8gRSCW+umzERt7+tuVkUdywstzQFIAe3ajHUlG06EeOoMpUVuXiDPan9 LrWzep/xeKvlkfYfDhl3TIz6G45pz/G0Wymfj3t/Ey08o6hhiNI6+yhYYGb2lpT8mJtK jI9a+1x3zZw+Z8OahhZ7vZ+kPnyAP8TpwjGzcWLPJgkOBaXali1BpgGxF9HqnqHSGm1C vnXjLwinxrkdyBjHh/bmcyks4pbBQZRIvEWRc0sBKjM8J2UL23dHhLFSOwh7Rs2nYNJS sFOg== X-Gm-Message-State: ALoCoQk/0H3upRj6QAhsO0OwFnOd5fpfpPca05dn4ZuP540rG3vXAN/I2k9ALgTbaZPrexbt7atX X-Received: by 10.66.145.74 with SMTP id ss10mr40929822pab.28.1441594813782; Sun, 06 Sep 2015 20:00:13 -0700 (PDT) Received: from [10.1.1.7] (58-6-183-210.dyn.iinet.net.au. [58.6.183.210]) by smtp.googlemail.com with ESMTPSA id v2sm9995612pdf.54.2015.09.06.20.00.11 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 06 Sep 2015 20:00:13 -0700 (PDT) Subject: [4/7] Use correct promoted mode sign for result of GIMPLE_CALL To: "gcc-patches@gcc.gnu.org" References: <55ECFC2A.7050908@linaro.org> Cc: Richard Biener From: Kugan Message-ID: <55ECFDB6.8010100@linaro.org> Date: Mon, 7 Sep 2015 13:00:06 +1000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: <55ECFC2A.7050908@linaro.org> X-IsSubscribed: yes For the following testcase (compiling with -O1; -O2 works fine), we have a stmt with stm_code SSA_NAME (_7 = _ 6) and for which _6 is defined by a GIMPLE_CALL. In this case, we are using wrong SUNREG promoted mode resulting in wrong code. Simple SSA_NAME copes are generally optimized but when they are not, we can end up using the wrong promoted mode. Attached patch fixes when we have one copy. I think it might be better to do this in a while loop but I don't think it can happen in practice. Please let me know what you think. _6 = bar5 (-10); ... _7 = _6; _3 = (long unsigned int) _6; ... if (_3 != l5.0_4) for extern void abort (void); __attribute__ ((noinline)) static unsigned short int foo5 (int x) { return x; } __attribute__ ((noinline)) short int bar5 (int x) { return foo5 (x + 6); } unsigned long l5 = (short int) -4; int main (void) { if (bar5 (-10) != l5) abort (); return 0; } gcc/ChangeLog: 2015-09-07 Kugan Vivekanandarajah * expr.c (expand_expr_real_1): Set proper SUNREG_PROMOTED_MODE for SSA_NAME that was set by GIMPLE_CALL and assigned to another SSA_NAME of same type. From 64ac68bfda1d3e8487827512e6d163b384e8a1cf Mon Sep 17 00:00:00 2001 From: Kugan Vivekanandarajah Date: Wed, 2 Sep 2015 12:18:41 +1000 Subject: [PATCH 4/8] use correct promoted sign for result of GIMPLE_CALL --- gcc/expr.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/gcc/expr.c b/gcc/expr.c index bcd87c0..6dac3cf 100644 --- a/gcc/expr.c +++ b/gcc/expr.c @@ -9633,7 +9633,22 @@ 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; + 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); -- 1.9.1