From patchwork Fri May 13 19:07:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Glisse X-Patchwork-Id: 622107 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 3r5zrR4Ffnz9syq for ; Sat, 14 May 2016 05:07:34 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=T3Q0HtV+; 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=aRM0jrUt9Hh7Baq6UXBk6iwogtgK+htwM9bX4ExO1U1SGJbSwIm0P WirVsZwdSmUVTU+JG1T0h3Z2qnZYpc3SEnxfFndjr0U924EfJ+Cjet2uty9J+EBp mDZAtrZcXkb6Ai2iXMNnH4MgX9oS9i/AkHC5Jp1XRRTM91RWddVhyo= 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=rTLGoqe+9TrYGrw6/z1lVSTRhTo=; b=T3Q0HtV+uwPmoM+n8sR9 auWSE/nO6BittooFYr1Emxx7bUN/lJeGsyv89vt5yKWfMDJTDV4HVSEXfE1C3XG0 tKI94/hZX1H1ZxAYE0Hp9eubB7AYgmYVmAao3WoxHd5mjvzwF+yZetjP4SNB6LhF oLCacWyARTF6w/NhzaIDl/I= Received: (qmail 43225 invoked by alias); 13 May 2016 19:07:25 -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 42978 invoked by uid 89); 13 May 2016 19:07:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.2 required=5.0 tests=AWL, BAYES_50, KAM_ASCII_DIVIDERS, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD autolearn=no version=3.3.2 spammy=minus, marc.glisse@inria.fr, marcglisseinriafr, bufferstep_ 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 (AES256-GCM-SHA384 encrypted) ESMTPS; Fri, 13 May 2016 19:07:14 +0000 Received: from 81-65-27-132.rev.numericable.fr (HELO laptop-mg.local) ([81.65.27.132]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 13 May 2016 21:07:11 +0200 Date: Fri, 13 May 2016 21:07:10 +0200 (CEST) From: Marc Glisse To: gcc-patches@gcc.gnu.org Subject: match.pd: ~X & Y to X ^ Y in some cases Message-ID: User-Agent: Alpine 2.02 (DEB 1266 2009-07-14) MIME-Version: 1.0 Hello, maybe this would fit better in VRP, but it is easier (and not completely useless) to put it in match.pd. Since the transformation is restricted to GIMPLE, I think I don't need to check that @0 is SSA_NAME. I didn't test if @0 has pointer type before calling get_range_info because we are doing bit_not on it, but it looks like I should because we can do bitops on pointers? Adjustment for pr69270.c is exactly the same as in the previous patch from today :-) Bootstrap+regtest on powerpc64le-unknown-linux-gnu. 2016-05-16 Marc Glisse gcc/ * match.pd (~X & Y): New transformation. gcc/testsuite/ * gcc.dg/tree-ssa/pr69270.c: Adjust. * gcc.dg/tree-ssa/andnot-1.c: New testcase. Index: gcc/match.pd =================================================================== --- gcc/match.pd (revision 236194) +++ gcc/match.pd (working copy) @@ -496,20 +496,27 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (minus @1 (bit_xor @0 @1))) /* Simplify (X & ~Y) | (~X & Y) -> X ^ Y. */ (simplify (bit_ior (bit_and:c @0 (bit_not @1)) (bit_and:c (bit_not @0) @1)) (bit_xor @0 @1)) (simplify (bit_ior:c (bit_and @0 INTEGER_CST@2) (bit_and (bit_not @0) INTEGER_CST@1)) (if (wi::bit_not (@2) == @1) (bit_xor @0 @1))) +/* Simplify (~X & Y) to X ^ Y if we know that (X & ~Y) is 0. */ +#if GIMPLE +(simplify + (bit_and (bit_not @0) INTEGER_CST@1) + (if ((get_nonzero_bits (@0) & wi::bit_not (@1)) == 0) + (bit_xor @0 @1))) +#endif /* X % Y is smaller than Y. */ (for cmp (lt ge) (simplify (cmp (trunc_mod @0 @1) @1) (if (TYPE_UNSIGNED (TREE_TYPE (@0))) { constant_boolean_node (cmp == LT_EXPR, type); }))) (for cmp (gt le) (simplify (cmp @1 (trunc_mod @0 @1)) Index: gcc/testsuite/gcc.dg/tree-ssa/andnot-1.c =================================================================== --- gcc/testsuite/gcc.dg/tree-ssa/andnot-1.c (revision 0) +++ gcc/testsuite/gcc.dg/tree-ssa/andnot-1.c (working copy) @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fdump-tree-optimized-raw" } */ + +unsigned f(unsigned i){ + i >>= __SIZEOF_INT__ * __CHAR_BIT__ - 3; + i = ~i; + return i & 7; +} + +/* { dg-final { scan-tree-dump "bit_xor_expr" "optimized" } } */ +/* { dg-final { scan-tree-dump-not "bit_not_expr" "optimized" } } */ +/* { dg-final { scan-tree-dump-not "bit_and_expr" "optimized" } } */ Index: gcc/testsuite/gcc.dg/tree-ssa/pr69270.c =================================================================== --- gcc/testsuite/gcc.dg/tree-ssa/pr69270.c (revision 236194) +++ gcc/testsuite/gcc.dg/tree-ssa/pr69270.c (working copy) @@ -1,21 +1,19 @@ /* { dg-do compile } */ /* { dg-options "-O2 -fsplit-paths -fdump-tree-dom3-details" } */ /* There should be two references to bufferstep that turn into constants. */ /* { dg-final { scan-tree-dump-times "Replaced .bufferstep_\[0-9\]+. with constant .0." 1 "dom3"} } */ /* { dg-final { scan-tree-dump-times "Replaced .bufferstep_\[0-9\]+. with constant .1." 1 "dom3"} } */ /* And some assignments ought to fold down to constants. */ -/* { dg-final { scan-tree-dump-times "Folded to: _\[0-9\]+ = -1;" 1 "dom3"} } */ -/* { dg-final { scan-tree-dump-times "Folded to: _\[0-9\]+ = -2;" 1 "dom3"} } */ /* { dg-final { scan-tree-dump-times "Folded to: _\[0-9\]+ = 1;" 1 "dom3"} } */ /* { dg-final { scan-tree-dump-times "Folded to: _\[0-9\]+ = 0;" 1 "dom3"} } */ /* The XOR operations should have been optimized to constants. */ /* { dg-final { scan-tree-dump-not "bit_xor" "dom3"} } */ extern int *stepsizeTable; void