From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1611) id 8F0ED3884FA3; Wed, 14 Dec 2022 18:09:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8F0ED3884FA3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1671041379; bh=6IdmShk6CCtoZFwAcDPLjdOAb0bB+4/t7ffw3L/pMMA=; h=From:To:Subject:Date:From; b=q+aF26BZrwaD7bBAUUrzHNbAG/7vqESmOqwEbLJA3JX4vk/jHhz2hv6CnWVo31Asg /X+Kqrc+AFU8S+Kz88h4gCQPlC1spuQdxqcK6cJMOGPxv3U8GP0Wk5lZRTAKuN9xhe BJidrEAlyEneFnit0K5OqKP/KlCLjOyXqkinB3jI= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Martin Jambor To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-4706] ipa-sra: Consider the first parameter of methods safe to dereference X-Act-Checkin: gcc X-Git-Author: Martin Jambor X-Git-Refname: refs/heads/master X-Git-Oldrev: 6539bbc14836b8e0fa08944be2c069b58bed9455 X-Git-Newrev: 0e9495303db062cf118869b7526132b5821833e9 Message-Id: <20221214180939.8F0ED3884FA3@sourceware.org> Date: Wed, 14 Dec 2022 18:09:39 +0000 (GMT) List-Id: https://gcc.gnu.org/g:0e9495303db062cf118869b7526132b5821833e9 commit r13-4706-g0e9495303db062cf118869b7526132b5821833e9 Author: Martin Jambor Date: Wed Dec 14 19:01:11 2022 +0100 ipa-sra: Consider the first parameter of methods safe to dereference Honza requested this after reviewing the patch that taught IPA-SRA that REFERENCE_TYPEs are always non-NULL that the pass also handles the first parameters of methods, this pointers, in the same way. So this patch does that. gcc/ChangeLog: 2022-12-14 Martin Jambor * ipa-sra.cc (create_parameter_descriptors): Consider the first parameter of a method safe to dereference. gcc/testsuite/ChangeLog: 2022-12-14 Martin Jambor * g++.dg/ipa/ipa-sra-6.C: New test. Diff: --- gcc/ipa-sra.cc | 7 +++- gcc/testsuite/g++.dg/ipa/ipa-sra-6.C | 62 ++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/gcc/ipa-sra.cc b/gcc/ipa-sra.cc index bcabdedfc6c..6fe336eeb19 100644 --- a/gcc/ipa-sra.cc +++ b/gcc/ipa-sra.cc @@ -1206,7 +1206,12 @@ create_parameter_descriptors (cgraph_node *node, if (POINTER_TYPE_P (type)) { desc->by_ref = true; - desc->safe_ref = (TREE_CODE (type) == REFERENCE_TYPE); + if (TREE_CODE (type) == REFERENCE_TYPE + || (num == 0 + && TREE_CODE (TREE_TYPE (node->decl)) == METHOD_TYPE)) + desc->safe_ref = true; + else + desc->safe_ref = false; type = TREE_TYPE (type); if (TREE_CODE (type) == FUNCTION_TYPE diff --git a/gcc/testsuite/g++.dg/ipa/ipa-sra-6.C b/gcc/testsuite/g++.dg/ipa/ipa-sra-6.C new file mode 100644 index 00000000000..d6b7822533f --- /dev/null +++ b/gcc/testsuite/g++.dg/ipa/ipa-sra-6.C @@ -0,0 +1,62 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-ipa-sra" } */ + +namespace { + +class C +{ + + int mi; + +public: + C (int i) + : mi(i) + {} + + void foo (int c); +}; + +volatile int vi; + + +void __attribute__((noinline)) +C::foo (int cond) +{ + int i; + if (cond) + i = mi; + else + i = 0; + vi = i; +} + +static C c_instance(1); +} + +void __attribute__((noinline)) +bar (C *p, int cond) +{ + p->foo (cond); +} + + +class C *gp; + +void something(void); + +void +baz (int cond) +{ + C c(vi); + gp = &c; + something (); + bar (gp, cond); +} + +void +hoo(void) +{ + gp = &c_instance; +} + +/* { dg-final { scan-ipa-dump "Will split parameter" "sra" } } */