From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 77938 invoked by alias); 5 Sep 2019 13:17:08 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 77921 invoked by uid 89); 5 Sep 2019 13:17:07 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-5.7 required=5.0 tests=AWL,BAYES_00,SPF_PASS autolearn=ham version=3.3.1 spammy=(unknown), U*c, H*Ad:U*pinskia X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 05 Sep 2019 13:17:06 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 84901AE64; Thu, 5 Sep 2019 13:17:02 +0000 (UTC) Date: Thu, 05 Sep 2019 13:17:00 -0000 From: Richard Biener To: Li Jia He cc: Andrew Pinski , Jeff Law , GCC Patches , Segher Boessenkool , wschmidt@linux.ibm.com, Martin Liska Subject: Re: [PATCH][middle-end/88784] Middle end is missing some optimizations about unsigned In-Reply-To: <845bc280-7bd6-509b-3830-4ebde50f1b20@linux.ibm.com> Message-ID: References: <1561615913-22109-1-git-send-email-helijia@linux.ibm.com> <6fb28248-5134-cec5-5045-45253e4d2eb0@redhat.com> <6d333ccf-9905-e929-c2dc-fc611ff929f1@linux.ibm.com> <845bc280-7bd6-509b-3830-4ebde50f1b20@linux.ibm.com> User-Agent: Alpine 2.21 (LSU 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-SW-Source: 2019-09/txt/msg00291.txt.bz2 On Tue, 16 Jul 2019, Li Jia He wrote: > Hi, > > I made some changes based on the recommendations. Would you like to > help me to see it again ? Sorry, it took so long time to provide the > patch. > > Note: 1. I keep the code for and_comparisons_1 and or_comparisons_1. > The reason is that I did not found a good way to handle the > optimization of '((x CODE1 y) AND (x CODE2 y))' in match.pd. > Maybe I missing some important information about match.pd. > 2. The gimple_resimplify2 function is not used. Since stmt1, > stmt2, lhs1 and lhs2 are allocated on the stack, Is there a > question with the value on the stack as the return value ? > I may have misunderstood Richard's intention. And now for the match.pd patch. +/* x > y && x != XXX_MIN --> x > y */ +(for and (truth_and bit_and) + (simplify + (and:c (gt:c@3 @0 @1) (ne @0 INTEGER_CST@2)) + (if (INTEGRAL_TYPE_P (TREE_TYPE (@0)) && INTEGRAL_TYPE_P (TREE_TYPE(@1)) + && (wi::eq_p (wi::to_wide (@2), wi::min_value (TREE_TYPE (@2))))) + @3))) + +/* x > y && x == XXX_MIN --> false */ +(for and (truth_and bit_and) + (simplify + (and:c (gt:c @0 @1) (eq @0 INTEGER_CST@2)) + (if (INTEGRAL_TYPE_P (TREE_TYPE (@0)) && INTEGRAL_TYPE_P (TREE_TYPE(@1)) + && (wi::eq_p (wi::to_wide (@2), wi::min_value (TREE_TYPE (@2))))) + { boolean_false_node; }))) you could merge those two via (for eqne (eq ne) (for and (.... (simplify (and:c (gt:c @0 @1) (eqne @0 INTEGER_CST@2)) (if (...) (switch (if (eqne == NE_EXPR) @3) (if (eqne == EQ_EXPR) { constant_boolean_node (false, type); })))) notice using constant_boolean_node (false, type); instead of boolean_false_node. I suspect more unification is possible. Also you could do (match min_value INTEGER_CST (if (INTEGRAL_TYPE_P (type) && wi::eq_p (wi::to_wide (t), wi::min_value (type))))) and then write (simplify (and:c (gt:c @0 @1) (eq @0 min_value)) (... Your (if (INTEGRAL_TYPE_P (TREE_TYPE (@0)) && INTEGRAL_TYPE_P (TREE_TYPE(@1)) is redundant, it's enough to check either @0 or @1 given they have to be compatible for the gt operation. Note you probably want to use (and:c (gt:c @0 @1) (eq @@0 min_value)) and verify that types_match (@1, @0) because when @0 are a constant (and (eq @0 min_value) is not folded which can happen) then they might have different types and thus you could have (SHORT_MAX > intvar) && (SHORT_MAX == SHORT_MAX) That said, the patterns can be quite a bit simplified I think. Richard.