From patchwork Thu Nov 12 20:43:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1399330 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=EvrvhsFi; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CXD941wHBz9sTL for ; Fri, 13 Nov 2020 07:44:08 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1596C386F00E; Thu, 12 Nov 2020 20:44:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1596C386F00E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1605213846; bh=TMtBNh8HJnx1RNz1okTEATzVqCUwn+Wy3B6S7qFRt3w=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=EvrvhsFifDfzOkHN26BbQkiq1MreKSLI3HNfdSJCxeYdlrcmJcbxmT9R2Uu6z865T Cpca7+gvD74WxmN5B9W3c7xjoDwUMyA/P5rfIjqOajio4Sg360L1XH0dfWV0cvGNeB mxY56NRaHllsURy0DLDuZG7ufzLTMKy3DEObSTPY= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by sourceware.org (Postfix) with ESMTP id 2FEE7386EC4D for ; Thu, 12 Nov 2020 20:44:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 2FEE7386EC4D 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-278-x7gcb5YAM4OhUufxcEOXqg-1; Thu, 12 Nov 2020 15:44:00 -0500 X-MC-Unique: x7gcb5YAM4OhUufxcEOXqg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DC17C186DD45 for ; Thu, 12 Nov 2020 20:43:59 +0000 (UTC) Received: from [10.10.119.201] (ovpn-119-201.rdu2.redhat.com [10.10.119.201]) by smtp.corp.redhat.com (Postfix) with ESMTP id C72AF1002C0D for ; Thu, 12 Nov 2020 20:43:56 +0000 (UTC) To: gcc-patches Subject: Fix gimple_expr_code? Message-ID: <7dc11892-b595-68b2-7b28-5b16eec63941@redhat.com> Date: Thu, 12 Nov 2020 15:43:52 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, BODY_8BITS, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, 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-Patchwork-Original-From: Andrew MacLeod via Gcc-patches From: Andrew MacLeod Reply-To: Andrew MacLeod Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" So I spent some time tracking down a ranger issue, and in the end, it boiled down to the range-op handler not being picked up properly. The handler is picked up by:   if ((gimple_code (s) == GIMPLE_ASSIGN) || (gimple_code (s) == GIMPLE_COND))     return range_op_handler (gimple_expr_code (s), gimple_expr_type (s)); where it is indexing the table with the gimple_expr_code.. the stmt being processed was for a pointer assignment,   _5 = _33 and it was coming back with a gimple_expr_code of  VAR_DECL instead of an SSA_NAME... which confused me greatly. gimple_expr_code (const gimple *stmt) {   enum gimple_code code = gimple_code (stmt);   if (code == GIMPLE_ASSIGN || code == GIMPLE_COND)     return (enum tree_code) stmt->subcode; A little more digging shows this: static inline enum tree_code gimple_assign_rhs_code (const gassign *gs) {   enum tree_code code = (enum tree_code) gs->subcode;   /* While we initially set subcode to the TREE_CODE of the rhs for      GIMPLE_SINGLE_RHS assigns we do not update that subcode to stay      in sync when we rewrite stmts into SSA form or do SSA propagations.  */   if (get_gimple_rhs_class (code) == GIMPLE_SINGLE_RHS)     code = TREE_CODE (gs->op[1]);   return code; } Fascinating comment. But it means that gimple_expr_code() isn't returning the correct result for GIMPLE_SINGLE_RHS.... Wouldn't it make sense that gimple_expr_code be changed to return gimple_assign_rhs_code() for GIMPLE_ASSIGN? I tested the attached patch, and it bootstraps and passes regression tests. There aren't a lot of places where its used, but I saw a suspicious bit in ipa-icf-gimple.c that looks like it is working around this? bool func_checker::compare_gimple_assign (gimple *s1, gimple *s2) {   tree arg1, arg2;   tree_code code1, code2;   unsigned i;   code1 = gimple_expr_code (s1);   code2 = gimple_expr_code (s2);   if (code1 != code2)     return false;   code1 = gimple_assign_rhs_code (s1);   code2 = gimple_assign_rhs_code (s2);   if (code1 != code2)     return false; and  there were one or two other places where SSA_NAME occurred in the cases of a switch after calling gimple_expr_code(). This seems like it should be the right thing? Andrew * gimple.h (gimple_expr_code): Return gimple_assign_rhs_code for GIMPLE_ASSIGN. diff --git a/gcc/gimple.h b/gcc/gimple.h index 62b5a8a6124..8ef2f83d412 100644 --- a/gcc/gimple.h +++ b/gcc/gimple.h @@ -2229,26 +2229,6 @@ gimple_set_modified (gimple *s, bool modifiedp) } -/* Return the tree code for the expression computed by STMT. This is - only valid for GIMPLE_COND, GIMPLE_CALL and GIMPLE_ASSIGN. For - GIMPLE_CALL, return CALL_EXPR as the expression code for - consistency. This is useful when the caller needs to deal with the - three kinds of computation that GIMPLE supports. */ - -static inline enum tree_code -gimple_expr_code (const gimple *stmt) -{ - enum gimple_code code = gimple_code (stmt); - if (code == GIMPLE_ASSIGN || code == GIMPLE_COND) - return (enum tree_code) stmt->subcode; - else - { - gcc_gimple_checking_assert (code == GIMPLE_CALL); - return CALL_EXPR; - } -} - - /* Return true if statement STMT contains volatile operands. */ static inline bool @@ -2889,6 +2869,29 @@ gimple_assign_cast_p (const gimple *s) return false; } + +/* Return the tree code for the expression computed by STMT. This is + only valid for GIMPLE_COND, GIMPLE_CALL and GIMPLE_ASSIGN. For + GIMPLE_CALL, return CALL_EXPR as the expression code for + consistency. This is useful when the caller needs to deal with the + three kinds of computation that GIMPLE supports. */ + +static inline enum tree_code +gimple_expr_code (const gimple *stmt) +{ + enum gimple_code code = gimple_code (stmt); + if (code == GIMPLE_ASSIGN) + return gimple_assign_rhs_code (stmt); + else if (code == GIMPLE_COND) + return (enum tree_code) stmt->subcode; + else + { + gcc_gimple_checking_assert (code == GIMPLE_CALL); + return CALL_EXPR; + } +} + + /* Return true if S is a clobber statement. */ static inline bool