From patchwork Tue Jun 30 16:32:48 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 489768 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 008141402AB for ; Wed, 1 Jul 2015 02:33:01 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=eUd9mfmT; 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:cc:subject:message-id:mime-version:content-type; q=dns; s=default; b=StbR7fMrLqXwxYK2xIK9qL9g/vrCOkPAoDj9rIRk1CcYBQd0Wb nIqjN4/cv7PWZZUpnPd6IKh6lQ7gTCJuCXdE4kNGZlgtRJuHjgkjH+n0LTrnvMGE KQcycEKUDQx3gS39VLeMOMSc8G/DQJIcI6v4+xccL2QWKg2QRSMkJQGNQ= 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:mime-version:content-type; s= default; bh=WqECZPgFFRW+jYdxEY+J89YH+I4=; b=eUd9mfmTY2gufo/t80+y 5JQkAlBP2wmGHC8tiAS6a0KarJLsiQfiJ4yyBGI9XRZTk+gj6AJDoV7V7n7Rn+Ts 2fS5hhVGZUDXrLah7/hfqAfJcv0PhZOd07m91qBckwgjPUsqc8zwClLi8J9zbX1T bzZI8OsJ5IlL8RmHHHOM68U= Received: (qmail 92140 invoked by alias); 30 Jun 2015 16:32:54 -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 92131 invoked by uid 89); 30 Jun 2015 16:32:54 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=no version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Tue, 30 Jun 2015 16:32:53 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id 76989B66B8; Tue, 30 Jun 2015 16:32:52 +0000 (UTC) Received: from redhat.com (ovpn-204-67.brq.redhat.com [10.40.204.67]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t5UGWmqf022774 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO); Tue, 30 Jun 2015 12:32:51 -0400 Date: Tue, 30 Jun 2015 18:32:48 +0200 From: Marek Polacek To: GCC Patches Cc: Richard Biener Subject: [match.pd, committed] Tweak ~x | x Message-ID: <20150630163248.GW10139@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) As discussed here: . Bootstrapped/regtested on x86_64-linux, applying to trunk. 2015-06-30 Marek Polacek * match.pd (~x | x): Don't use tree_nop_conversion_p. Build the final expression with the operand's type and then convert it to the type of the expression. * gcc.dg/fold-ior-3.c: New test. Marek diff --git gcc/match.pd gcc/match.pd index 682784b..adb7a52 100644 --- gcc/match.pd +++ gcc/match.pd @@ -286,8 +286,7 @@ along with GCC; see the file COPYING3. If not see /* ~x | x -> -1 */ (simplify (bit_ior:c (convert? @0) (convert? (bit_not @0))) - (if (tree_nop_conversion_p (type, TREE_TYPE (@0))) - { build_all_ones_cst (type); })) + (convert { build_all_ones_cst (TREE_TYPE (@0)); })) /* x ^ x -> 0 */ (simplify diff --git gcc/testsuite/gcc.dg/fold-ior-3.c gcc/testsuite/gcc.dg/fold-ior-3.c index e69de29..ed89ff9 100644 --- gcc/testsuite/gcc.dg/fold-ior-3.c +++ gcc/testsuite/gcc.dg/fold-ior-3.c @@ -0,0 +1,35 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fdump-tree-cddce1" } */ + +int +fn1 (_Bool a) +{ + return ((int) a) | ((int) ~a); +} + +int +fn2 (unsigned char a) +{ + return ((int) a) | ((int) ~a); +} + +int +fn3 (unsigned short a) +{ + return ((int) a) | ((int) ~a); +} + +int +fn4 (signed char a) +{ + return ((int) a) | ((int) ~a); +} + +int +fn5 (signed short a) +{ + return ((int) a) | ((int) ~a); +} + +/* { dg-final { scan-tree-dump-not "~" "cddce1" } } */ +/* { dg-final { scan-tree-dump-not " \\| " "cddce1" } } */