From patchwork Thu Aug 14 04:50:48 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhenqiang Chen X-Patchwork-Id: 379805 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 AE6FD14008F for ; Thu, 14 Aug 2014 14:51:05 +1000 (EST) 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:date:message-id:subject:from:to:cc:content-type; q=dns; s=default; b=IUFOHtUzoYuH9xQQY2llm2GSFxEKHZSYZ4+KcYMOMBC PgWASgF5uKktoDgjBK6d9Q1Hxn8yP5sb+SvzJGn+FwhH8a5NVSxG0kPMVefj+Lp6 Cw3t8u4vCP3OAQPdIrrYDjSVknzyERwvoKurzGVYxi38DIZrPngE6CcrUjQugE84 = 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:date:message-id:subject:from:to:cc:content-type; s=default; bh=9bvTmIN1IoiclG3fLcukwO/hOO0=; b=W89ot5ICwQAjRHcb8 NNSHplYDMvccKElvbefftmxOEOsB9jmFxLzXK7IQ7SdDhIh8VgZOsZF0YvyQtcUV EG1mfyjEBicOwCvAFTQ/RB8QTkDIOKNo6cf1PLLKx4SayQoRCSJYjXzUtVWQV4HY UUuQp7LHAeuCza+DK4Mopd7AK0= Received: (qmail 29306 invoked by alias); 14 Aug 2014 04:50:57 -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 29163 invoked by uid 89); 14 Aug 2014 04:50:55 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-la0-f43.google.com Received: from mail-la0-f43.google.com (HELO mail-la0-f43.google.com) (209.85.215.43) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Thu, 14 Aug 2014 04:50:52 +0000 Received: by mail-la0-f43.google.com with SMTP id hr17so549842lab.2 for ; Wed, 13 Aug 2014 21:50:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to:cc :content-type; bh=YZcUHZnlZJizwWPboPTz7vMt9wzSkRBkI94mRZYbs1w=; b=ddBUejqImWeZ9ZGwmH/B1YJ1AtYYLGKsYx1rGxuT9ls/wY/pi0oK3PvnzRny5XQxk1 YgGW1uQ1Rl+iXUE8u+m9eVwigwXtrX9si0ESf4c43ViMYwMViMYv62/MLgU4zUXlcBfa XmiTV2GZXKlloDbj9zZMcDNLK0bAL0zzgQmb96oGPGgb8ZajB4De8/XcV0QX59l+7Clv Tp3c1XQ+ClOFfYYenHREgLbJw8U2oIa66+GwrF5C4xOuDh98uA+J5XczwPUGiv+/dpeV w2PAzOKynsGG9o2YFQUc0jmSecfad0CKcyraK5ynVrTeYfTqTzpJgBQcR0VNfXU25xDn 5cKg== X-Gm-Message-State: ALoCoQkLK4NDzZsldVudH/3IHOodSEGcieL7dxcQJzXeDeY146omcb4SRhQVsAEqyg6g5nMc1OmZ MIME-Version: 1.0 X-Received: by 10.112.30.39 with SMTP id p7mr2020141lbh.35.1407991848504; Wed, 13 Aug 2014 21:50:48 -0700 (PDT) Received: by 10.112.140.169 with HTTP; Wed, 13 Aug 2014 21:50:48 -0700 (PDT) Date: Thu, 14 Aug 2014 12:50:48 +0800 Message-ID: Subject: [Committed] [PATCH, ARM] Set max_insns_skipped to MAX_INSN_PER_IT_BLOCK when optimize_size for THUMB2 From: Zhenqiang Chen To: Richard Earnshaw Cc: Zhenqiang Chen , "gcc-patches@gcc.gnu.org" , Ramana Radhakrishnan On 13 August 2014 20:29, Richard Earnshaw wrote: > On 25/02/14 09:34, Zhenqiang Chen wrote: >> Hi, >> >> Current value for max_insns_skipped is 6. For THUMB2, it needs 2 (IF-THEN) >> or 3 (IF-THEN-ELSE) IT blocks to hold all the instructions. The overhead of >> IT is 4 or 6 BYTES. >> >> If we do not generate IT blocks, for IF-THEN, the overhead of conditional >> jump is 2 or 4; for IF-THEN-ELSE, the overhead is 4, 6, or 8. >> >> Most THUMB2 jump instructions are 2 BYTES. Tests on CSiBE show no one file >> has code size regression. So The patch sets max_insns_skipped to >> MAX_INSN_PER_IT_BLOCK. >> >> No make check regression on cortex-m3. >> For CSiBE, no any file has code size regression. And overall there is >0.01% >> code size improvement for cortex-a9 and cortex-m4. >> >> Is it OK? >> >> Thanks! >> -Zhenqiang >> >> 2014-02-25 Zhenqiang Chen >> >> * config/arm/arm.c (arm_option_override): Set max_insns_skipped >> to MAX_INSN_PER_IT_BLOCK when optimize_size for THUMB2. >> >> testsuite/ChangeLog: >> 2014-02-25 Zhenqiang Chen >> >> * gcc.target/arm/max-insns-skipped.c: New test. >> >> diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c >> index b49f43e..99cdbc4 100644 >> --- a/gcc/config/arm/arm.c >> +++ b/gcc/config/arm/arm.c >> @@ -2743,6 +2743,15 @@ arm_option_override (void) >> /* If optimizing for size, bump the number of instructions that we >> are prepared to conditionally execute (even on a StrongARM). */ >> max_insns_skipped = 6; >> + >> + /* For THUMB2, it needs 2 (IF-THEN) or 3 (IF-THEN-ELSE) IT blocks to >> + hold all the instructions. The overhead of IT is 4 or 6 BYTES. >> + If we do not generate IT blocks, for IF-THEN, the overhead of >> + conditional jump is 2 or 4; for IF-THEN-ELSE, the overhead is 4, 6 >> + or 8. Most THUMB2 jump instructions are 2 BYTES. >> + So set max_insns_skipped to MAX_INSN_PER_IT_BLOCK. */ >> + if (TARGET_THUMB2) >> + max_insns_skipped = MAX_INSN_PER_IT_BLOCK; > > Replacing a single 2-byte branch with a 2-byte IT insn doesn't save any > space in itself. > > Pedantically, we save space with IT blocks if either: > a) we can replace an else clause (saving a branch around that) > b) we can use non-flag setting versions of insns to replace what would > otherwise be 4-byte insns with 2-byte versions. > > I agree that multiple IT instructions is probably not a win (the > cond-exec code doesn't know how to reason about the finer points of item > b) and doesn't even really consider a) either). > > So this is OK, but I think the comment should be simplified. Just say, > for thumb2 we limit the conditional sequence to one IT block. > > OK with that change. Thanks! Commit the patch with the comment change @r213939. ChangeLog: 2014-08-14 Zhenqiang Chen * config/arm/arm.c (arm_option_override): Set max_insns_skipped to MAX_INSN_PER_IT_BLOCK when optimize_size for THUMB2. testsuite/ChangeLog: 2014-08-14 Zhenqiang Chen * gcc.target/arm/max-insns-skipped.c: New test. > >> } >> else >> max_insns_skipped = current_tune->max_insns_skipped; >> diff --git a/gcc/testsuite/gcc.target/arm/max-insns-skipped.c >> b/gcc/testsuite/gcc.target/arm/max-insns-skipped.c >> new file mode 100644 >> index 0000000..0a11554 >> --- /dev/null >> +++ b/gcc/testsuite/gcc.target/arm/max-insns-skipped.c >> @@ -0,0 +1,21 @@ >> +/* { dg-do assemble { target arm_thumb2 } } */ >> +/* { dg-options " -Os " } */ >> + >> +int t (int a, int b, int c, int d) >> +{ >> + int r; >> + if (a > 0) { >> + r = a + b; >> + r += 0x456; >> + r *= 0x1234567; >> + } >> + else { >> + r = b - a; >> + r -= 0x123; >> + r *= 0x12387; >> + r += d; >> + } >> + return r; >> +} >> + >> +/* { dg-final { object-size text <= 40 } } */ >> >> >> >> > > diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c index 7f62ca4..2f8d327 100644 --- a/gcc/config/arm/arm.c +++ b/gcc/config/arm/arm.c @@ -2989,6 +2989,10 @@ arm_option_override (void) /* If optimizing for size, bump the number of instructions that we are prepared to conditionally execute (even on a StrongARM). */ max_insns_skipped = 6; + + /* For THUMB2, we limit the conditional sequence to one IT block. */ + if (TARGET_THUMB2) + max_insns_skipped = MAX_INSN_PER_IT_BLOCK; } else max_insns_skipped = current_tune->max_insns_skipped; diff --git a/gcc/testsuite/gcc.target/arm/max-insns-skipped.c b/gcc/testsuite/gcc.target/arm/max-insns-skipped.c new file mode 100644 index 0000000..0a11554 --- /dev/null +++ b/gcc/testsuite/gcc.target/arm/max-insns-skipped.c @@ -0,0 +1,21 @@ +/* { dg-do assemble { target arm_thumb2 } } */ +/* { dg-options " -Os " } */ + +int t (int a, int b, int c, int d) +{ + int r; + if (a > 0) { + r = a + b; + r += 0x456; + r *= 0x1234567; + } + else { + r = b - a; + r -= 0x123; + r *= 0x12387; + r += d; + } + return r; +} + +/* { dg-final { object-size text <= 40 } } */