From patchwork Wed Nov 22 17:34:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Glisse X-Patchwork-Id: 840461 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-467718-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="LnrPAzzI"; 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 3yhqMH1fvCz9s83 for ; Thu, 23 Nov 2017 04:34:19 +1100 (AEDT) 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=LC8rwqRuXIi87fiKYIMFBOLl3xt25p2Y2YYtpkxNE4RD16OfStmds xCEE75ZIE/JRANTm0NcLp0NNs+dRluVrkgXb93cRDif4lugQjWmJ1q0QsPHp+kcf j8GOCf79TUGELD7sKYYnudHEOtg8d8BRtNugEHSiOywumE+a9HNFdw= 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=o1NoN3qMudJZXUMTdk6VPS+hVxI=; b=LnrPAzzIY9tAIPP4Vy+S C0iBL+JbfhtJqk4Pry89g9nmJI+8eEArynoNhoDAYNYmEqTrW2aDodaLoVtffZEv D92AImjaFsZ8CASdnCBWxpCDa435qGWYGFAtd4UWrH7m29zevmRTkGZkInXcgoNC KQAAARhRcz7L7pxKERPBIrw= Received: (qmail 126790 invoked by alias); 22 Nov 2017 17:34:12 -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 126779 invoked by uid 89); 22 Nov 2017 17:34:11 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-13.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, KAM_NUMSUBJECT, KB_WAM_FROM_NAME_SINGLEWORD, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=H*c:HHHHH 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; Wed, 22 Nov 2017 17:34:10 +0000 Received: from stedding-dock.saclay.inria.fr ([193.55.177.248]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 22 Nov 2017 18:34:08 +0100 Date: Wed, 22 Nov 2017 18:34:08 +0100 (CET) From: Marc Glisse To: gcc-patches@gcc.gnu.org Subject: Simplify ptr - 0 Message-ID: User-Agent: Alpine 2.02 (DEB 1266 2009-07-14) MIME-Version: 1.0 Hello, I hadn't implemented this simplification because I think it is invalid code, but apparently people do write it, so we might as well handle it sensibly. This also happens to work around PR 83104 (already fixed). bootstrap+regtest on powerpc64le-unknown-linux-gnu. 2017-11-22 Marc Glisse * match.pd (ptr-0): New transformation. Index: gcc/match.pd =================================================================== --- gcc/match.pd (revision 255052) +++ gcc/match.pd (working copy) @@ -95,20 +95,25 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (for op (plus pointer_plus minus bit_ior bit_xor) (simplify (op @0 integer_zerop) (non_lvalue @0))) /* 0 +p index -> (type)index */ (simplify (pointer_plus integer_zerop @1) (non_lvalue (convert @1))) +/* ptr - 0 -> (type)ptr */ +(simplify + (pointer_diff @0 integer_zerop) + (convert @0)) + /* See if ARG1 is zero and X + ARG1 reduces to X. Likewise if the operands are reversed. */ (simplify (plus:c @0 real_zerop@1) (if (fold_real_zero_addition_p (type, @1, 0)) (non_lvalue @0))) /* See if ARG1 is zero and X - ARG1 reduces to X. */ (simplify (minus @0 real_zerop@1)