From patchwork Thu Dec 6 23:34:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1009135 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-491844-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="Bd8AlwRB"; 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 439sQL0J62z9s55 for ; Fri, 7 Dec 2018 10:34:47 +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:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; q=dns; s=default; b=QUHgklhvirM0/TzzvgqwqCAvrZoeQ 3YqCpqnc7R/vcmEJCDrLyNtEUO/Pmsu47IVYmIh+hGqoF6Zloh/uTIKUQxGJqQbq TAcGHulj462cofOyL8/2ijUw+kGSmK/THLFNjKCfBxy0d53pXMvq0itOsI1AUkeV 7M/CvsJezjSy3Q= 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:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; s=default; bh=0yErEuPuKnI7HD0E7I+n+m6dR7Y=; b=Bd8 AlwRBqKu+kBogBAWZcVw5PhPzwdAZSmCiyclQ2OykQ56Wz/Mvm8ztsI6Q62Y3bG+ btbrcM7w+L7xnGXfpgKqJnkkT0rmUY1MeFGZDoDgcnmjmm3F303aFxzQQFhMVa14 RFeliEVm4UCAnzM3BkAUUOLPHGHMxQtql8S/IMms= Received: (qmail 69236 invoked by alias); 6 Dec 2018 23:34:41 -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 69216 invoked by uid 89); 6 Dec 2018 23:34:40 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-10.9 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=lp64 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 06 Dec 2018 23:34:38 +0000 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A8F6CC05FF96; Thu, 6 Dec 2018 23:34:37 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-117-214.ams2.redhat.com [10.36.117.214]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4A59860E3F; Thu, 6 Dec 2018 23:34:37 +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 wB6NYZmL016157; Fri, 7 Dec 2018 00:34:35 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id wB6NYXS9016156; Fri, 7 Dec 2018 00:34:33 +0100 Date: Fri, 7 Dec 2018 00:34:33 +0100 From: Jakub Jelinek To: Richard Biener , Jeff Law Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Disable -fipa-ra for naked functions (PR target/85593) Message-ID: <20181206233433.GB12380@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.2 (2017-12-15) X-IsSubscribed: yes Hi! The only documented supported content of naked functions is basic asm statement(s). Those don't have clobbers though, so we should ignore naked functions for IPA-RA; if they are written the only supported way, they will appear not to clobber any registers at all and IPA-RA will then assume they don't clobber any registers. While naked is a target attribute supported only on a subset of targets, the generic code already handles it in multiple spots, so I think we can add another spot rather than introducing a target hook for it. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2018-12-07 Jakub Jelinek PR target/85593 * final.c (rest_of_handle_final): Don't call collect_fn_hard_reg_usage for functions with naked attribute. * gcc.target/i386/pr85593.c: New test. Jakub --- gcc/final.c.jj 2018-11-21 19:38:50.264064648 +0100 +++ gcc/final.c 2018-12-06 19:01:39.052525201 +0100 @@ -4659,7 +4659,11 @@ rest_of_handle_final (void) final_start_function_1 (&first, asm_out_file, &seen, optimize); final_1 (first, asm_out_file, seen, optimize); if (flag_ipa_ra - && !lookup_attribute ("noipa", DECL_ATTRIBUTES (current_function_decl))) + && !lookup_attribute ("noipa", DECL_ATTRIBUTES (current_function_decl)) + /* Functions with naked attributes are supported only with basic asm + statements in the body, thus for supported use cases the information + on clobbered registers is not available. */ + && !lookup_attribute ("naked", DECL_ATTRIBUTES (current_function_decl))) collect_fn_hard_reg_usage (); final_end_function (); --- gcc/testsuite/gcc.target/i386/pr85593.c.jj 2018-12-06 19:19:17.286362641 +0100 +++ gcc/testsuite/gcc.target/i386/pr85593.c 2018-12-06 19:18:47.188850564 +0100 @@ -0,0 +1,30 @@ +/* PR target/85593 */ +/* { dg-do run { target { { i?86-*-linux* x86_64-*-linux* } && lp64 } } } */ +/* { dg-options "-O2" } */ + +__attribute__((naked)) void +bar (void) +{ + asm ("xorl %eax, %eax\n\t" + "xorl %edx, %edx\n\t" + "xorl %ecx, %ecx\n\t" + "xorl %esi, %esi\n\t" + "xorl %edi, %edi\n\t" + "xorl %r8d, %r8d\n\t" + "xorl %r9d, %r9d\n\t" + "xorl %r10d, %r10d\n\t" + "xorl %r11d, %r11d\n\t" + "ret"); +} + +int +main () +{ + int a = 42; + asm ("" : "+r" (a)); + bar (); + asm ("" : "+r" (a)); + if (a != 42) + __builtin_abort (); + return 0; +}