From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 44AD4382CB94 for ; Wed, 14 Dec 2022 15:19:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 44AD4382CB94 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.cz Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 5D28622142; Wed, 14 Dec 2022 15:18:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1671031139; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=gem8nKAnXU17L2e6N4UrbViBJbpEQ8b+zJBy843OvUs=; b=xgecHrfvQB05X6XPbGomWdWwiwAb0aXMUY+YJcAenm2Z8qn+V6ygKYVkO5PRAgRX7POFnL MmPaZQeMj7W5+PmwOSpWn4JXMsQ+yJ0oybgyoibt4GZi0Q2FOWWkf5zqG/e4C+Ic3jQ4/t HWcff75d40+6u2ocrMbWJ0BguVOkTqI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1671031139; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=gem8nKAnXU17L2e6N4UrbViBJbpEQ8b+zJBy843OvUs=; b=mNn65h/PV1U3Kse+qGcRRgCBWHbDxvuJcsN/UhYywSNEyewtVT2OLvOJsAaiZCyVjYNUdr uTwYnAlDfo35/XBg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 4FD2E1333E; Wed, 14 Dec 2022 15:18:59 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id QGFoE2PpmWMDRAAAMHmgww (envelope-from ); Wed, 14 Dec 2022 15:18:59 +0000 From: Martin Jambor To: GCC Patches Cc: Jan Hubicka , Jan Hubicka Subject: [PATCH] ipa-sra: Consider the first parameter of methods safe to dereference User-Agent: Notmuch/0.37 (https://notmuchmail.org) Emacs/28.1 (x86_64-suse-linux-gnu) Date: Wed, 14 Dec 2022 16:18:58 +0100 Message-ID: MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hi, 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. The patch is undergoing bootstrap and testing on an x86_64-linux right now. OK if it passes? Thanks, Martin 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. --- gcc/ipa-sra.cc | 7 +++- gcc/testsuite/g++.dg/ipa/ipa-sra-6.C | 62 ++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/ipa/ipa-sra-6.C 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" } } */ -- 2.38.1