From patchwork Fri Aug 2 07:11:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kito Cheng X-Patchwork-Id: 1140992 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-506056-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="p1t6SNyo"; dkim=pass (2048-bit key; unprotected) header.d=sifive.com header.i=@sifive.com header.b="RtwXy5bk"; dkim-atps=neutral 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 460JHx0VJxz9s7T for ; Fri, 2 Aug 2019 17:11:54 +1000 (AEST) 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:cc:subject:date:message-id; q=dns; s=default; b=TD72JsgcyckF BtsWkDa//UEvOE3ooGHco2U8qBx9S6pTwIp+eQfaf9db9DEMTKhcZOOlwtBo3w3T qYpIGooX3L7XK21eG+hR0mWcGa8N/FIDGkW0lGmUrsdzqzmALtt8lvTtFsxsEeEc Fyci2atYybi6guTzE0C3Q1DDYdXg70I= 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:cc:subject:date:message-id; s=default; bh=qu4sVbXuROObYj9Dtl 8F6LymOgI=; b=p1t6SNyok8rBMieSIWmkPPgIokmMehBZsreVKsN6s1GsW0Pc7s xjYOYiQcDZ2/xLVmE+wJj1PGY8Dh3I79m6xX/gc3eI7+gHAM9/hvheWw3rm6oX6q 2SjnKUx/rwyRqZj1XjkffDRXcVRA52p6OQ8h6FmT/UdcJcSRYDS5yuCb0= Received: (qmail 71213 invoked by alias); 2 Aug 2019 07:11:47 -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 71205 invoked by uid 89); 2 Aug 2019 07:11:47 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=H*r:sk:mail-pf, HX-HELO:sk:mail-pf X-HELO: mail-pf1-f173.google.com Received: from mail-pf1-f173.google.com (HELO mail-pf1-f173.google.com) (209.85.210.173) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 02 Aug 2019 07:11:46 +0000 Received: by mail-pf1-f173.google.com with SMTP id f17so31553498pfn.6 for ; Fri, 02 Aug 2019 00:11:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id; bh=h34QlHCX8ZNssZD5Las6Hj4eNW4wJfJg8FTDjh6YZnA=; b=RtwXy5bkMvkWgoq/lTmozjKdCykPcVryt1TMseeWH3ZL4TVbMGNGYUOImaKL+Y46cj gpsHLKqE1Fw4gVgRBPKZ8YqR/4zCzxgO0J4HIYYv6f2ul9/INl3Pmt+l4bgxRi4w0Ecq XdqAVBonaL/DrNTxwrfy+Nb7oKAQJkGEDYqfxjezDvJ/qKlDUQmb4TsFrfjW7THU23Up X27npQMul0wce2e8GFJ9JFJG0CkE8DWcToxX+N/vtLAjgEw2rdIz0TckBO18S+KuWayi pJ7Q66zuVvvUye7wptcWJdK0mRmLnj6InvUjYA4xNpADdSmeJyg3ZT+cm/6zPMgWJjja Y8eA== Received: from gamma06.internal.sifive.com ([64.62.193.194]) by smtp.gmail.com with ESMTPSA id v185sm84043192pfb.14.2019.08.02.00.11.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 02 Aug 2019 00:11:43 -0700 (PDT) From: Kito Cheng To: gcc-patches@gcc.gnu.org, kito.cheng@gmail.com, jimw@sifive.com Cc: Kito Cheng Subject: [PATCH v2] RISC-V: Promote type correctly for libcalls Date: Fri, 2 Aug 2019 00:11:25 -0700 Message-Id: <1564729885-7984-1-git-send-email-kito.cheng@sifive.com> - argument and return value for libcall won't promote at default_promote_function_mode_always_promote, however we expect it should sign-extend as normal function. - Witout this patch, this test case will fail at -march=rv64i -mabi=lp64. - The implementation of riscv_promote_function_mode is borrowed from MIPS. gcc/ChangeLog * config/riscv/riscv.c (riscv_promote_function_mode): New. (TARGET_PROMOTE_FUNCTION_MODE): Use riscv_promote_function_mode. gcc/testsuite/ChangeLog * gcc.target/riscv/promote-type-for-libcall.c: New. --- gcc/config/riscv/riscv.c | 28 +++++++++++++++- .../gcc.target/riscv/promote-type-for-libcall.c | 37 ++++++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.target/riscv/promote-type-for-libcall.c diff --git a/gcc/config/riscv/riscv.c b/gcc/config/riscv/riscv.c index e274f1b..431e90a 100644 --- a/gcc/config/riscv/riscv.c +++ b/gcc/config/riscv/riscv.c @@ -4910,6 +4910,32 @@ riscv_constant_alignment (const_tree exp, HOST_WIDE_INT align) return align; } +/* Implement TARGET_PROMOTE_FUNCTION_MODE. */ + +/* This function is equivalent to default_promote_function_mode_always_promote + except that it returns a promoted mode even if type is NULL_TREE. This is + needed by libcalls which have no type (only a mode) such as fixed conversion + routines that take a signed or unsigned char/short/int argument and convert + it to a fixed type. */ + +static machine_mode +riscv_promote_function_mode (const_tree type ATTRIBUTE_UNUSED, + machine_mode mode, + int *punsignedp ATTRIBUTE_UNUSED, + const_tree fntype ATTRIBUTE_UNUSED, + int for_return ATTRIBUTE_UNUSED) +{ + int unsignedp; + + if (type != NULL_TREE) + return promote_mode (type, mode, punsignedp); + + unsignedp = *punsignedp; + PROMOTE_MODE (mode, unsignedp, type); + *punsignedp = unsignedp; + return mode; +} + /* Initialize the GCC target structure. */ #undef TARGET_ASM_ALIGNED_HI_OP #define TARGET_ASM_ALIGNED_HI_OP "\t.half\t" @@ -4951,7 +4977,7 @@ riscv_constant_alignment (const_tree exp, HOST_WIDE_INT align) #define TARGET_EXPAND_BUILTIN_VA_START riscv_va_start #undef TARGET_PROMOTE_FUNCTION_MODE -#define TARGET_PROMOTE_FUNCTION_MODE default_promote_function_mode_always_promote +#define TARGET_PROMOTE_FUNCTION_MODE riscv_promote_function_mode #undef TARGET_RETURN_IN_MEMORY #define TARGET_RETURN_IN_MEMORY riscv_return_in_memory diff --git a/gcc/testsuite/gcc.target/riscv/promote-type-for-libcall.c b/gcc/testsuite/gcc.target/riscv/promote-type-for-libcall.c new file mode 100644 index 0000000..bdbcbc0 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/promote-type-for-libcall.c @@ -0,0 +1,37 @@ +/* { dg-do run } */ +/* { dg-options "-O1 -ftree-slp-vectorize -funroll-loops" } */ + +#include +#include +#define N 4 +volatile float f[N]; +int x[N] __attribute__((aligned(8))); +int main() { + int i; + x[0] = -1; + x[1] = 2; + x[2] = -2; + x[3] = 2; + + for (i=0;i