From patchwork Thu Aug 1 11:48:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kito Cheng X-Patchwork-Id: 1140418 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-505980-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="vKBSbPwB"; dkim=pass (2048-bit key; unprotected) header.d=sifive.com header.i=@sifive.com header.b="W/pCDOtw"; 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 45zpVk21dRz9s7T for ; Thu, 1 Aug 2019 21:49:32 +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=vk3u+q71ybH/ Rd4Er7tJJ/zU9vs47ylQoKMG1fct3HoVSTUuXHbI7hXegR8VV1d18QDugNtghQWh +fXIu0kJjNFV090neXhLkQQAzbcTSM5bxNjfAttDQj79K/qO0b4GiWsz0048q+Zt YpKQLWVqMQy+hJOneBjG+Y8tdoio0iI= 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=Y+xif/Kzn6ZNOwEej6 gcJZAN5Vg=; b=vKBSbPwBSVwikjAByRR2us/sP/H7QKY/CAYiT2mndequumFrC+ 4qbti3vqdS31hYDm3fp0S0nHbYnMgPO8HftvRmJ173adPV3NS59Suobo5rTnDXyq QL36pWSTg0mrQaPis33B5rPWlwp+bcCP9rLjguPZCBZ3Q+h9o6F46Rb2E= Received: (qmail 61971 invoked by alias); 1 Aug 2019 11:49: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 61495 invoked by uid 89); 1 Aug 2019 11:48:47 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=Promote, HX-Spam-Relays-External:209.85.210.195, H*RU:209.85.210.195, H*r:sk:mail-pf X-HELO: mail-pf1-f195.google.com Received: from mail-pf1-f195.google.com (HELO mail-pf1-f195.google.com) (209.85.210.195) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 01 Aug 2019 11:48:37 +0000 Received: by mail-pf1-f195.google.com with SMTP id u14so33946258pfn.2 for ; Thu, 01 Aug 2019 04:48:35 -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=O79w9WrxMne/mshol0v/xDxDTW+CjyRkOzGiQJsPut8=; b=W/pCDOtw4HDcY1KxZdrh/L5fIyKQXeyJ4lwTcYIDKGa+a2ITP2vD/V0TW3/4qR6XTH U7wzGPe9gu/kyvGx3muQUdjOhKJuiw02sLVWm8Qs2hzar8w6TOm/BUzVVefDpvInGa2C iwKHLdugks60y26EZwjUdyHEEhJimvQ3ELIOlsCXyvYTXvXp8S4BZougiXW7uMl65wC/ tBgxm+0TOkVYYJLmsXEF+G4vJCFvkPgEFW2iiFv6veds8J/wyATKYb2cxy/JOE88KePB issxUeVFthva7WQe3ZpGUC9KQIWfDzxmjAULUiky9+MqpUDkW9P9p0gzCgNfibqQvO9a GpkQ== Received: from gamma06.internal.sifive.com ([64.62.193.194]) by smtp.gmail.com with ESMTPSA id j6sm62863293pfa.141.2019.08.01.04.48.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 01 Aug 2019 04:48:33 -0700 (PDT) From: Kito Cheng To: gcc-patches@gcc.gnu.org, kito.cheng@gmail.com, jimw@sifive.com Cc: Kito Cheng Subject: [PATCH] RISC-V: Promote type correctly for libcalls Date: Thu, 1 Aug 2019 04:48:30 -0700 Message-Id: <1564660110-29983-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..7d80fe1 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..5d37029 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/promote-type-for-libcall.c @@ -0,0 +1,37 @@ +/* { dg-do run } */ +/* { dg-options "-O3" } */ + +#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