From patchwork Fri Nov 6 19:04:13 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Ellcey X-Patchwork-Id: 541081 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 872B11400A0 for ; Sat, 7 Nov 2015 06:04:29 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=qoEWHMeh; 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:from :date:to:subject:mime-version:content-type :content-transfer-encoding:message-id; q=dns; s=default; b=iQTpQ BhEiBfuyVf5CRM47X9HPuQ5IBxqWwAnUWhKzukbQ76FYwRfamtcSWsIs6+jA0S4P oqark7cJthI7ZCx6IcJvlMILtTw9ye2ijybhKtwCfgypDqGXdidonGLMpZqc0kiH 0PoprKPW3Wz+Ln+y5Kc6LHKCyWK4xxnTXxJ6JA= 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 :date:to:subject:mime-version:content-type :content-transfer-encoding:message-id; s=default; bh=t6ikjHk3MHD qYmi9dMDkCqW4u+4=; b=qoEWHMeh6b6yMCz0dTA0hpk7VNbAqDoG0GGWfSdMN4D vZMMns1WtNgnecP20MBmGl4D9WxYyARSERyjlcohAxcnxyoBkyNibLF4e7HdQ6YY uT5iAafZu4IO4jzABX3P1wH4TnZ0jvxjOPVZllghCYV3ZsMs98CyOkLg/4TZMhQY = Received: (qmail 89623 invoked by alias); 6 Nov 2015 19:04:23 -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 89611 invoked by uid 89); 6 Nov 2015 19:04:22 -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, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mailapp01.imgtec.com Received: from mailapp01.imgtec.com (HELO mailapp01.imgtec.com) (195.59.15.196) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 06 Nov 2015 19:04:21 +0000 Received: from hhmail02.hh.imgtec.org (unknown [10.100.10.20]) by Websense Email Security Gateway with ESMTPS id 58FE72BB57E2C for ; Fri, 6 Nov 2015 19:04:14 +0000 (GMT) Received: from BAMAIL02.ba.imgtec.org (10.20.40.28) by hhmail02.hh.imgtec.org (10.100.10.20) with Microsoft SMTP Server (TLS) id 14.3.235.1; Fri, 6 Nov 2015 19:04:17 +0000 Received: from ubuntu-sellcey.mips.com (10.20.3.214) by bamail02.ba.imgtec.org (10.20.40.28) with Microsoft SMTP Server id 14.3.174.1; Fri, 6 Nov 2015 11:04:14 -0800 Received: by ubuntu-sellcey.mips.com (sSMTP sendmail emulation); Fri, 06 Nov 2015 11:04:13 -0800 From: "Steve Ellcey " Date: Fri, 6 Nov 2015 11:04:13 -0800 To: Subject: [Patch] Change to argument promotion in fixed conversion library calls User-Agent: Heirloom mailx 12.5 6/20/10 MIME-Version: 1.0 Message-ID: <15881f44-1bed-4fda-a47c-45234f9c091e@BAMAIL02.ba.imgtec.org> This is part one of a two part patch I want to checkin in order to improve argument passing on MIPS. Right now MIPS defines TARGET_PROMOTE_PROTOTYPES as true and so short and char arguments are getting promoted in the caller and callee functions. The ABI requires callers to do the promotion and so I want to remove the definition of TARGET_PROMOTE_PROTOTYPES which will get rid of the promotion done in the callee. This matches what LLVM and the MIPS Greenhills compilers do. When I made this change I had one regression in the GCC testsuite (gcc.dg/fixed-point/convert-sat.c). I tracked this down to the fact that emit_library_call_value_1 does not do any argument promotion because it does not have the original tree type information for library calls. It only knows about modes. I can't change emit_library_call_value_1 to do the promotion because it does not know whether to do a signed or unsigned promotion, but expand_fixed_convert could do the conversion before calling emit_library_call_value_1 and that is what this patch does. Note that if a target uses one of the default argument promotion functions like default_promote_function_mode or default_promote_function_mode_always_promote, this change will have no affect because they call promote_mode and if promote_mode is called with a NULL_TREE as the first argument it returns the original mode. For target specific promote functions, this change should just cause the promotion to be done in expand_fixed_convert instead of in emit_library_call_value_1 and with the proper setting of unsignedp. This patch by itself will not fix my MIPS bug because it uses one of the default promote functions. Part two of this patch will be to define the TARGET_PROMOTE_FUNCTION_MODE macro on MIPS so that it promotes QI and HI to SI even if the type tree is NULL and then everything will work. The 'real' long term fix for this problem is to have tree types for builtin functions so the proper promotions can always be done but that is a fairly large change that I am not willing to tackle right now and it could probably not be done in time for GCC 6.0 anyway. See https://gcc.gnu.org/ml/gcc/2015-10/msg00234.html for more discussion of this change. Is this part of the patch OK to checkin? Tested on mips-mti-linux-gnu. Steve Ellcey sellcey@imgtec.com 2015-11-06 Steve Ellcey * optabs.c (expand_fixed_convert): Call promote_function_mode. diff --git a/gcc/optabs.c b/gcc/optabs.c index fdcdc6a..964e92a 100644 --- a/gcc/optabs.c +++ b/gcc/optabs.c @@ -4880,6 +4880,24 @@ expand_fixed_convert (rtx to, rtx from, int uintp, int satp) libfunc = convert_optab_libfunc (tab, to_mode, from_mode); gcc_assert (libfunc); + if (SCALAR_INT_MODE_P (from_mode)) + { + /* If we need to promote the integer function argument we need to do + it here instead of inside emit_library_call_value because here we + know if we should be doing a signed or unsigned promotion. */ + + machine_mode arg_mode; + int unsigned_p = 0; + + arg_mode = promote_function_mode (NULL_TREE, from_mode, + &unsigned_p, NULL_TREE, 0); + if (arg_mode != from_mode) + { + from = convert_to_mode (arg_mode, from, uintp); + from_mode = arg_mode; + } + } + start_sequence (); value = emit_library_call_value (libfunc, NULL_RTX, LCT_CONST, to_mode, 1, from, from_mode);