From patchwork Sat Sep 29 11:35:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Glisse X-Patchwork-Id: 976588 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-486661-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=inria.fr Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="LglkLUBr"; dkim-atps=neutral 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 42Mmgd3sy0z9s9J for ; Sat, 29 Sep 2018 21:35:23 +1000 (AEST) 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=I+hwcq/VtnBVH/5QZ91NeWqU/mv8cFQGrjcjjdQXD+jv7igX9igM3 BU1ugK+J/nS62QA0fHsLz1CnJru9/AnmZemclsDzkxIY3PbWx9ooXwBmAU5eyhp/ V5VmejbhaUndrJwdmX98ihZyvYb8oQTvNia8AN0ZnyQKdgRt+QUMnc= 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=Lg8cd84WFK1mp8UWxwnDPY/vtPQ=; b=LglkLUBrKncaDiHz0Tl4 BG7MbJV+TfkigOuM67O9q/G+CLvLXZ+takh/utUgA0dHlSg9ZoEFlWP863fWtgzn BjMpQSM/d4aIGidQQ5Y2qhz+sN6+WxFZgozPGO7MtDMBp+qqMw/Pw5ZcTSDuhutZ cDUwwsU9VOuzQ5rufqdJGas= Received: (qmail 77896 invoked by alias); 29 Sep 2018 11:35:17 -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 77882 invoked by uid 89); 29 Sep 2018 11:35:16 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-10.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, SPF_PASS autolearn=ham version=3.3.2 spammy=ugly, D*1, Eventually, to_wide X-HELO: mail2-relais-roc.national.inria.fr Received: from mail2-relais-roc.national.inria.fr (HELO mail2-relais-roc.national.inria.fr) (192.134.164.83) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 29 Sep 2018 11:35:14 +0000 Received: from ip-133.net-89-2-166.rev.numericable.fr (HELO stedding) ([89.2.166.133]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 29 Sep 2018 13:35:12 +0200 Date: Sat, 29 Sep 2018 13:35:06 +0200 (CEST) From: Marc Glisse To: gcc-patches@gcc.gnu.org Subject: ((X /[ex] A) +- B) * A --> X +- A * B Message-ID: User-Agent: Alpine 2.02 (DEB 1266 2009-07-14) MIME-Version: 1.0 Hello, I noticed quite ugly code from both testcases. This transformation does not fix either, but it helps a bit. bootstrap+regtest on powerpc64le-unknown-linux-gnu. 2018-09-30 Marc Glisse gcc/ * match.pd (((X /[ex] A) +- B) * A): New transformation. gcc/testsuite/ * gcc.dg/tree-ssa/muldiv-1.c: New file. * gcc.dg/tree-ssa/muldiv-2.c: Likewise. Index: gcc/match.pd =================================================================== --- gcc/match.pd (revision 264371) +++ gcc/match.pd (working copy) @@ -2637,20 +2637,39 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) && operand_equal_p (@1, build_low_bits_mask (TREE_TYPE (@1), TYPE_PRECISION (type)), 0)) (convert @0))) /* (X /[ex] A) * A -> X. */ (simplify (mult (convert1? (exact_div @0 @@1)) (convert2? @1)) (convert @0)) +/* ((X /[ex] A) +- B) * A --> X +- A * B. */ +(for op (plus minus) + (simplify + (mult (convert1? (op (convert2? (exact_div @0 INTEGER_CST@@1)) INTEGER_CST@2)) @1) + (if (tree_nop_conversion_p (type, TREE_TYPE (@2)) + && tree_nop_conversion_p (TREE_TYPE (@0), TREE_TYPE (@2))) + (with + { + wi::overflow_type overflow; + wide_int mul = wi::mul (wi::to_wide (@1), wi::to_wide (@2), + TYPE_SIGN (type), &overflow); + } + (if (types_match (type, TREE_TYPE (@2)) + && types_match (TREE_TYPE (@0), TREE_TYPE (@2)) && !overflow) + (op @0 { wide_int_to_tree (type, mul); }) + (with { tree utype = unsigned_type_for (type); } + (convert (op (convert:utype @0) + (mult (convert:utype @1) (convert:utype @2)))))))))) + /* Canonicalization of binary operations. */ /* Convert X + -C into X - C. */ (simplify (plus @0 REAL_CST@1) (if (REAL_VALUE_NEGATIVE (TREE_REAL_CST (@1))) (with { tree tem = const_unop (NEGATE_EXPR, type, @1); } (if (!TREE_OVERFLOW (tem) || !flag_trapping_math) (minus @0 { tem; }))))) Index: gcc/testsuite/gcc.dg/tree-ssa/muldiv-1.c =================================================================== --- gcc/testsuite/gcc.dg/tree-ssa/muldiv-1.c (nonexistent) +++ gcc/testsuite/gcc.dg/tree-ssa/muldiv-1.c (working copy) @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-options "-O3 -fdump-tree-optimized-raw" } */ + +// ldist produces (((q-p-4)/4)&...+1)*4 +// Make sure we remove at least the division +// Eventually this should just be n*4 + +void foo(int*p, __SIZE_TYPE__ n){ + for(int*q=p+n;p!=q;++p)*p=0; +} + +/* { dg-final { scan-tree-dump "builtin_memset" "optimized" } } */ +/* { dg-final { scan-tree-dump-not "div" "optimized" } } */ Index: gcc/testsuite/gcc.dg/tree-ssa/muldiv-2.c =================================================================== --- gcc/testsuite/gcc.dg/tree-ssa/muldiv-2.c (nonexistent) +++ gcc/testsuite/gcc.dg/tree-ssa/muldiv-2.c (working copy) @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-O1 -fdump-tree-optimized-raw" } */ + +// 'a' should disappear, but we are not there yet + +int* f(int* a, int* b, int* c){ + __PTRDIFF_TYPE__ d = b - a; + d += 1; + return a + d; +} + +/* { dg-final { scan-tree-dump-not "div" "optimized" } } */