From patchwork Mon Mar 21 01:39:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 599936 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 3qSz642vDdz9s5M for ; Mon, 21 Mar 2016 12:39:56 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=g6efslLO; 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:subject:message-id:references:mime-version:content-type :in-reply-to; q=dns; s=default; b=R8divEg07tC9m/oPETkU851eFSit+7 qZe7jMCHBJwnxNHCy4zZNAAvCbKU0akZuZbxIqFugK/+S2Ez8tuzwWl2hal/HfP0 cAxaP57vKhY03VV+I9AC5ONHQJMQ31V58z/CHYzG2PsTEwF/mDTiNSn0NL7ddpt7 6FmcVMFhUH9DQ= 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:subject:message-id:references:mime-version:content-type :in-reply-to; s=default; bh=BVOwSouHIDuc6lKhgXFNUPEt588=; b=g6ef slLOEFDdQkvLkM4TxURoaKOYG3jBgK6T8yoNDvAUELa9UsqzbXtJt10oLBkbeqF3 0Yn8tRzJ0ccrvgSbduYsfhpt+3ULyqADEef9CBnnSFUHG1UI7CNl2wVXdMJ/oOPf /7TGLvSF5g/XX0yQwK/Etm9uSOG7cSWPNNKxN2c= Received: (qmail 64409 invoked by alias); 21 Mar 2016 01:39:45 -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 64329 invoked by uid 89); 21 Mar 2016 01:39:40 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=Clean, puts, H*MI:sk:2016032, Scan X-HELO: mail-pf0-f194.google.com Received: from mail-pf0-f194.google.com (HELO mail-pf0-f194.google.com) (209.85.192.194) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Mon, 21 Mar 2016 01:39:39 +0000 Received: by mail-pf0-f194.google.com with SMTP id q129so27947937pfb.3 for ; Sun, 20 Mar 2016 18:39:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=bbT/BBh9dGGyl2yc+0ATN9UIAwXW/gy+IjdnaEcCPtg=; b=gZkiwvLEa4eEwDW2Aa5UBLeC5C56vE49c+V7ldgMr8W1z+XPOn/QYHIMFwPJ5XUfdu csoRluvEz5fV2cao5tH72kb8rJMi18KgFL4QuZjBfKcbgT5idJfxugGzCTdeAeSHQG0o KMwD9G2qsz5S7me8Nq5Jr+cQsnPlY8M8IHp8HZOr5Vmhb3A/CAbat1DpuISpI41EddUi 13qMiWVP5CW+HpkKIpxtAC6BrTiX/50sGtDeNN5/xpXUhBwfdPja+hKHPfisGgMgGPS0 omRKohJJ6LgUcaPkrn4rtbBgbYVR/Ia9iUlZMufnfHzNcTJs5fq6J6XwMI/MGpTd2hDC +fXQ== X-Gm-Message-State: AD7BkJKCwmW4A7U1qhsmF+xybcY7ZnwoRHMneACaLKQPK9BLyKwiRzWL9RC00ALLH9ZJYA== X-Received: by 10.98.93.205 with SMTP id n74mr41297320pfj.99.1458524377188; Sun, 20 Mar 2016 18:39:37 -0700 (PDT) Received: from bubble.grove.modra.org (CPE-58-160-146-233.sa.bigpond.net.au. [58.160.146.233]) by smtp.gmail.com with ESMTPSA id qy7sm35977212pab.34.2016.03.20.18.39.36 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 20 Mar 2016 18:39:36 -0700 (PDT) Received: by bubble.grove.modra.org (Postfix, from userid 1000) id 38E44EA0153; Mon, 21 Mar 2016 12:09:33 +1030 (ACDT) Date: Mon, 21 Mar 2016 12:09:33 +1030 From: Alan Modra To: gcc-patches@gcc.gnu.org Subject: [PATCH 2/7] ira.c tidies: split update_reg_equivs Message-ID: <20160321013933.GE22605@bubble.grove.modra.org> References: <20160321013723.GC22605@bubble.grove.modra.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20160321013723.GC22605@bubble.grove.modra.org> User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes This just splits up add_store_equivs. * ira.c (add_store_equivs, combine_and_move_insns): New functions, split out from.. (update_reg_equivs): ..here. Move allocation and freeing of reg_equiv, and calls to grow_reg_equivs, init_alias_analysis, end_alias_analysis to.. (ira): ..here. diff --git a/gcc/ira.c b/gcc/ira.c index f3e9e86..abd78ff 100644 --- a/gcc/ira.c +++ b/gcc/ira.c @@ -3343,13 +3343,6 @@ update_equiv_regs (void) rtx_insn *insn; basic_block bb; int loop_depth; - bitmap cleared_regs; - bitmap_head seen_insns; - - reg_equiv = XCNEWVEC (struct equivalence, max_regno); - grow_reg_equivs (); - - init_alias_analysis (); /* Scan insns and set pdx_subregs if the reg is used in a paradoxical subreg. Don't set such reg equivalent to a mem, @@ -3604,18 +3597,24 @@ update_equiv_regs (void) } } } +} - if (!optimize) - goto out; - - /* A second pass, to gather additional equivalences with memory. This needs - to be done after we know which registers we are going to replace. */ +/* For insns that set a MEM to the contents of a REG that is only used + in a single basic block, see if the register is always equivalent + to that memory location and if moving the store from INSN to the + insn that sets REG is safe. If so, put a REG_EQUIV note on the + initializing insn. */ +static void +add_store_equivs (void) +{ + bitmap_head seen_insns; bitmap_initialize (&seen_insns, NULL); - for (insn = get_insns (); insn; insn = NEXT_INSN (insn)) + for (rtx_insn *insn = get_insns (); insn; insn = NEXT_INSN (insn)) { rtx set, src, dest; unsigned regno; + rtx_insn *init_insn; bitmap_set_bit (&seen_insns, INSN_UID (insn)); @@ -3629,66 +3628,60 @@ update_equiv_regs (void) dest = SET_DEST (set); src = SET_SRC (set); - /* If this sets a MEM to the contents of a REG that is only used - in a single basic block, see if the register is always equivalent - to that memory location and if moving the store from INSN to the - insn that set REG is safe. If so, put a REG_EQUIV note on the - initializing insn. - - Don't add a REG_EQUIV note if the insn already has one. The existing + /* Don't add a REG_EQUIV note if the insn already has one. The existing REG_EQUIV is likely more useful than the one we are adding. If one of the regs in the address has reg_equiv[REGNO].replace set, then we can't add this REG_EQUIV note. The reg_equiv[REGNO].replace optimization may move the set of this register immediately before - insn, which puts it after reg_equiv[REGNO].init_insns, and hence - the mention in the REG_EQUIV note would be to an uninitialized - pseudo. */ - + insn, which puts it after reg_equiv[REGNO].init_insns, and hence the + mention in the REG_EQUIV note would be to an uninitialized pseudo. */ if (MEM_P (dest) && REG_P (src) && (regno = REGNO (src)) >= FIRST_PSEUDO_REGISTER && REG_BASIC_BLOCK (regno) >= NUM_FIXED_BLOCKS && DF_REG_DEF_COUNT (regno) == 1 && ! reg_equiv[regno].pdx_subregs && reg_equiv[regno].init_insns != NULL - && reg_equiv[regno].init_insns->insn () != NULL - && ! find_reg_note (XEXP (reg_equiv[regno].init_insns, 0), - REG_EQUIV, NULL_RTX) - && ! contains_replace_regs (XEXP (dest, 0))) + && (init_insn = reg_equiv[regno].init_insns->insn ()) != 0 + && bitmap_bit_p (&seen_insns, INSN_UID (init_insn)) + && ! find_reg_note (init_insn, REG_EQUIV, NULL_RTX) + && ! contains_replace_regs (XEXP (dest, 0)) + && validate_equiv_mem (init_insn, src, dest) + && ! memref_used_between_p (dest, init_insn, insn) + /* Attaching a REG_EQUIV note will fail if INIT_INSN has + multiple sets. */ + && set_unique_reg_note (init_insn, REG_EQUIV, copy_rtx (dest))) { - rtx_insn *init_insn = - as_a (XEXP (reg_equiv[regno].init_insns, 0)); - if (validate_equiv_mem (init_insn, src, dest) - && bitmap_bit_p (&seen_insns, INSN_UID (init_insn)) - && ! memref_used_between_p (dest, init_insn, insn) - /* Attaching a REG_EQUIV note will fail if INIT_INSN has - multiple sets. */ - && set_unique_reg_note (init_insn, REG_EQUIV, copy_rtx (dest))) - { - /* This insn makes the equivalence, not the one initializing - the register. */ - ira_reg_equiv[regno].init_insns - = gen_rtx_INSN_LIST (VOIDmode, insn, NULL_RTX); - df_notes_rescan (init_insn); - if (dump_file) - fprintf (dump_file, - "Adding REG_EQUIV to insn %d for source of insn %d\n", - INSN_UID (init_insn), - INSN_UID (insn)); - } + /* This insn makes the equivalence, not the one initializing + the register. */ + ira_reg_equiv[regno].init_insns + = gen_rtx_INSN_LIST (VOIDmode, insn, NULL_RTX); + df_notes_rescan (init_insn); + if (dump_file) + fprintf (dump_file, + "Adding REG_EQUIV to insn %d for source of insn %d\n", + INSN_UID (init_insn), + INSN_UID (insn)); } } bitmap_clear (&seen_insns); +} + +/* Scan all regs killed in an insn to see if any of them are registers + only used that once. If so, see if we can replace the reference + with the equivalent form. If we can, delete the initializing + reference and this register will go away. If we can't replace the + reference, and the initializing reference is within the same loop + (or in an inner loop), then move the register initialization just + before the use, so that they are in the same basic block. */ +static void +combine_and_move_insns (void) +{ + rtx_insn *insn; + basic_block bb; + int loop_depth; + bitmap cleared_regs = BITMAP_ALLOC (NULL); - cleared_regs = BITMAP_ALLOC (NULL); - /* Now scan all regs killed in an insn to see if any of them are - registers only used that once. If so, see if we can replace the - reference with the equivalent form. If we can, delete the - initializing reference and this register will go away. If we - can't replace the reference, and the initializing reference is - within the same loop (or in an inner loop), then move the register - initialization just before the use, so that they are in the same - basic block. */ FOR_EACH_BB_REVERSE_FN (bb, cfun) { loop_depth = bb_loop_depth (bb); @@ -3848,12 +3841,6 @@ update_equiv_regs (void) } BITMAP_FREE (cleared_regs); - - out: - /* Clean up. */ - - end_alias_analysis (); - free (reg_equiv); } /* A pass over indirect jumps, converting simple cases to direct jumps. @@ -5230,7 +5217,19 @@ ira (FILE *f) if (resize_reg_info () && flag_ira_loop_pressure) ira_set_pseudo_classes (true, ira_dump_file); + reg_equiv = XCNEWVEC (struct equivalence, max_regno); + grow_reg_equivs (); + init_alias_analysis (); update_equiv_regs (); + if (optimize) + { + /* Gather additional equivalences with memory. */ + add_store_equivs (); + combine_and_move_insns (); + } + end_alias_analysis (); + free (reg_equiv); + setup_reg_equiv (); setup_reg_equiv_init ();