From patchwork Wed Apr 18 11:59:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kito Cheng X-Patchwork-Id: 900073 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-476549-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="h9e4CWny"; 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 40R0zD2TDPz9s3Z for ; Wed, 18 Apr 2018 21:59:36 +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 :mime-version:from:date:message-id:subject:to:content-type; q= dns; s=default; b=DsrAiGfCjQVf0BK9gIOrrRZYxC1wYkjDxZ7BIUEEeQktHS HKKsUNfRYT48+Fw+BUo4zsPNfppOy5shMrhjf7vBYgwMN7GTGvXX4/3p2K8OqSG8 vHn81/Q9etbuvoFuB9Dz6dopENt587W95YJEc6csJnBuBhiHuyWcVhxZl2sWE= 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 :mime-version:from:date:message-id:subject:to:content-type; s= default; bh=EH9AdlMXyPOu1NvSYKdOh96eXyY=; b=h9e4CWnyztj5et1gzel7 SJBJdhCpZx1492JF2IHAtq7+pWi49XAh1Gstz9d6tO+rcHlQwgyiMYkld2a9nHK3 8eM9Y5oVHvVLh6fUBuEh/Qg5oxI/EatrJ9K604q9RCvuyM5F3Pi1K6ipGxSAIiOm 2skK4KwOsOjJT7uehiTsHWA= Received: (qmail 108748 invoked by alias); 18 Apr 2018 11:59:29 -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 108736 invoked by uid 89); 18 Apr 2018 11:59:28 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.0 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=here!, round, HTo:U*patches, Round X-HELO: mail-io0-f180.google.com Received: from mail-io0-f180.google.com (HELO mail-io0-f180.google.com) (209.85.223.180) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 18 Apr 2018 11:59:26 +0000 Received: by mail-io0-f180.google.com with SMTP id v13-v6so2071864iob.6 for ; Wed, 18 Apr 2018 04:59:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:from:date:message-id:subject :to; bh=3SNK4LYO2ZFqcKAhugxP6PDdB8jR14KgqfKmuS751x8=; b=F/NfdB5sITKv8o9vm6RhNZt29b+DWI6fUrGyN4in85O2L3cvVtOOINwDE1E4pgdjR4 ZYFFyUG5lWsyIrP8aUR1d0l4+QJqPaRocYVWa3+TXD2inpcAbrTYRM9UEfzJWpNMaaIE yAoB5HtMbKIj4JfKuuxQ6fa5XJkEsl1/X56CitpQTNrnrS7K7cBdDL09Xw7f6oqeQFl1 Q+K0LhVnStH+ckz3P/XucoYnBZbg8F8jUmfO3l/S/L+7SjM8ZWwjITRv7IoFsthSxz3V gzLGo2rrkj9xbBhzg+bzMol+vRV09Ad1/AzZnrkEfnWruUdGrRXeSc18YI6dn8wNGQ5u h/Dg== X-Gm-Message-State: ALQs6tC4nsS9TiAHIxRJKlHiI1T52d4gR0RrqG1C9t5LCX2Qwr1XXAOC 972ZKL0I31eHJajCUvWjFMRecMP71bBM7vAhb3RRNuMe X-Google-Smtp-Source: AIpwx4+eMOPBffehKaSu5xgMF8cLVKgeq5f/OWDd7x+Mi8sYee9OSpVOuojXliuQFiezL6NrqYypEW5xo9L+zDYfLyE= X-Received: by 2002:a6b:9107:: with SMTP id t7-v6mr1006323iod.32.1524052763898; Wed, 18 Apr 2018 04:59:23 -0700 (PDT) MIME-Version: 1.0 Received: by 10.107.140.151 with HTTP; Wed, 18 Apr 2018 04:59:03 -0700 (PDT) From: Kito Cheng Date: Wed, 18 Apr 2018 19:59:03 +0800 Message-ID: Subject: [PATCH] RISC-V: Make sure stack is always aligned during adjusting To: GCC Patches , patches@groups.riscv.org, Jim Wilson , Palmer Dabbelt , Andrew Waterman X-IsSubscribed: yes Hi all: I've hit a bug when running gcc testsuite with gc trunk on our internal simulator, C extension may generate non-aligned stack in some program point. Verified with gcc testsuite on rv32imac/rv32ima elf. Fail case: riscv32-elf-gcc -march=rv32imac gcc/testsuite/gcc.dg/graph ite/interchange-6.c -O2 -ffast-math -floop-nest-opt imize -o - -S ... .type main, @function main: li t1,-81920 addi sp,sp,-36 # <-- stack not aligned here! ... gcc/ChangeLog: 2018-04-18 Kito Cheng * config/riscv/riscv.c (riscv_first_stack_step): Round up min step and round down max step to make sure stack always aligned. From cf75c573ec9c8e5071e54a3cfba377fd0cb5bf3d Mon Sep 17 00:00:00 2001 From: Kito Cheng Date: Wed, 18 Apr 2018 17:51:35 +0800 Subject: [PATCH] RISC-V: Make sure stack is always aligned during adjusting stack. gcc/ChangeLog: 2018-04-18 Kito Cheng * config/riscv/riscv.c (riscv_first_stack_step): Round up min step and round down max step to make sure stack always aligned. --- gcc/config/riscv/riscv.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/gcc/config/riscv/riscv.c b/gcc/config/riscv/riscv.c index 2870177fa97..eca1cacf015 100644 --- a/gcc/config/riscv/riscv.c +++ b/gcc/config/riscv/riscv.c @@ -3507,9 +3507,13 @@ riscv_first_stack_step (struct riscv_frame_info *frame) if (SMALL_OPERAND (frame->total_size)) return frame->total_size; - HOST_WIDE_INT min_first_step = frame->total_size - frame->fp_sp_offset; - HOST_WIDE_INT max_first_step = IMM_REACH / 2 - PREFERRED_STACK_BOUNDARY / 8; - HOST_WIDE_INT min_second_step = frame->total_size - max_first_step; + HOST_WIDE_INT min_first_step = + RISCV_STACK_ALIGN (frame->total_size - frame->fp_sp_offset); + HOST_WIDE_INT max_first_step = + ROUND_DOWN (IMM_REACH / 2 - PREFERRED_STACK_BOUNDARY / 8, + PREFERRED_STACK_BOUNDARY / 8); + HOST_WIDE_INT min_second_step = + RISCV_STACK_ALIGN (frame->total_size - max_first_step); gcc_assert (min_first_step <= max_first_step); /* As an optimization, use the least-significant bits of the total frame -- 2.11.2