From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 12C31393BC15 for ; Mon, 30 Nov 2020 19:54:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 12C31393BC15 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-347-h5JQo9-wMIaa50Q73a8TqQ-1; Mon, 30 Nov 2020 14:54:17 -0500 X-MC-Unique: h5JQo9-wMIaa50Q73a8TqQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4DE0B8145E5; Mon, 30 Nov 2020 19:54:16 +0000 (UTC) Received: from localhost.localdomain (ovpn-112-145.phx2.redhat.com [10.3.112.145]) by smtp.corp.redhat.com (Postfix) with ESMTP id E15C75C239; Mon, 30 Nov 2020 19:54:15 +0000 (UTC) Subject: Re: [14/23] simplify-rtx: Put simplify routines into a class To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com References: From: Jeff Law Message-ID: Date: Mon, 30 Nov 2020 12:54:15 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.4.0 MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Content-Language: en-US X-Spam-Status: No, score=-6.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, 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: Mon, 30 Nov 2020 19:54:21 -0000 On 11/13/20 1:18 AM, Richard Sandiford via Gcc-patches wrote: > One of the recurring warts of RTL is that multiplication by a power > of 2 is represented as a MULT inside a MEM but as an ASHIFT outside > a MEM. It would obviously be better if we didn't have this kind of > context sensitivity, but it would be difficult to remove. > > Currently the simplify-rtx.c routines are hard-coded for the > ASHIFT form. This means that some callers have to convert the > ASHIFTs “back” into MULTs after calling the simplify-rtx.c > routines; see fwprop.c:canonicalize_address for an example. > > I think we can relieve some of the pain by wrapping the simplify-rtx.c > routines in a simple class that tracks whether the expression occurs > in a MEM or not, so that no post-processing is needed. > > An obvious concern is whether passing the “this” pointer around > will slow things down or bloat the code. I can't measure any > increase in compile time after applying the patch. Sizewise, > simplify-rtx.o text increases by 2.3% in default-checking builds > and 4.1% in release-checking builds. > > I realise the MULT/ASHIFT thing isn't the most palatable > reason for doing this, but I think it might be useful for > other things in future, such as using local nonzero_bits > hooks/virtual functions instead of the global hooks. > > The obvious alternative would be to add a static variable > and hope that it is always updated correctly. I think a static would be step in the wrong direction and I'm generally in favor using classes, particularly when there's contextual information we want to query.  Shoving things into a class allows us to reason about when/how that contextual information is used. > > Later patches make use of this. > > gcc/ > * rtl.h (simplify_context): New class. > (simplify_unary_operation, simplify_binary_operation): Use it. > (simplify_ternary_operation, simplify_relational_operation): Likewise. > (simplify_subreg, simplify_gen_unary, simplify_gen_binary): Likewise. > (simplify_gen_ternary, simplify_gen_relational): Likewise. > (simplify_gen_subreg, lowpart_subreg): Likewise. > * simplify-rtx.c (simplify_gen_binary): Turn into a member function > of simplify_context. > (simplify_gen_unary, simplify_gen_ternary, simplify_gen_relational) > (simplify_truncation, simplify_unary_operation): Likewise. > (simplify_unary_operation_1, simplify_byte_swapping_operation) > (simplify_associative_operation, simplify_logical_relational_operation) > (simplify_binary_operation, simplify_binary_operation_series) > (simplify_distributive_operation, simplify_plus_minus): Likewise. > (simplify_relational_operation, simplify_relational_operation_1) > (simplify_cond_clz_ctz, simplify_merge_mask): Likewise. > (simplify_ternary_operation, simplify_subreg, simplify_gen_subreg) > (lowpart_subreg): Likewise. > (simplify_binary_operation_1): Likewise. Test mem_depth when > deciding whether the ASHIFT or MULT form is canonical. > (simplify_merge_mask): Use simplify_context. I like it.  OK for the trunk. jeff