From patchwork Tue Dec 1 06:00:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Kleen X-Patchwork-Id: 7733051 Return-Path: X-Original-To: patchwork-linux-kbuild@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 5C7F4BEEE1 for ; Tue, 1 Dec 2015 06:04:33 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CA6E8206C5 for ; Tue, 1 Dec 2015 06:04:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 72636206BD for ; Tue, 1 Dec 2015 06:04:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750876AbbLAGDl (ORCPT ); Tue, 1 Dec 2015 01:03:41 -0500 Received: from one.firstfloor.org ([193.170.194.197]:41253 "EHLO one.firstfloor.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750741AbbLAGDk (ORCPT ); Tue, 1 Dec 2015 01:03:40 -0500 Received: from basil.firstfloor.org (174-25-119-104.ptld.qwest.net [174.25.119.104]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by one.firstfloor.org (Postfix) with ESMTPSA id 84F8086F3C; Tue, 1 Dec 2015 07:03:37 +0100 (CET) Received: by basil.firstfloor.org (Postfix, from userid 1000) id F1C84A07CC; Mon, 30 Nov 2015 22:00:49 -0800 (PST) From: Andi Kleen To: mmarek@suse.com Cc: torvalds@linux-foundation.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, linux-kbuild@vger.kernel.org, Andi Kleen Subject: [PATCH] Kbuild: Enable interprocedural register allocation for gcc 5 Date: Mon, 30 Nov 2015 22:00:43 -0800 Message-Id: <1448949643-6059-1-git-send-email-andi@firstfloor.org> X-Mailer: git-send-email 2.6.3 Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Andi Kleen gcc 5 has a new -fipa-ra option that enables limited interprocedural register allocation. When it generates a function it remembers what registers it clobbered. Later when the function is called it only saves registers that are actually clobbered by the function. This only really works when caller and callee are in the same compilation unit (except with LTO) In principle this violates the ABI which specifies which registers are saved and which are clobbered on a call. However there shouldn't be anything else relying on this: while we have multiple subsystems that patch binaries (like ftrace, kprobes) they all cannot know which registers are used as arguments, so always need to save/restore all registers. Similarly gdb and other debuggers cannot rely on the ABI either. It has some risk that it breaks something obscure, but so far I haven't seen or found anything. On my system with gcc 5.2 it saves about 40k in binary size text data bss dec hex filename 9583446 2178288 1675264 13436998 cd0846 vmlinux-base 9542180 2178096 1675264 13395540 cc6654 vmlinux-ipara -0.4% pretty much all in missing spill code. So it's not a dramatic win, but still a nice improvement. Open: for now I enabled it for all architectures, although it's only tested on x86-64. It may be safer to move it to be x86 specific or guard with an CONFIG option, until more testing can be done. Signed-off-by: Andi Kleen --- Makefile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Makefile b/Makefile index 2ffdf9d..c95320f 100644 --- a/Makefile +++ b/Makefile @@ -626,6 +626,12 @@ KBUILD_CFLAGS += $(call cc-option,-fno-reorder-blocks,) \ $(call cc-option,-fno-partial-inlining) endif +# Ask gcc to use interprocedural register allocation when possible. +# This allows it to violate the callee-saved register ABI and avoid +# generating register spills in the caller when it knows the function does +# not clobber these registers +KBUILD_CFLAGS += $(call cc-option,-fipa-ra,) + ifneq ($(CONFIG_FRAME_WARN),0) KBUILD_CFLAGS += $(call cc-option,-Wframe-larger-than=${CONFIG_FRAME_WARN}) endif