From patchwork Wed Oct 1 22:36:27 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Segher Boessenkool X-Patchwork-Id: 395700 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 C8DC414016A for ; Thu, 2 Oct 2014 08:36:43 +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:date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=ZqbyrYaiyew8xay3q ZaEobCCZLQfsym9SVDWR2Rl8tje/LFtwPvL754XawmV3I/KWHPDdv2/xWT3Y6CmA q4ctZPVJneKK0lhgzcR+qzkBpHiIPcXitGf8PFRKygFsroTyI1NP4tY6Ll0Sp35h 9GBC1mUlQ+GLVQ7Gxc6q4obEU0= 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:references:mime-version :content-type:in-reply-to; s=default; bh=tZvi6iWU4oEYhe57Lf+WB7h mwHI=; b=E4JpzzrRhu9Dyw6FL466ebxLMD6AuRuJmUAG0tef8OpngGHST4YnYXF ALVgI9Y10DIrH58POvhoV1T4X6PqXaKi+lreW6DzrLCjcUt+LsOCNwN/fo9jlwSw VaVjT/nCU4rKHadT0wtRMcwj2SPlLhsOh4pcvqNTm7ND8dSLqMC8= Received: (qmail 32214 invoked by alias); 1 Oct 2014 22:36:37 -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 32203 invoked by uid 89); 1 Oct 2014 22:36:36 -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, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-HELO: gate.crashing.org Received: from gate.crashing.org (HELO gate.crashing.org) (63.228.1.57) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Wed, 01 Oct 2014 22:36:32 +0000 Received: from gate.crashing.org (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.13.8) with ESMTP id s91MaSFk005767; Wed, 1 Oct 2014 17:36:28 -0500 Received: (from segher@localhost) by gate.crashing.org (8.14.1/8.14.1/Submit) id s91MaRXF005766; Wed, 1 Oct 2014 17:36:27 -0500 Date: Wed, 1 Oct 2014 17:36:27 -0500 From: Segher Boessenkool To: Jeff Law Cc: gcc-patches@gcc.gnu.org Subject: Re: [PATCH] combine: Allow substituting the target reg of a clobber Message-ID: <20141001223627.GA32352@gate.crashing.org> References: <8137af77d6faef78001c49d0196e475ceafc5aba.1409750557.git.segher@kernel.crashing.org> <5420A09C.9080708@redhat.com> <20140927220326.GA25296@gate.crashing.org> Mime-Version: 1.0 Content-Disposition: inline In-Reply-To: <20140927220326.GA25296@gate.crashing.org> User-Agent: Mutt/1.4.2.3i X-IsSubscribed: yes On Sat, Sep 27, 2014 at 05:03:26PM -0500, Segher Boessenkool wrote: > I've tried to make a stable future-proof testcase that does such a three-insn > combination. Not easy at all. Turns out it is quite easy (when you've seen the solution, anyway :-P ) Tested on powerpc64-linux as before, and bootstrapped + regression checked on x86_64-linux. Also checked the testcase fails before on i386 and x86_64, and works afterwards. Does this look good? Segher 2014-10-02 Segher Boessenkool gcc/ PR rtl-optimization/62151 * combine.c (can_combine_p): Allow the destination register of INSN to be clobbered in I3. (subst): Do not substitute into clobbers of registers. gcc/testsuite/ * gcc.dg/combine-clobber.c: New. diff --git a/gcc/combine.c b/gcc/combine.c index 1457eab..ff5f0db 100644 --- a/gcc/combine.c +++ b/gcc/combine.c @@ -1950,11 +1950,7 @@ can_combine_p (rtx_insn *insn, rtx_insn *i3, rtx_insn *pred ATTRIBUTE_UNUSED, for (i = XVECLEN (PATTERN (i3), 0) - 1; i >= 0; i--) if (GET_CODE (XVECEXP (PATTERN (i3), 0, i)) == CLOBBER) { - /* Don't substitute for a register intended as a clobberable - operand. */ rtx reg = XEXP (XVECEXP (PATTERN (i3), 0, i), 0); - if (rtx_equal_p (reg, dest)) - return 0; /* If the clobber represents an earlyclobber operand, we must not substitute an expression containing the clobbered register. @@ -4963,6 +4959,11 @@ subst (rtx x, rtx from, rtx to, int in_dest, int in_cond, int unique_copy) || (REG_P (X) && REG_P (Y) \ && REGNO (X) == REGNO (Y) && GET_MODE (X) == GET_MODE (Y))) + /* Do not substitute into clobbers of regs -- this will never result in + valid RTL. */ + if (GET_CODE (x) == CLOBBER && REG_P (XEXP (x, 0))) + return x; + if (! in_dest && COMBINE_RTX_EQUAL_P (x, from)) { n_occurrences++; diff --git a/gcc/testsuite/gcc.dg/combine-clobber.c b/gcc/testsuite/gcc.dg/combine-clobber.c new file mode 100644 index 0000000..bf0d88c --- /dev/null +++ b/gcc/testsuite/gcc.dg/combine-clobber.c @@ -0,0 +1,22 @@ +/* { dg-do compile { target i?86-*-* x86_64-*-* } } */ +/* { dg-options "-O2 -fdump-rtl-combine-all" } */ + +/* This testcase checks if combine tries to combine sequences where the last + insn has a clobber of a reg, and a previous insn sets that reg. + + In this case, we have three insns + + (set flags (compare a b)) + (set tmp (eq flags 0)) + (parallel [(set dst (neg tmp)) + (clobber flags)]) + + Previously, combine would not try the three-insn combination because of + the set and clobber of flags. Now it does. Test that. */ + + +int f(int a, int b) { return -(a == b); } + +/* This regexp works for reg parameters as well as mem parameters. */ +/* { dg-final { scan-rtl-dump {neg:SI[^:]*eq:SI[^:]*:SI} "combine" } } */ +/* { dg-final { cleanup-rtl-dump "combine" } } */