From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 108763 invoked by alias); 26 Feb 2018 20:49:44 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 108740 invoked by uid 89); 26 Feb 2018 20:49:44 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-12.3 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_LOW,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=refuses X-HELO: mx1.redhat.com Received: from mx3-rdu2.redhat.com (HELO mx1.redhat.com) (66.187.233.73) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 26 Feb 2018 20:49:42 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7CC2240FB656 for ; Mon, 26 Feb 2018 20:49:30 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-204-85.brq.redhat.com [10.40.204.85]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 130BF1C718 for ; Mon, 26 Feb 2018 20:49:29 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id w1QK6QYY019788; Mon, 26 Feb 2018 21:06:26 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id w1QK6O1t019787; Mon, 26 Feb 2018 21:06:25 +0100 Date: Mon, 26 Feb 2018 20:49:00 -0000 From: Jakub Jelinek To: Uros Bizjak , "H.J.Lu" Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix ICE with -mforce-indirect-call (PR target/84564) Message-ID: <20180226200624.GZ5867@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.9.1 (2017-09-22) X-IsSubscribed: yes X-SW-Source: 2018-02/txt/msg01461.txt.bz2 Hi! While this isn't a regression, it is ICE in newly added feature and so should be fixed too. The problem is that with -mforce-indirect-call even direct calls are emitted as indirect, and if we have in 32-bit mode a direct call to a regparm(3) function or a direct call to a function we've optimized using regparm(3) convention internally, we can't really tail call it, as there aren't any registers left for the address of the function in the indirect call, eax/ecx/edx are used to pass arguments, esp has fixed role and the rest needs to be already restored. The following patch refuses to tail call in that case, similarly how we reject to tail call an indirect call to a regparm(3) function. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2018-02-26 Jakub Jelinek PR target/84564 * config/i386/i386.c (ix86_function_ok_for_sibcall): Check for regparm >= 3 with no arg reg available also for calls with flag_force_indirect_call. Pass decl to ix86_function_regparm. * gcc.target/i386/pr84564.c: New test. --- gcc/config/i386/i386.c.jj 2018-02-22 22:25:57.109993153 +0100 +++ gcc/config/i386/i386.c 2018-02-26 15:14:11.786294313 +0100 @@ -6411,7 +6411,8 @@ ix86_function_ok_for_sibcall (tree decl, function via GOT slot are indirect. */ if (!decl || (bind_global && flag_pic && !flag_plt) - || (TARGET_DLLIMPORT_DECL_ATTRIBUTES && DECL_DLLIMPORT_P (decl))) + || (TARGET_DLLIMPORT_DECL_ATTRIBUTES && DECL_DLLIMPORT_P (decl)) + || flag_force_indirect_call) { /* Check if regparm >= 3 since arg_reg_available is set to false if regparm == 0. If regparm is 1 or 2, there is @@ -6420,7 +6421,7 @@ ix86_function_ok_for_sibcall (tree decl, ??? The symbol indirect call doesn't need a call-clobbered register. But we don't know if this is a symbol indirect call or not here. */ - if (ix86_function_regparm (type, NULL) >= 3 + if (ix86_function_regparm (type, decl) >= 3 && !cfun->machine->arg_reg_available) return false; } --- gcc/testsuite/gcc.target/i386/pr84564.c.jj 2018-02-26 15:10:02.981296789 +0100 +++ gcc/testsuite/gcc.target/i386/pr84564.c 2018-02-26 14:57:38.287304183 +0100 @@ -0,0 +1,21 @@ +/* PR target/84564 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -mforce-indirect-call" } */ + +int a, b, c, d; +int foo (void); + +static int +bar (int x, int y, int z) +{ + while (a) + if (foo ()) + bar (x, y, z); + return 0; +} + +int +baz (void) +{ + return bar (b, c, d); +} Jakub