From patchwork Sat Nov 11 12:11:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 164132 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp191644vqg; Sat, 11 Nov 2023 04:11:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IGeC5VQhbql9yImcM2Q+l2KXkIAXROqwZ6tskWto9ftugQ46vjrQjEKMIvbWq9HD45RN/a/ X-Received: by 2002:ac8:7e8c:0:b0:41c:c3ad:922f with SMTP id w12-20020ac87e8c000000b0041cc3ad922fmr2328471qtj.42.1699704717442; Sat, 11 Nov 2023 04:11:57 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1699704717; cv=pass; d=google.com; s=arc-20160816; b=Y13u3AfJ0RqN1lgAnWHpAbH8BKVAv784UnqIdEAKrbTtsNOFcdafGmCEvlEo0gWrSt /+IxwmLvKn0VmAAZE1dL7IV3tOe/JVyIbPn/Zy7tg8P5UTv/Zhg2b10TO4yeuECI4Z0A 3OxQa1J1TEh3MgcEPVcspCsvoyMXpMWWYMUUZE5nTw5ExEHZJlLnLAYx0KcFTesFjbiU wihhVtz/1F3GbkZW+8qbTSWcy5aJIfBnr56JjzVDQ+VMMsnAqSU6QODLTg61+4UWrOJm QpiosJeO5ID6A7StYw1eDdTkBxCVMLbsS+s/1nydhCWwpWcl4qg1rRHtLy2LvPMAPLnp uLMA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=9/9VmEJ0EmfOJ/EpBiJqu99wdMsT/BvkuDshx/Ee/Rc=; fh=hPrbWPhweUx4V0GV9uXJqbyAzg2ABmTz7kczrAQqMmM=; b=HLJTYG93Lb3j+VI+AVSgC+2TTHvmxNpC9DRbAgOHyX1PawydoctRDV2FVQVHBZHCzI QApOdCoCfdnv02eyxecwjIi74lgiPQNvOJ9Nhcjf5kLzd1/uTb33VtTYxUw5V7IO5X/Y GVfEeRwV05l+a3no0fcDSacV7qvTEA6/UluJmO7b3ojfLFyLvcVYWCILPDcLbWAMw1gc BrfwhOl41PKEbfYr9NQaZ1acDf9PlpIi5WwlzhELv5HrrV+rv/D432BKHVzvCeqOHC8b 8++DaSOUVO796Q2TOJh08vcVlSaQnrIZ2yWe7fPH6bjPBqd6zfR7dzGbca7HNQ6bWMmI bY3A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@adacore.com header.s=google header.b=dgXTEh2J; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=adacore.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id x15-20020ac85f0f000000b00421a4d68160si1219985qta.618.2023.11.11.04.11.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Nov 2023 04:11:57 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@adacore.com header.s=google header.b=dgXTEh2J; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=adacore.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3894A3858C2D for ; Sat, 11 Nov 2023 12:11:57 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by sourceware.org (Postfix) with ESMTPS id 7B8D93858D1E for ; Sat, 11 Nov 2023 12:11:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7B8D93858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 7B8D93858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::42e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699704693; cv=none; b=xg6S4lb0FMwdNRty1TDMvQwMiI5NJwb8eo7JqRKwn2tcn4/QmxpKiD0gw7bjTGWspcR4cQhu/tSV7SH0nqBVNtq1wUdcU0KHiDxwHT7wHKli89GD9Dr79eG8klbzHrTFufdhC/CRgaO4C0cWkINUvVypwqtKB3E8/rTVS8TGnPU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699704693; c=relaxed/simple; bh=Ktx/IA0XSgWu+Sdf0kedEqNdanVRP2gJYVhQSUDyGuQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=DOzGVjOKg6gwMyhkaGBlpSXyAvGeHRPndhj3L91q4Wpm62W9xYa+Z4G/5S+fkGDj13UYg2ti5u8JcpCztMYfFQXIZ5FvpOme6PCknWgjAtTvg+ccZfHHqItXX4yQK7DB4cB5Zy2+aYZXZx1Xru/pZ0o9rTctoWxV53L5p5qZFN0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-32f7bd27c2aso1945020f8f.2 for ; Sat, 11 Nov 2023 04:11:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1699704690; x=1700309490; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=9/9VmEJ0EmfOJ/EpBiJqu99wdMsT/BvkuDshx/Ee/Rc=; b=dgXTEh2J3386kpuBCFob9XFGgwLYHDjGT+Z09u0gzd5hMy4sxYaRhkfjjHMMwaESbE oqMNA15vTBRE9JrDoICUcaSzMY7xJsweYex2UpyJTNJkV/5xt1YpHaTbQa/jpBK8/dft 5+paX++wfNG2Vr3OCJxhdOUKSRULr4H+oIHjfXrxYkomsFbuq6RYQn/HBXXconHV3C7g 1Q6qNksWFjqIcIE1Qc9X196792Q8Cuoeyqm0SplzPMEWsSPJG9Qm4MGstS3pCxzSf+oU c/lY5hffIYhNZDJc6xNR+6qIgG7uDJDLUaV7+WiZQZ4VU/+TyOPP8DAuAzkXVelv9My1 Fi1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699704690; x=1700309490; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=9/9VmEJ0EmfOJ/EpBiJqu99wdMsT/BvkuDshx/Ee/Rc=; b=bDPwrq+IFtE4rQWjdvpULOLxDrRUPk5CxNHRK9pdXtSQrfulbsg4NVZ+FnklGKwkHa SzD7Ws1spVMz467c/2uarav7T3VIPLOeAQbctqxmvtDLPiZZbP1+lJqZK3H+7BBEtOWa RBwgL3DITzeoJaQV+vYnVOLt6dUBL+MXF9Ca8PwhUcvDhXQNsrS/CZZu8n5DWs6/NTrj Mk0m5hmT7fduCj38B7RHYedvu380lSeihBWrSDyN/PFnqKGcftsHA5fOlnElEN1IKsS5 PME3+xz7uQqs0hsnY+VBdhHgrUFUDv5di7WRw8T07e/f0XaloVuxJ8K32S3jfXuqzEI2 iSEg== X-Gm-Message-State: AOJu0YxhD0lTNsY6exF+399oFDAbsf1ZYGOoI8K2eCHrRc1gbmkVSJpv v0ITeEvet2RM43n7utk6yfkmWImzjlFmKLQbhCqLUA== X-Received: by 2002:adf:a342:0:b0:32f:9709:df75 with SMTP id d2-20020adfa342000000b0032f9709df75mr1336946wrb.24.1699704689915; Sat, 11 Nov 2023 04:11:29 -0800 (PST) Received: from fomalhaut.localnet ([2a01:e0a:8d5:d990:e654:e8ff:fe8f:2ce6]) by smtp.gmail.com with ESMTPSA id q12-20020a05600000cc00b0032db4e660d9sm1359552wrx.56.2023.11.11.04.11.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Nov 2023 04:11:29 -0800 (PST) From: Eric Botcazou X-Google-Original-From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [PATCH] Handle addresses of more constants in IPA-CP Date: Sat, 11 Nov 2023 13:11:28 +0100 Message-ID: <2245595.iZASKD2KPV@fomalhaut> MIME-Version: 1.0 X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782269573954844829 X-GMAIL-MSGID: 1782269573954844829 Hi, IPA-CP can currently handle addresses of scalar constants (CONST_DECL) so this extends that to addresses of constants in the pool (DECL_IN_CONSTANT_POOL). Again this is helpful for so-called fat pointers in Ada, i.e. objects that are semantically pointers but represented by structures made up of two pointers. This also moves the unused function print_ipcp_constant_value from ipa-cp.cc to ipa-prop.cc and renames it. I have an LTO testcase for which this makes a difference, but it's large so not really suitable for the testsuite. Bootstrapped/regtested on x86-64/Linux, OK for the mainline? 2023-11-11 Eric Botcazou * ipa-cp.cc (print_ipcp_constant_value): Move to... (values_equal_for_ipcp_p): Deal with VAR_DECLs from the constant pool. * ipa-prop.cc (ipa_print_constant_value): ...here. Likewise. (ipa_print_node_jump_functions_for_edge): Call the function ipa_print_constant_value to print IPA_JF_CONST elements. diff --git a/gcc/ipa-cp.cc b/gcc/ipa-cp.cc index 788157ebd55..34fae065454 100644 --- a/gcc/ipa-cp.cc +++ b/gcc/ipa-cp.cc @@ -478,31 +478,21 @@ values_equal_for_ipcp_p (tree x, tree y) if (TREE_CODE (x) == ADDR_EXPR && TREE_CODE (y) == ADDR_EXPR - && TREE_CODE (TREE_OPERAND (x, 0)) == CONST_DECL - && TREE_CODE (TREE_OPERAND (y, 0)) == CONST_DECL) - return operand_equal_p (DECL_INITIAL (TREE_OPERAND (x, 0)), - DECL_INITIAL (TREE_OPERAND (y, 0)), 0); + && (TREE_CODE (TREE_OPERAND (x, 0)) == CONST_DECL + || (TREE_CODE (TREE_OPERAND (x, 0)) == VAR_DECL + && DECL_IN_CONSTANT_POOL (TREE_OPERAND (x, 0)))) + && (TREE_CODE (TREE_OPERAND (y, 0)) == CONST_DECL + || (TREE_CODE (TREE_OPERAND (y, 0)) == VAR_DECL + && DECL_IN_CONSTANT_POOL (TREE_OPERAND (y, 0))))) + return TREE_OPERAND (x, 0) == TREE_OPERAND (y, 0) + || operand_equal_p (DECL_INITIAL (TREE_OPERAND (x, 0)), + DECL_INITIAL (TREE_OPERAND (y, 0)), 0); else return operand_equal_p (x, y, 0); } /* Print V which is extracted from a value in a lattice to F. */ -static void -print_ipcp_constant_value (FILE * f, tree v) -{ - if (TREE_CODE (v) == ADDR_EXPR - && TREE_CODE (TREE_OPERAND (v, 0)) == CONST_DECL) - { - fprintf (f, "& "); - print_generic_expr (f, DECL_INITIAL (TREE_OPERAND (v, 0))); - } - else - print_generic_expr (f, v); -} - -/* Print V which is extracted from a value in a lattice to F. */ - static void print_ipcp_constant_value (FILE * f, ipa_polymorphic_call_context v) { diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc index 827bdb691ba..7de2b788185 100644 --- a/gcc/ipa-prop.cc +++ b/gcc/ipa-prop.cc @@ -365,6 +365,24 @@ ipa_initialize_node_params (struct cgraph_node *node) ipa_populate_param_decls (node, *info->descriptors); } +/* Print VAL which is extracted from a jump function to F. */ + +static void +ipa_print_constant_value (FILE *f, tree val) +{ + print_generic_expr (f, val); + + /* This is in keeping with values_equal_for_ipcp_p. */ + if (TREE_CODE (val) == ADDR_EXPR + && (TREE_CODE (TREE_OPERAND (val, 0)) == CONST_DECL + || (TREE_CODE (TREE_OPERAND (val, 0)) == VAR_DECL + && DECL_IN_CONSTANT_POOL (TREE_OPERAND (val, 0))))) + { + fputs (" -> ", f); + print_generic_expr (f, DECL_INITIAL (TREE_OPERAND (val, 0))); + } +} + /* Print the jump functions associated with call graph edge CS to file F. */ static void @@ -386,15 +404,8 @@ ipa_print_node_jump_functions_for_edge (FILE *f, struct cgraph_edge *cs) fprintf (f, "UNKNOWN\n"); else if (type == IPA_JF_CONST) { - tree val = jump_func->value.constant.value; fprintf (f, "CONST: "); - print_generic_expr (f, val); - if (TREE_CODE (val) == ADDR_EXPR - && TREE_CODE (TREE_OPERAND (val, 0)) == CONST_DECL) - { - fprintf (f, " -> "); - print_generic_expr (f, DECL_INITIAL (TREE_OPERAND (val, 0))); - } + ipa_print_constant_value (f, jump_func->value.constant.value); fprintf (f, "\n"); } else if (type == IPA_JF_PASS_THROUGH) @@ -468,7 +479,7 @@ ipa_print_node_jump_functions_for_edge (FILE *f, struct cgraph_edge *cs) else if (item->jftype == IPA_JF_CONST) { fprintf (f, "CONST: "); - print_generic_expr (f, item->value.constant); + ipa_print_constant_value (f, item->value.constant); } else if (item->jftype == IPA_JF_UNKNOWN) fprintf (f, "UNKNOWN: " HOST_WIDE_INT_PRINT_DEC " bits",