From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 94983 invoked by alias); 7 Aug 2019 17:40:00 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 94971 invoked by uid 89); 7 Aug 2019 17:39:59 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-1.6 required=5.0 tests=BAYES_00,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=no version=3.3.1 spammy=worried X-HELO: mail-qt1-f173.google.com Received: from mail-qt1-f173.google.com (HELO mail-qt1-f173.google.com) (209.85.160.173) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 07 Aug 2019 17:39:56 +0000 Received: by mail-qt1-f173.google.com with SMTP id l9so89139467qtu.6 for ; Wed, 07 Aug 2019 10:39:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:date:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=ripfU0EXGPhrAx6x0u6xONBCcbwhD0IFzHlxSak4OYk=; b=FQ1fSxw71bCOUIe8aUQMDCW4V8nJGDATprVwVX+Pp+tDTkxXY27lli2WP4GXTBSQ2X H0YDgHa6GH/j1W9wIakjyxRQbJHcaVAC07bYFIohbIuf4AyPsD9voiAvEJ4VgYe8BRSE TzfhyySDD9vRw8VgwulWpb69G/ich7xa0kEiyG9dOaUZPuKJa4KD6QpriE8ufIC3sbVL CanYkF7xpQeTlNU/4DTQLhPBV6SJbAw1nmRQY/+pO8IQUORWrXsuQ6HzQkGi41hobKrN KM0o6Z52cXSSarVCIy2Ak+SLmuVnjqX4q1c/q3T56sSs+3ANxQr+LUNM/MClrOhwJb+d Zg0w== Return-Path: Received: from rani.riverdale.lan ([2001:470:1f07:5f3::b55f]) by smtp.gmail.com with ESMTPSA id e125sm37731205qkd.120.2019.08.07.10.39.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Aug 2019 10:39:54 -0700 (PDT) From: Arvind Sankar Date: Wed, 07 Aug 2019 17:40:00 -0000 To: Segher Boessenkool Cc: Arvind Sankar , gcc@gcc.gnu.org Subject: Re: Use predicates for RTL objects Message-ID: <20190807173952.GA3751941@rani.riverdale.lan> References: <20190807161528.GA3326377@rani.riverdale.lan> <20190807173353.GV31406@gate.crashing.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20190807173353.GV31406@gate.crashing.org> User-Agent: Mutt/1.10.1 (2018-07-13) X-SW-Source: 2019-08/txt/msg00026.txt.bz2 On Wed, Aug 07, 2019 at 12:33:53PM -0500, Segher Boessenkool wrote: > On Wed, Aug 07, 2019 at 12:15:29PM -0400, Arvind Sankar wrote: > > I would also like to get some comments on the following idea to make the > > code checks more readable: I am thinking of adding > > bool rtx_def::is_a (enum rtx_code) const > > This would allow us to make all the rtx_code comparisons more readable > > without having to define individual macros for each. > > i.e., > > REG_P (x) => x->is_a (REG) > > GET_CODE (x) == PLUS => x->is_a (PLUS) > > GET_CODE (PATTERN (x)) == SEQUENCE => PATTERN (x)->is_a (SEQUENCE) > > That makes things much worse. Not only is it less readable (IMO), but > the "is_a" idiom is used to check if something is of a certain class, > which is not the case here. > Well, the rtx_code *is* kind of a class. It determines what fields of the rtx are valid and what they contain etc. > In "GET_CODE (x) == PLUS" it is clear that what the resulting machine > code does is cheap. With "x->is_a (PLUS)", who knows what is happening > below the covers! We already have, for eg, is_a (x), and there are predicate macros whose implementation is more complex than checking the code field. You basically have to trust that it's sensibly implemented, i.e. that it is as efficiently implemented as it can be. I don't think people writing RTL transformations should be overly worried about what machine code their predicates are generating, especially when they're calling the defined API for it. > > (And "REG_P" and similar are much shorter code to type). > That is true for the ones that exist, but there are lots more that don't and it doesn't really make sense to add individual macros for all of them. > > Segher