From patchwork Fri Jan 15 11:01:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 568032 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3A719140BFF for ; Fri, 15 Jan 2016 22:02:05 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=YcCV4d+5; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=GRGT7tLuHjCluGbpmko85h/NSli3kQSN/MnwoSFsaKTv/ybHdqR// UvH0Fvj4F4yUgsZCoyW6cJ/J14eY0h0lKxbWG/ctlLbYZimip9Nyf/rhQR1F5dIR riTkoGPpemYcec5C5Fg6+mz9riNtoydo7zY2Rp8zIwvbIjng2g1wWI= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=TBFnY19erznVY/alTVTivfuL4VU=; b=YcCV4d+5Id+JHDXDHohI jHMqi8517NQYQsfMHLOF35hiFhyI/gdvW62g7/X+n+iK4tddychUoetGyjuM6MQi ay5ERlCje0tkc/bXrdazUtFzeOi7oHq/mrQxUBiyJkDayRoofuBY9D7WevN+0uPZ jkmZG8SxXadE0LRfcSfYoEY= Received: (qmail 116076 invoked by alias); 15 Jan 2016 11:01:55 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 116019 invoked by uid 89); 15 Jan 2016 11:01:55 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.0 required=5.0 tests=AWL, BAYES_00, KAM_ASCII_DIVIDERS, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD autolearn=no version=3.3.2 spammy= X-HELO: nikam.ms.mff.cuni.cz Received: from nikam.ms.mff.cuni.cz (HELO nikam.ms.mff.cuni.cz) (195.113.20.16) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Fri, 15 Jan 2016 11:01:53 +0000 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id A2A8B54453E; Fri, 15 Jan 2016 12:01:48 +0100 (CET) Date: Fri, 15 Jan 2016 12:01:48 +0100 From: Jan Hubicka To: gcc-patches@gcc.gnu.org Subject: Make ipa-icf to not prevent devirtualization Message-ID: <20160115110148.GC77658@kam.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Hi, this patch avoid ipa-icf to take away body of a virtual function which is a subject of later devirtualization. Bootstrapped/regtested x86_64-linux, comitted. Honza PR ipa/68148 * ipa-icf.c (sem_function::merge): Virtual functions may become reachable even if they address is not taken and there are no idrect calls. * testsuite/g++.dg/ipa/devirt-49.C: New testcase. Index: ipa-icf.c =================================================================== --- ipa-icf.c (revision 232407) +++ ipa-icf.c (working copy) @@ -1305,6 +1305,7 @@ sem_function::merge (sem_item *alias_ite /* If all callers was redirected, do not produce wrapper. */ if (alias->can_remove_if_no_direct_calls_p () + && !DECL_VIRTUAL_P (alias->decl) && !alias->has_aliases_p ()) { create_wrapper = false; Index: testsuite/g++.dg/ipa/devirt-49.C =================================================================== --- testsuite/g++.dg/ipa/devirt-49.C (revision 0) +++ testsuite/g++.dg/ipa/devirt-49.C (revision 0) @@ -0,0 +1,20 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-ipa-devirt" } */ +struct Interface { + virtual ~Interface() {} + virtual void virtualFunc() = 0; + virtual void virtualFunc2() = 0; +}; + +struct Concrete : Interface { + int counter_; + Concrete() : counter_(0) {} + void virtualFunc() { counter_++; } + void virtualFunc2() { counter_++; } +}; + +void test(Interface &c) { + c.virtualFunc(); + c.virtualFunc2(); +} +/* { dg-final { scan-ipa-dump "2 speculatively devirtualized" "devirt" } } */