From patchwork Tue Nov 19 23:53:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1197692 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-514086-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="YpQ/YAHg"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="Eg70tG1e"; dkim-atps=neutral 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 47HjN329xQz9s7T for ; Wed, 20 Nov 2019 10:54:09 +1100 (AEDT) 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:cc:subject:message-id:reply-to:mime-version :content-type:content-transfer-encoding; q=dns; s=default; b=jUY mExyWgElHtV0G2IHasNdRUr7kUXzlOiKdcUSivaFNAXKHyhYL6y2Y2wH0mhI2HPZ RrizZyRMg1fl+as4ClSt+mmITg5FkBvlkakZYVfmvp7mbVV01jWSEwvYbJqkWvOg Hwx1xQAjT++4qTUG4X1kpx0Zw8KFfB1ICtMnzEyE= 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:cc:subject:message-id:reply-to:mime-version :content-type:content-transfer-encoding; s=default; bh=Xqyr1yONc LJfPN/ZLYI/9fJRRGE=; b=YpQ/YAHg+//NWLJsgpo0is3K1NTGhQ0Be62bv6Lk9 KBNOfpplPADLTXa90NqGlgx9tRSEmShFpYjg0bbBwtUcNLTdxcbKYz8LPsKB2eSd 8solwVKivX4QGiu0PX/wWM+ZMdiYZcw2BH3p2ZN1zBJ0TIInsKXfBavsRh2/Ucow L0= Received: (qmail 120080 invoked by alias); 19 Nov 2019 23:54:00 -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 120072 invoked by uid 89); 19 Nov 2019 23:54:00 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-7.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: us-smtp-delivery-1.mimecast.com Received: from us-smtp-1.mimecast.com (HELO us-smtp-delivery-1.mimecast.com) (205.139.110.61) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 19 Nov 2019 23:53:58 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1574207637; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=a+9h9lOKQk/IFAZKCoaXm0kVwGk337e3V938DK0MP28=; b=Eg70tG1eMOmPhndJ9UQAaXKnKsHgp84uI0PISWbpgPNMN+TwD59tODqV6gVqU+0/UZM/Wd 2wCxjHxHv3EJSYL7EctHH5vNiQpAhlfJ4qW1f4lsqEvlsTphM6D82kqcUgQgThVK2PW8U/ UM+e2F5Mu9oSInV6tP/9Oqob3OCBdsU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-414-aM3dp-VeM_CQ0CAm1uHGPA-1; Tue, 19 Nov 2019 18:53:53 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B9E41107ACC7; Tue, 19 Nov 2019 23:53:52 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-21.ams2.redhat.com [10.36.116.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 625732B89C; Tue, 19 Nov 2019 23:53:52 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id xAJNroHG029834; Wed, 20 Nov 2019 00:53:50 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id xAJNrlB8029833; Wed, 20 Nov 2019 00:53:47 +0100 Date: Wed, 20 Nov 2019 00:53:47 +0100 From: Jakub Jelinek To: Uros Bizjak , hjl.tools@gmail.com Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix up arch= handling in x86 target attribute (PR target/90867) Message-ID: <20191119235347.GR4650@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 User-Agent: Mutt/1.11.3 (2019-02-01) X-Mimecast-Spam-Score: 0 Content-Disposition: inline X-IsSubscribed: yes Hi! The arch= handling in target attribute right now clears almost all isa_flags and all isa_flags2, so that later call to ix86_option_override_internal can set just the isa options for the specific arch and nothing else. Unfortunately, it doesn't work, because next to the ix86_isa_flags{,2} we have also ix86_isa_flags{,2}_explicit bitmask and in ix86_option_override_internal and say for arch=x86_64 will not try to set sse2 isa when we cleared it in ix86_isa_flags but kept it set in ix86_isa_flags_explicit. So, the testcase works fine with -O2, but doesn't work with -O2 -msse2, in the former case ix86_isa_flags_explicit doesn't have MASK_SSE2 bit set, but in the latter case it does, so in the former case we end up with MASK_SSE2 in ix86_isa_flags, in the latter not in the function with target attribute. The following patch thus clears both ix86_isa_flags{,2} and corresponding ix86_isa_flags{,2}_explicit. Also, so that say target ("arch=x86_64", "avx") works, the clearing is done when actually seeing the arch=, not at the end. target ("avx", "arch=x86_64") will still not enable avx, like before, though. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2019-11-19 Jakub Jelinek PR target/90867 * config/i386/i386-options.c (ix86_valid_target_attribute_tree): Don't clear opts->x_ix86_isa_flags{,2} here... (ix86_valid_target_attribute_inner_p): ... but here when seeing arch=. Also clear opts->x_ix86_isa_flags{,2}_explicit. * gcc.target/i386/pr90867.c: New test. Jakub --- gcc/config/i386/i386-options.c.jj 2019-11-18 12:07:54.672405129 +0100 +++ gcc/config/i386/i386-options.c 2019-11-19 18:43:36.426606458 +0100 @@ -1147,7 +1147,25 @@ ix86_valid_target_attribute_inner_p (tre ret = false; } else - p_strings[opt] = xstrdup (p + opt_len); + { + p_strings[opt] = xstrdup (p + opt_len); + if (opt == IX86_FUNCTION_SPECIFIC_ARCH) + { + /* If arch= is set, clear all bits in x_ix86_isa_flags, + except for ISA_64BIT, ABI_64, ABI_X32, and CODE16 + and all bits in x_ix86_isa_flags2. */ + opts->x_ix86_isa_flags &= (OPTION_MASK_ISA_64BIT + | OPTION_MASK_ABI_64 + | OPTION_MASK_ABI_X32 + | OPTION_MASK_CODE16); + opts->x_ix86_isa_flags_explicit &= (OPTION_MASK_ISA_64BIT + | OPTION_MASK_ABI_64 + | OPTION_MASK_ABI_X32 + | OPTION_MASK_CODE16); + opts->x_ix86_isa_flags2 = 0; + opts->x_ix86_isa_flags2_explicit = 0; + } + } } else if (type == ix86_opt_enum) @@ -1225,18 +1243,8 @@ ix86_valid_target_attribute_tree (tree f /* If we are using the default tune= or arch=, undo the string assigned, and use the default. */ if (option_strings[IX86_FUNCTION_SPECIFIC_ARCH]) - { - opts->x_ix86_arch_string - = ggc_strdup (option_strings[IX86_FUNCTION_SPECIFIC_ARCH]); - - /* If arch= is set, clear all bits in x_ix86_isa_flags, - except for ISA_64BIT, ABI_64, ABI_X32, and CODE16. */ - opts->x_ix86_isa_flags &= (OPTION_MASK_ISA_64BIT - | OPTION_MASK_ABI_64 - | OPTION_MASK_ABI_X32 - | OPTION_MASK_CODE16); - opts->x_ix86_isa_flags2 = 0; - } + opts->x_ix86_arch_string + = ggc_strdup (option_strings[IX86_FUNCTION_SPECIFIC_ARCH]); else if (!orig_arch_specified) opts->x_ix86_arch_string = NULL; --- gcc/testsuite/gcc.target/i386/pr90867.c.jj 2019-11-19 18:49:11.746592189 +0100 +++ gcc/testsuite/gcc.target/i386/pr90867.c 2019-11-19 18:48:17.271406789 +0100 @@ -0,0 +1,30 @@ +/* PR target/90867 */ +/* { dg-do run { target lp64 } } */ +/* { dg-options "-O2 -msse2" } */ + +unsigned long long freq = 3600000000UL; /* 3.6 GHz = 3600.0 MHz */ + +__attribute__((noipa)) void +bar (double x) +{ + static double d = 3600000000.0; + if (x != d) + __builtin_abort (); + d /= 1000.0; +} + +__attribute__ ((target ("arch=x86-64"))) int +foo () +{ + bar ((double) freq); + bar (1e-3 * freq); + bar (1e-6 * freq); + bar (1e-9 * freq); + return 0; +} + +int +main () +{ + return foo (); +}