From patchwork Thu Apr 28 12:29:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 616194 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 3qwbks02Hzz9s4q for ; Thu, 28 Apr 2016 22:30:11 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=NRUpg3F/; 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:mime-version:content-type; q=dns; s= default; b=gHpHzH+w4nxLSP6OuPMBXafhaRehBr633ZS+XSE2RHxZiPxmD7ewL gqZuKXjTUl+ALaTIk8oTwvMRDjEr4qqyRlI4r7qexj/8G87UBHWLDtF6m0dCOPq2 TOY75So1zjZEwXMSLhac4Z8vZ+VyTLDuYeEI5Uly3L9mLDVEs0sxuc= 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:mime-version:content-type; s= default; bh=2ClftKwOsLrb0vcxnRdtB3R1zUA=; b=NRUpg3F/1B5OtL3uI4j6 +FJQGBqRzkz4nLxtgI//UjtLxCifiWjtOekv3Dhv8jmvDCBjxxx9HNo2o9dUmWI/ qal6hAJ89nra01sZU7gXmCn9V+O8t0lnIRoeS4+0MTIAbDB4d3Ckl2WXJ3+GxAvA u7JVYKnRccxb0u5GM/yJIPk= Received: (qmail 4072 invoked by alias); 28 Apr 2016 12:29:59 -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 2599 invoked by uid 89); 28 Apr 2016 12:29:57 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.2 required=5.0 tests=BAYES_50, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy=RINT, TREE_OVERFLOW, tree_overflow, integer_cst1 X-HELO: mx2.suse.de Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (CAMELLIA256-SHA encrypted) ESMTPS; Thu, 28 Apr 2016 12:29:47 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 563BBABB4 for ; Thu, 28 Apr 2016 12:29:42 +0000 (UTC) Date: Thu, 28 Apr 2016 14:29:44 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Add some more powi patterns to match.pd Message-ID: User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 Bootstrapped and tested on x86_64-unknown-linux-gnu. Richard. 2016-04-28 Richard Biener PR tree-optimization/70840 * match.pd: powi(-x, y) and powi(|x|,y) -> powi(x,y) if y is even; Fix pow(copysign(x, y), z) -> pow(x, z) and add powi variant; Mark x * pow(x,c) -> pow(x,c+1) commutative. Add powi(x,y) * powi(z,y) -> powi(x*z,y). Index: gcc/match.pd =================================================================== --- gcc/match.pd (revision 235544) +++ gcc/match.pd (working copy) @@ -366,6 +366,12 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (with { HOST_WIDE_INT n; } (if (real_isinteger (&TREE_REAL_CST (@1), &n) && (n & 1) == 0) (pows @0 @1))))) + /* Likewise for powi. */ + (for pows (POWI) + (simplify + (pows (op @0) INTEGER_CST@1) + (if (wi::bit_and (@1, 1) == 0) + (pows @0 @1)))) /* Strip negate and abs from both operands of hypot. */ (for hypots (HYPOT) (simplify @@ -396,10 +402,17 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (for pows (POW) copysigns (COPYSIGN) (simplify - (pows (copysigns @0 @1) REAL_CST@1) + (pows (copysigns @0 @2) REAL_CST@1) (with { HOST_WIDE_INT n; } (if (real_isinteger (&TREE_REAL_CST (@1), &n) && (n & 1) == 0) (pows @0 @1))))) +/* Likewise for powi. */ +(for pows (POWI) + copysigns (COPYSIGN) + (simplify + (pows (copysigns @0 @2) INTEGER_CST@1) + (if (wi::bit_and (@1, 1) == 0) + (pows @0 @1)))) (for hypots (HYPOT) copysigns (COPYSIGN) @@ -2781,7 +2794,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) /* Simplify x * pow(x,c) -> pow(x,c+1). */ (simplify - (mult @0 (POW:s @0 REAL_CST@1)) + (mult:c @0 (POW:s @0 REAL_CST@1)) (if (!TREE_OVERFLOW (@1)) (POW @0 (plus @1 { build_one_cst (type); })))) @@ -2819,6 +2832,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (mult (POW:s @0 @1) (POW:s @2 @1)) (POW (mult @0 @2) @1)) + /* Simplify powi(x,y) * powi(z,y) -> powi(x*z,y). */ + (simplify + (mult (POWI:s @0 @1) (POWI:s @2 @1)) + (POWI (mult @0 @2) @1)) + /* Simplify pow(x,c) / x -> pow(x,c-1). */ (simplify (rdiv (POW:s @0 REAL_CST@1) @0)