From patchwork Mon Nov 14 03:45:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Maciej W. Rozycki" X-Patchwork-Id: 694354 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 3tHGdT6YKkz9sCg for ; Mon, 14 Nov 2016 14:45:49 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="Yt0AjLCt"; dkim-atps=neutral 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:in-reply-to:message-id:references :mime-version:content-type; q=dns; s=default; b=SMt2aSnoAZicMLxJ wlJRSIeB5qwxSrWfUCcRl0jtNiLAm97CaR894OxynO5u0IfqoT0XM+aDQ6OPyU0M tS3IK2qhmOmA9do8wCteQehn0Q4Bn0x5667ZoUevJreX1fKBPVvZX2OUB/S5mgm6 FYvZnrxuo94H/IoDEhov5mmXvaw= 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:in-reply-to:message-id:references :mime-version:content-type; s=default; bh=PPwU9Tnbw6eCoilhtyCAMw /xCxM=; b=Yt0AjLCtB4JLY0/6OF55Xfz01xL5qWWKpB2i8+IlfSHTjAguRJ3uHb R5sivKBGbAS66IJPtJvknTBymCpdV9ZuvTCjtT2Z09RcHeFO1g8kWIhdfjl3rZds dDhYk18oHyLJ3GBQg6653wn67WUaamZc63THRyDI9nmbt0ovVD3sY= Received: (qmail 78018 invoked by alias); 14 Nov 2016 03:45: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 77987 invoked by uid 89); 14 Nov 2016 03:45:38 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.5 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy=halfword, Hx-languages-length:2918, distance X-HELO: mailapp01.imgtec.com Received: from mailapp01.imgtec.com (HELO mailapp01.imgtec.com) (195.59.15.196) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 14 Nov 2016 03:45:28 +0000 Received: from HHMAIL01.hh.imgtec.org (unknown [10.100.10.19]) by Forcepoint Email with ESMTPS id 4718768330D82; Mon, 14 Nov 2016 03:45:24 +0000 (GMT) Received: from [10.20.78.88] (10.20.78.88) by HHMAIL01.hh.imgtec.org (10.100.10.21) with Microsoft SMTP Server id 14.3.294.0; Mon, 14 Nov 2016 03:45:24 +0000 Date: Mon, 14 Nov 2016 03:45:15 +0000 From: "Maciej W. Rozycki" To: CC: Catherine Moore , Matthew Fortune Subject: [PATCH 3/4] MIPS16/GCC: Improve `casesi_internal_mips16_'s instruction count estimate In-Reply-To: Message-ID: References: User-Agent: Alpine 2.20.17 (DEB 179 2016-10-28) MIME-Version: 1.0 A typical code sequence produced by the `casesi_internal_mips16_' insn is like this: sltu $3, 11 # 16 casesi_internal_mips16_si [length = 32] bteqz $L2 sll $5, $3, 1 la $3, $L4 addu $5, $3, $5 lh $5, 0($5) addu $3, $3, $5 j $3 .align 1 .align 2 .type __jump_foo_4, @object __jump_foo_4: $L4: which in turn assembles to this binary code: a: 5b0b sltiu v1,11 c: 601d bteqz 48 <__pool_foo_12> e: 3564 sll a1,v1,1 10: 0b03 la v1,1c <__jump_foo_4> 12: e3b5 addu a1,v1,a1 14: 8da0 lh a1,0(a1) 16: e3ad addu v1,a1 18: eb80 jrc v1 1a: 6500 nop 0000001c <__jump_foo_4>: As you can see the code length estimate is 32, which in turn comes from the instruction count being set to 16 for the insn, telling the compiler that the pattern will produce the equivalent of 16 regular (16-bit or unextended) MIPS16 instructions, as per the attribute's definition. This estimate is too pessimistic as this pattern will never actually reach so many instructions. Taking the instructions produced one by one we have: 1. sltu $3, 11 => 1 or 2 depending on the immediate => 2 2. bteqz $L2 => 1 or 2 depending on label distance => 2 3. sll $5, $3, 1 => (HImode) fixed 1 sll $5, $3, 2 => (SImode) fixed 1 => 1 4. la $3, $L4 => (Pmode == SImode) fixed 1 as $L4 is close and word-aligned dla $3, $L4 => (Pmode == DImode) fixed 1 as $L4 is close and word-aligned => 1 5. addu $5, $3, $5 => (Pmode == SImode) fixed 1 daddu $5, $3, $5 => (Pmode == DImode) fixed 1 => 1 6. lh $5, 0($5) => (HImode) fixed 1 lw $5, 0($5) => (SImode) fixed 1 => 1 7. addu $3, $3, $5 => (Pmode == SImode) fixed 1 daddu $3, $3, $5 => (Pmode == SImode) fixed 1 => 1 8. j $3 => 1 if JRC is used or 2 if JR/NOP is => 2 ---- 11 Word alignment of the jump table start is explicitly arranged by ASM_OUTPUT_BEFORE_CASE_LABEL and is beneficial as we can use the short encoding of LH at no loss in code size, because any 2-byte padding produced by the `.align 2' pseudo-op would otherwise be consumed by the extended form of LH required to encode a PC-relative offset which is not a multiple of 4, possibly at some performance loss required for the extra instruction halfword fetch. Set the instruction count to 11 then. gcc/ * config/mips/mips.md (casesi_internal_mips16_): Set `insn_count' to 11 rather than 16. --- OK to apply? Maciej gcc-mips16-casesi-insn-count.diff Index: gcc/gcc/config/mips/mips.md =================================================================== --- gcc.orig/gcc/config/mips/mips.md 2016-11-12 10:57:12.544746018 +0000 +++ gcc/gcc/config/mips/mips.md 2016-11-12 10:57:13.972699749 +0000 @@ -6444,7 +6444,7 @@ return "j\t%4"; } - [(set_attr "insn_count" "16")]) + [(set_attr "insn_count" "11")]) ;; For TARGET_USE_GOT, we save the gp in the jmp_buf as well. ;; While it is possible to either pull it off the stack (in the