From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sourceware.org (Postfix) with ESMTPS id 1EE8B385ED4B for ; Tue, 4 Aug 2020 15:38:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 1EE8B385ED4B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=inria.fr Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=marc.glisse@inria.fr X-IronPort-AV: E=Sophos;i="5.75,434,1589234400"; d="scan'208";a="462427272" Received: from 85-171-191-139.rev.numericable.fr (HELO stedding) ([85.171.191.139]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Aug 2020 17:38:52 +0200 Date: Tue, 4 Aug 2020 17:38:52 +0200 (CEST) From: Marc Glisse X-X-Sender: glisse@stedding.saclay.inria.fr To: Richard Biener cc: GCC Patches Subject: Re: Simplify X * C1 == C2 with undefined overflow In-Reply-To: Message-ID: References: User-Agent: Alpine 2.23 (DEB 453 2020-06-18) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Aug 2020 15:38:54 -0000 On Mon, 3 Aug 2020, Richard Biener wrote: > On Sat, Aug 1, 2020 at 9:29 AM Marc Glisse wrote: >> >> Hello, >> >> this transformation is quite straightforward, without overflow, 3*X==15 is >> the same as X==5 and 3*X==5 cannot happen. Adding a single_use restriction >> for the first case didn't seem necessary, although of course it can >> slightly increase register pressure in some cases. >> >> Bootstrap+regtest on x86_64-pc-linux-gnu. > > OK with using constant_boolean_node (cmp == NE_EXPR, type). > > ISTR we had the x * 0 == CST simplification somewhere > but maybe it was x * y == 0 ... ah, yes: > > /* Transform comparisons of the form X * C1 CMP 0 to X CMP 0 in the > signed arithmetic case. That form is created by the compiler > often enough for folding it to be of value. One example is in > computing loop trip counts after Operator Strength Reduction. */ > (for cmp (simple_comparison) > scmp (swapped_simple_comparison) > (simplify > (cmp (mult@3 @0 INTEGER_CST@1) integer_zerop@2) > > As it is placed after your pattern it will be never matched I think > (but we don't warn because of INTEGER_CST vs. integer_zerop). > > But I think your pattern subsumes it besides of the X * 0 == 0 > compare - oh, and the other pattern also handles relational compares > (those will still trigger). > > Maybe place the patterns next to each other? Also see whether > moving yours after the above will cease the testcases to be handled > because it's no longer matched - if not this might be the better > order. I moved it after, it still works, so I pushed the patch. Note that the other transformation has a single_use restriction, while this one doesn't, that's not very consistent, but also hopefully not so important... -- Marc Glisse