From patchwork Wed Dec 13 09:21:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 82040 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 195CB385DC33 for ; Wed, 13 Dec 2023 09:22:11 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 9E285385DC31 for ; Wed, 13 Dec 2023 09:21:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9E285385DC31 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9E285385DC31 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702459311; cv=none; b=PqXz4ftXC3r7vpQ62tVZeOt23UFqFeQrh3Xp2CQZiC2/E1j+h9wjnUne16quz2oL01gHhBH/Yit9Hv+IC2vO6jl9U/a3KANya5vsdhEwJwH2ObH5trvq8+FjeXD7MdrnkxbIRkzw8CrM9dCoeScWPfy1rMci0lc/AnzpHclXtXw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702459311; c=relaxed/simple; bh=NMV7uvoMo1aY3655wlW03VBlA6/WAh3TXqDEDZwKOXA=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=M0XMG1HWqdWs6I+06mIGn4MvXy5S8corg5ZNElFTJOpKCkdNpTLfeChKGrG+KLNV8h20xD/iVycHyy8RMtZwE7NJzF9+0Qd4h1KimIAeIAA32ByrUDpW9SDNVY/3SF4ry9ZR9zdjNeInY8uKJOOtBrywQDWMMVjQyuJHTfbLk4g= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702459308; 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; bh=4Kv8oqlQXxNlC1fRJPklcP5nhf+LJpwqTSeUSRniX5c=; b=H2LVJhpoRBCgtAa8TCMo6o615Z2Gao0m13w4LP67MrEdalwGG2jDcHSIt2odBiiYd60bq0 FMzZWt45d8oknR7opl+wB4kOv9SusPWCujSId5/6nOSiuAZhs86x3pJlpsM0RxJweTR5Pk f/qVuTH13uRdzEW9i2vFNmMlaF8tvXI= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-612-7bmwB62yMQukA3WYTGGEkg-1; Wed, 13 Dec 2023 04:21:47 -0500 X-MC-Unique: 7bmwB62yMQukA3WYTGGEkg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BEFEE8871C2; Wed, 13 Dec 2023 09:21:46 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.92]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8300C1121306; Wed, 13 Dec 2023 09:21:46 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 3BD9LhVH2489750 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 13 Dec 2023 10:21:44 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3BD9LhEa2489749; Wed, 13 Dec 2023 10:21:43 +0100 Date: Wed, 13 Dec 2023 10:21:43 +0100 From: Jakub Jelinek To: Uros Bizjak , Hongtao Liu Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] i386: Make most MD builtins nothrow, leaf [PR112962] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=0.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, MEDICAL_SUBJECT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Hi! The following patch makes most of x86 MD builtins nothrow,leaf (like most middle-end builtins are). For -fnon-call-exceptions it doesn't nothrow, better might be to still add it if the builtins don't read or write memory and can't raise floating point exceptions, but we don't have such information readily available, so the patch uses just !flag_non_call_exceptions for now. Not sure if we shouldn't have some exceptions for the leaf attribute, e.g. wonder about EMMS/FEMMS and the various xsave/xrstor etc. builtins, pedantically none of those builtins do anything that leaf functions are forbidden to do (having callbacks, calling functions from current TU, longjump into the current TU), but sometimes non-leaf is also used on really complex functions to prevent some unwanted optimizations. That said, haven't run into any problems as is with the patch. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2023-12-13 Jakub Jelinek PR target/112962 * config/i386/i386-builtins.cc (ix86_builtins): Increase by one element. (def_builtin): If not -fnon-call-exceptions, set TREE_NOTHROW on the builtin FUNCTION_DECL. Add leaf attribute to DECL_ATTRIBUTES. (ix86_add_new_builtins): Likewise. Jakub --- gcc/config/i386/i386-builtins.cc.jj 2023-10-13 19:34:43.767837029 +0200 +++ gcc/config/i386/i386-builtins.cc 2023-12-12 12:20:50.980071085 +0100 @@ -221,7 +221,7 @@ ix86_get_builtin_func_type (enum ix86_bu } /* Table for the ix86 builtin decls. */ -static GTY(()) tree ix86_builtins[(int) IX86_BUILTIN_MAX]; +static GTY(()) tree ix86_builtins[(int) IX86_BUILTIN_MAX + 1]; struct builtin_isa ix86_builtins_isa[(int) IX86_BUILTIN_MAX]; @@ -295,6 +295,12 @@ def_builtin (HOST_WIDE_INT mask, HOST_WI NULL, NULL_TREE); ix86_builtins[(int) code] = decl; ix86_builtins_isa[(int) code].set_and_not_built_p = false; + if (!flag_non_call_exceptions) + TREE_NOTHROW (decl) = 1; + if (ix86_builtins[(int) IX86_BUILTIN_MAX] == NULL_TREE) + ix86_builtins[(int) IX86_BUILTIN_MAX] + = build_tree_list (get_identifier ("leaf"), NULL_TREE); + DECL_ATTRIBUTES (decl) = ix86_builtins[(int) IX86_BUILTIN_MAX]; } else { @@ -393,6 +399,12 @@ ix86_add_new_builtins (HOST_WIDE_INT isa TREE_READONLY (decl) = 1; if (ix86_builtins_isa[i].pure_p) DECL_PURE_P (decl) = 1; + if (!flag_non_call_exceptions) + TREE_NOTHROW (decl) = 1; + if (ix86_builtins[(int) IX86_BUILTIN_MAX] == NULL_TREE) + ix86_builtins[(int) IX86_BUILTIN_MAX] + = build_tree_list (get_identifier ("leaf"), NULL_TREE); + DECL_ATTRIBUTES (decl) = ix86_builtins[(int) IX86_BUILTIN_MAX]; } }