From patchwork Thu Jul 16 15:25:14 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyrylo Tkachov X-Patchwork-Id: 496742 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 8B9751402A9 for ; Fri, 17 Jul 2015 01:25:42 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=uiAbj1qF; 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 :message-id:date:from:mime-version:to:cc:subject:content-type; q=dns; s=default; b=hPMveuefsV3MbIH3tSFXOF31nGMDKu7aqW0d+TFaw5v nqW4+FocF41NrdU7gaeam+SM31VOajgdZr0cJZZFbZ/z42PFNfjO9cfonbOobyXX t/4GeE5nbTbpSW2TSiqZ1aVoHQFk/ZGWnOgJqINgNAnqwhmnHNe/GPFcLIAC0+0g = 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 :message-id:date:from:mime-version:to:cc:subject:content-type; s=default; bh=h/vncRl1yBIZ1XpALUMjODK3NuY=; b=uiAbj1qFcAsvTMxzp R2MS0jG4fbfKJo15FvDOUTEplcwqGybQ7YVoEpW3uX9mw8AjWk6DalRmAWE6YsqS zJVJee8JKwXqzykGmaFOPypJTjFpgyZds8YzuXym+iENMFd0f9ZQxyTlnc2B7G1T vCKmp5Q106mVr07Maggq0Lgbss= Received: (qmail 64319 invoked by alias); 16 Jul 2015 15:25:29 -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 64214 invoked by uid 89); 16 Jul 2015 15:25:28 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL, BAYES_00, SPF_PASS autolearn=ham version=3.3.2 X-HELO: eu-smtp-delivery-143.mimecast.com Received: from eu-smtp-delivery-143.mimecast.com (HELO eu-smtp-delivery-143.mimecast.com) (207.82.80.143) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 16 Jul 2015 15:25:26 +0000 Received: from cam-owa2.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.140]) by eu-smtp-1.mimecast.com with ESMTP id uk-mta-30-oHwW2aQARdi4EnkbyAFmAg-1; Thu, 16 Jul 2015 16:25:15 +0100 Received: from [10.2.207.50] ([10.1.2.79]) by cam-owa2.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 16 Jul 2015 16:25:14 +0100 Message-ID: <55A7CCDA.8050203@arm.com> Date: Thu, 16 Jul 2015 16:25:14 +0100 From: Kyrill Tkachov User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: GCC Patches CC: Segher Boessenkool , Andrew Pinski Subject: [PATCH][combine][1/2] Try to simplify before substituting X-MC-Unique: oHwW2aQARdi4EnkbyAFmAg-1 X-IsSubscribed: yes Hi all, This is an attempt to solve the problem in the thread starting at https://gcc.gnu.org/ml/gcc-patches/2015-07/msg01010.html in a generic way after some pointers from Segher and Andrew. The problem I got was that combine_simplify_rtx was trying to do some special handling of unary operations applied to if_then_else but ended up exiting early due to: enum rtx_code cond_code = simplify_comparison (NE, &cond, &cop1); if (cond_code == NE && COMPARISON_P (cond)) return x; I tried removing that bug that led to regressions in SPEC2006. The solution that worked for me led to two patches. In this first patch we add a simplification step to the rtx before trying any substitutions. In the second patch I add the simplify-rtx.c simplification to transform - (y ? -x : x) into (!y ? -x : x) which fixes the testcase I mentioned in the first thread. This first patch by itself already showed to be an improvement for aarch64 with by managing to eliminate a large amount of redundant zero_extend operations in SPEC2006. Overall, I saw a 2.8% decrease in [su]xt[bhw] instructions generated for the whole of SPEC2006 and no regressions in code quality i.e. no instructions that were combined before but not combine with this patch. Bootstrapped and tested on arm, aarch64 and x86_64. Ok for trunk? Thanks, Kyrill 2015-07-16 Kyrylo Tkachov * combine.c (combine_simplify_rtx): Try to simplify if_then_else rtxes before trying substitutions. commit 685bc1a66a36292329f678bae555e9c43e434e5d Author: Kyrylo Tkachov Date: Thu Jul 9 16:54:23 2015 +0100 [combine] Try to simplify before substituting diff --git a/gcc/combine.c b/gcc/combine.c index 574f874..40d2231 100644 --- a/gcc/combine.c +++ b/gcc/combine.c @@ -5510,6 +5510,17 @@ combine_simplify_rtx (rtx x, machine_mode op0_mode, int in_dest, { rtx cond, true_rtx, false_rtx; + /* If some simplification is possible from the start, try it now. */ + temp = simplify_rtx (x); + + if (temp) + { + x = temp; + code = GET_CODE (x); + mode = GET_MODE (x); + op0_mode = VOIDmode; + } + cond = if_then_else_cond (x, &true_rtx, &false_rtx); if (cond != 0 /* If everything is a comparison, what we have is highly unlikely