From patchwork Thu Nov 15 22:08:47 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sriraman Tallam X-Patchwork-Id: 199451 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]) by ozlabs.org (Postfix) with SMTP id A36AA2C0332 for ; Fri, 16 Nov 2012 09:08:59 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1353622139; h=Comment: DomainKey-Signature:Received:Received:Received:Received: MIME-Version:Received:Received:Date:Message-ID:Subject:From:To: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=o/NsbU+ KPZMFXPWX+OpIZ0q49Hc=; b=Dsj+SQjRza9fW4T/n20DL/NhrvICQq9mdMCcK/S D4sCsiOUtRGkBne4gpMUwvCp633Muahizhu6wguRRuW7NuXFhCKZxMqvP2HPweJi u1TOanacewohOzy/L9MIkaLd56N4XWlVkUrXJQgkPvT7QCLWhkEqnFs8P/HMQ28s b5xk= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:X-Google-DKIM-Signature:MIME-Version:Received:Received:Date:Message-ID:Subject:From:To:Content-Type:X-Gm-Message-State:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=WaR1whaUWBOiUX+1ZT/+tfzhjtZIvEBKgz8QyOR7MTpnbJUPFQfnoNAlV8houX eLFXeR+UsSWh+CQ2A0UAvFgHchf9SFOs3R5SlkMD8D+s5XgY1AZEr2KeHkQZ76Zh azVcWZFPaOKm8KOrsBN1B/IJ30KHhHmqegIBxCTi+Px5Y=; Received: (qmail 2437 invoked by alias); 15 Nov 2012 22:08:54 -0000 Received: (qmail 2423 invoked by uid 22791); 15 Nov 2012 22:08:53 -0000 X-SWARE-Spam-Status: No, hits=-4.7 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, KHOP_RCVD_TRUST, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail-ob0-f175.google.com (HELO mail-ob0-f175.google.com) (209.85.214.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 15 Nov 2012 22:08:48 +0000 Received: by mail-ob0-f175.google.com with SMTP id vb8so2233937obc.20 for ; Thu, 15 Nov 2012 14:08:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type :x-gm-message-state; bh=0khDZSlYgOGwh3+mUCt3iVJhIbnyNih6YE5H/I0AgZI=; b=i82NMfaAKsXNj+qxcfIcWLT+NS0J+G6ziZ6iyji8Nil4V99maXrRAaaNTLZwVPtzY1 /uxuxbwdm6p+FYGOn/2q4SI9TRRZx6XSYmdCC1UmGk/6EX38TBtzPPAYB4tYXLoONgyL xIGsq/ILFh42+2zOI14JtVn9e2UI2cRBYBVFuYWy6fHFbJNAh3f9I7hvULS+YQR4u2q8 QidJb5mqWbxQVtogkU3KcajHyfacy42BTGbB1wQWmcEWwVeDJOIlc2tr4unNQeI8dGj5 aqfwH9rG3MOEp7PbOAbm07G2q28derbvgQHLGLlS8XrD44yVCZ2+NAOQ+gRbEVy6+aV0 ljFA== MIME-Version: 1.0 Received: by 10.60.27.161 with SMTP id u1mr2320882oeg.27.1353017327840; Thu, 15 Nov 2012 14:08:47 -0800 (PST) Received: by 10.182.176.106 with HTTP; Thu, 15 Nov 2012 14:08:47 -0800 (PST) Date: Thu, 15 Nov 2012 14:08:47 -0800 Message-ID: Subject: [PATCH] Function Multiversioning Bug, checking for function versions From: Sriraman Tallam To: GCC Patches , "H.J. Lu" , "Zamyatin, Igor" , David Li X-Gm-Message-State: ALoCoQkT3g0GaHGleG/8kfO3q1US9sxUDD5Hk7FN+3krTSGUU+v0U5jAIRKBloZrqzjn/ojXfxwRsz6dREp7nVATScYYBoYbWRPCPddb7lBf2fPnVjxNR6a/gLxg3Yoh0+1liA2nwkfZqZUHYbOVvosmqvRZCQqvEcllIC8fm9Fn8azwUUPBlrY2/se54qIgAGELUnRTDb2I X-IsSubscribed: yes 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 Hi, Currently, function multiversioning determines that two functions are different by comparing the arch type and isa flags that are set after the target string is processed. This leads to cases where the versions become identical when the command-line target options are altered. For example, these two versions: __attribute__ target (("sse4.2"))) int foo () { } __attribute__ target (("popcnt"))) int foo () { } become identical when -mpopcnt and -msse4.2 are used while building, leading to build errors. To avoid this, I have modified the function version determination to just compare the target string. Patch attached. Is this alright to submit? Thanks, -Sri. * config/i386/i386.c (ix86_function_versions): Use target string to check for function versions instead of target flags. Index: config/i386/i386.c =================================================================== --- config/i386/i386.c (revision 193486) +++ config/i386/i386.c (working copy) @@ -28646,47 +28646,6 @@ dispatch_function_versions (tree dispatch_decl, return 0; } -/* This function returns true if FN1 and FN2 are versions of the same function, - that is, the targets of the function decls are different. This assumes - that FN1 and FN2 have the same signature. */ - -static bool -ix86_function_versions (tree fn1, tree fn2) -{ - tree attr1, attr2; - struct cl_target_option *target1, *target2; - - if (TREE_CODE (fn1) != FUNCTION_DECL - || TREE_CODE (fn2) != FUNCTION_DECL) - return false; - - attr1 = DECL_FUNCTION_SPECIFIC_TARGET (fn1); - attr2 = DECL_FUNCTION_SPECIFIC_TARGET (fn2); - - /* Atleast one function decl should have target attribute specified. */ - if (attr1 == NULL_TREE && attr2 == NULL_TREE) - return false; - - if (attr1 == NULL_TREE) - attr1 = target_option_default_node; - else if (attr2 == NULL_TREE) - attr2 = target_option_default_node; - - target1 = TREE_TARGET_OPTION (attr1); - target2 = TREE_TARGET_OPTION (attr2); - - /* target1 and target2 must be different in some way. */ - if (target1->x_ix86_isa_flags == target2->x_ix86_isa_flags - && target1->x_target_flags == target2->x_target_flags - && target1->arch == target2->arch - && target1->tune == target2->tune - && target1->x_ix86_fpmath == target2->x_ix86_fpmath - && target1->branch_cost == target2->branch_cost) - return false; - - return true; -} - /* Comparator function to be used in qsort routine to sort attribute specification strings to "target". */ @@ -28799,6 +28758,52 @@ ix86_mangle_function_version_assembler_name (tree return get_identifier (assembler_name); } +/* This function returns true if FN1 and FN2 are versions of the same function, + that is, the target strings of the function decls are different. This assumes + that FN1 and FN2 have the same signature. */ + +static bool +ix86_function_versions (tree fn1, tree fn2) +{ + tree attr1, attr2; + const char *attr_str1, *attr_str2; + char *target1, *target2; + bool result; + + if (TREE_CODE (fn1) != FUNCTION_DECL + || TREE_CODE (fn2) != FUNCTION_DECL) + return false; + + attr1 = lookup_attribute ("target", DECL_ATTRIBUTES (fn1)); + attr2 = lookup_attribute ("target", DECL_ATTRIBUTES (fn2)); + + /* Atleast one function decl should have the target attribute specified. */ + if (attr1 == NULL_TREE && attr2 == NULL_TREE) + return false; + + /* If one function does not have a target attribute, these are versions. */ + if (attr1 == NULL_TREE || attr2 == NULL_TREE) + return true; + + attr_str1 = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr1))); + attr_str2 = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr2))); + + target1 = sorted_attr_string (attr_str1); + target2 = sorted_attr_string (attr_str2); + + /* The sorted target strings must be different for fn1 and fn2 + to be versions. */ + if (strcmp (target1, target2) == 0) + result = false; + else + result = true; + + free (target1); + free (target2); + + return result; +} + static tree ix86_mangle_decl_assembler_name (tree decl, tree id) {