From patchwork Tue Oct 30 16:10:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uros Bizjak X-Patchwork-Id: 990965 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-488623-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="g8nPwwJM"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="vLsByOx7"; 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 42kxJt1XzLz9s4s for ; Wed, 31 Oct 2018 03:10:36 +1100 (AEDT) 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:cc:content-type; q=dns; s=default; b=NWyDjEVYvXKMu5EBk7oDxwsS5uzujzF4SUgRfaeJ5rF BHrKDtlP2qdh/anuni8k3S8NcNKrRB6gkR/eCNFP3+mFJtft1rzFdEkBEYuANMWu 1POocNRF89/huUeUeeAirR7G7/Ll3OIajcXqV6QX1rAUvP8dnRU78qFEH/dDl6ZA = 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:cc:content-type; s=default; bh=iAaPjK8NgKBgJ+WEcHu5wx49yUA=; b=g8nPwwJMNCgTrikJA 9DowJzppgXOXB7eeY4OL8Q1reOlgdU9ETAwNzjgB3agPWVgm7drgNF7kVvyQ/GFZ rglofoTMTFUtyXg7B1gRIqeOxsfNGCJ7Jh8Vk2UD/WxOfHaO8xbR1iJyxpuqAvT/ u8VXpRM4tsInCV5Cx/By8WmmEg= Received: (qmail 2466 invoked by alias); 30 Oct 2018 16:10: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 2439 invoked by uid 89); 30 Oct 2018 16:10:28 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.6 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=calls.c, outmode, UD:calls.c, callsc X-HELO: mail-io1-f51.google.com Received: from mail-io1-f51.google.com (HELO mail-io1-f51.google.com) (209.85.166.51) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 30 Oct 2018 16:10:26 +0000 Received: by mail-io1-f51.google.com with SMTP id q4-v6so7583163iob.8 for ; Tue, 30 Oct 2018 09:10:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to:cc; bh=JtSpd9AyXhcIcGM5v0lldUtrSNU8kXi+sBff10rRvFQ=; b=vLsByOx7Nqn5AV7X98/eFYkCVh9UBBO3bidOM+Kj2ETw+XWl2Lc7fbMUxoxbGAmH9h SG5156XXlg5gkY8Ivzc53FA3/vPkGpjxz41oTfGUq2OtwjoQ+hUkLEMsxqMFMxijECBh 0W2C1Qt1tx/2McnWJemVk3hUPygGXhuARmBygOkagbdo8Yto2iVLH+EnHoRuY5kOMF+5 VCxIbgVbvf48FVv5ZLEXBH6NGktZB0c3WloVxDLyC0YgzmEgUsYB/GbyVe2p7onPK4HY wgwYkIna7pP0xlEz3an1EA+RzXUejR4jZJQoexIUwtmQTkthlEyzj7sfr4iT5bPe+zlw NA6Q== MIME-Version: 1.0 From: Uros Bizjak Date: Tue, 30 Oct 2018 17:10:12 +0100 Message-ID: Subject: [RFT PATCH, middle end]: Fix PR58372, internal compiler error: ix86_compute_frame_layout To: "gcc-patches@gcc.gnu.org" Cc: "H. J. Lu" Hello! Function calls, generated directly through emit_library_call (for the testcase from PR the compiler builds a call to _Unwind_SjLj_Register via sjlj_emit_function_enter) miss a whole lot of stack realignmnet setup. There is an update to crtl->preferred_stack_boundary present, but several updates for SUPPORTS_STACK_ALIGNMENT targets are missing, including eventual DRAP setup. Attached patch introduces additional updates to stack realignment crtl variables in emit_library_call_1, based on what expand_stack_alignment from cfgrtl.c does. In addition to update of preferred_stack_boundary, it updates stack_alignment_estimated and stack_alignment_needed. The patch also updates dependent variables stack_realign_meeded and stack_realign_tried. Additionally, if needed, DRAP register is prepared. 2018-10-30 Uros Bizjak PR middle-end/58372 * calls.c (emit_library_call_value_1): For SUPPORTS_STACK_ALIGNMENT targets, also update crtl->stack_alignment_estimated, crtl->stack_alignment_needed, crtl->stack_realign_needed, crtl->stack_realign_tried and prepare DRAP register if needed. testsuite/ChangeLog: 2018-10-30 Uros Bizjak PR middle-end/58372 * g++.target/i386/pr58372.C: New test. The patch was bootstrapped and regression tested on x86_64-linux-gnu {,-m32}. Additionally, the testcase from PR (and a couple of similar ones) were compiled for i686-w64-mingw32 target with various combinations of -mpreferred-stack-boundary= -mincoming-stack-boundary= -mforce-drap and -m{no-}accumulate-outgoing-args. The patch is posted as RFT, to leave some time for eventual tests on other targets, comments and possible approval. Uros. Index: calls.c =================================================================== --- calls.c (revision 265582) +++ calls.c (working copy) @@ -4736,9 +4736,41 @@ emit_library_call_value_1 (int retval, rtx orgfun, /* Ensure current function's preferred stack boundary is at least what we need. */ - if (crtl->preferred_stack_boundary < PREFERRED_STACK_BOUNDARY) - crtl->preferred_stack_boundary = PREFERRED_STACK_BOUNDARY; + unsigned int preferred_stack_boundary = PREFERRED_STACK_BOUNDARY; + if (preferred_stack_boundary > crtl->preferred_stack_boundary) + crtl->preferred_stack_boundary = preferred_stack_boundary; + + if (SUPPORTS_STACK_ALIGNMENT) + { + if (preferred_stack_boundary > crtl->stack_alignment_estimated) + crtl->stack_alignment_estimated = preferred_stack_boundary; + if (preferred_stack_boundary > crtl->stack_alignment_needed) + crtl->stack_alignment_needed = preferred_stack_boundary; + + crtl->stack_realign_needed + = INCOMING_STACK_BOUNDARY < crtl->stack_alignment_estimated; + crtl->stack_realign_tried = crtl->stack_realign_needed; + + if (crtl->drap_reg == NULL_RTX) + { + rtx drap_rtx = targetm.calls.get_drap_rtx (); + + /* stack_realign_drap and drap_rtx must match. */ + gcc_assert ((stack_realign_drap != 0) == (drap_rtx != NULL)); + + /* Do nothing if NULL is returned, which means DRAP is not needed. */ + if (drap_rtx != NULL) + { + crtl->args.internal_arg_pointer = drap_rtx; + + /* Call fixup_tail_calls to clean up REG_EQUIV note if DRAP is + needed. */ + fixup_tail_calls (); + } + } + } + /* If this kind of value comes back in memory, decide where in memory it should come back. */ if (outmode != VOIDmode) Index: testsuite/g++.target/i386/pr58372.C =================================================================== --- testsuite/g++.target/i386/pr58372.C (nonexistent) +++ testsuite/g++.target/i386/pr58372.C (working copy) @@ -0,0 +1,9 @@ +/* PR target/58372 */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +__attribute__ ((__target__ ("rdrnd"))) +void f (unsigned int *b) noexcept +{ + __builtin_ia32_rdrand32_step (b); +}