From patchwork Wed Mar 27 10:26:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1916675 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=DFbV/GHm; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4V4NBw247zz1yXq for ; Wed, 27 Mar 2024 21:27:04 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4D0563858291 for ; Wed, 27 Mar 2024 10:27:02 +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 63D813858C98 for ; Wed, 27 Mar 2024 10:26:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 63D813858C98 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 63D813858C98 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=1711535208; cv=none; b=DRE3V9xDs+ZKVE7FtLY/fKYX0BBrrV8/uWx7ERmLikYl3SZzLeU8Bufctg7BysZMhnZWMmpLPP7i129SzYZ6FViRfDbL+qXnm2WmTIoxs724gbxWlxWD63n06c7nETRlC7hqnPMMAOubTFT9VpNrJS5EpuQ6MQ0OWgoK4mrPFsU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711535208; c=relaxed/simple; bh=+fbRX3W58hBWYNbPPKOPgprad4R1Ktf4X2mE6EhdL5g=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=xyKMXcP4nUi9uUkyWxQziCc2RdJ2ViTys37W1vV8Z7y7bf0LzIRX5E6awlUnoa6/gAaM+iXU4wWIXqLm5LUPxKJrEUI39JDAz2+1iSqAPR+Yk6Cip0VoxeqpESlG9BimrKngqI07SVOCZ788Kk4qC6cBS4Mh2CjxsxUGeufiwHM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711535205; 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=hg2Q2JlU7bcO/oDZ1yBUzst2Df9RXsn+BifOGNcKa5k=; b=DFbV/GHmW72liOaIJDfAlbeGPSxRICk1MWGDB4HBQFW7TI6rLxaJpK+NAM+RO4h2KDte4R cCugiBDf4gKu5VyfRzXkaRRc2Gc68NgN72lHhnJhfFiGnvUsBxiKmMFXsHbHbGw1KUt+QI M1Jld0oJdTBWYTlAfY+PFOnnLz53rew= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-592-MH6nss--OVCNfZ2FNQNVNQ-1; Wed, 27 Mar 2024 06:26:43 -0400 X-MC-Unique: MH6nss--OVCNfZ2FNQNVNQ-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (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 837371C07269 for ; Wed, 27 Mar 2024 10:26:43 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.57]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4026E492BC8; Wed, 27 Mar 2024 10:26:43 +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 42RAQaJI1687722 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 27 Mar 2024 11:26:37 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 42RAQaTE1687721; Wed, 27 Mar 2024 11:26:36 +0100 Date: Wed, 27 Mar 2024 11:26:36 +0100 From: Jakub Jelinek To: "Joseph S. Myers" Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c-family: Cast __atomic_load_*/__atomic_exchange_* result to _BitInt rather then VCE it [PR114469] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Hi! As written in the PR, torture/bitint-64.c test fails with -O2 -flto and the reason is that on _BitInt arches where the padding bits are undefined, the padding bits in the _Atomic vars are also undefined, but when __atomic_load or __atomic_exchange on a _BitInt _Atomic variable with some padding bits is lowered into __atomic_load_{1,2,4,8,16} or __atomic_exchange_*, the mode precision unsigned result is VIEW_CONVERT_EXPR converted to _BitInt and because of the VCE nothing actually sign/zero extends it as needed for later uses - the var is no longer addressable and expansion assumes such automatic vars are properly extended. The following patch fixes that by using NOP_EXPR on it (the VIEW_CONVERT_EXPR after it will then be optimized away during gimplification, didn't want to repeat it in the code as else result = build1 (VIEW_CONVERT_EXPR, ...); twice. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-03-26 Jakub Jelinek PR tree-optimization/114469 * c-common.cc (resolve_overloaded_builtin): For _BitInt result on !extended targets convert result to the _BitInt type before using VIEW_CONVERT_EXPR. Jakub --- gcc/c-family/c-common.cc.jj 2024-03-08 09:29:30.257747832 +0100 +++ gcc/c-family/c-common.cc 2024-03-26 14:30:59.493031026 +0100 @@ -8461,7 +8461,19 @@ resolve_overloaded_builtin (location_t l if (new_return) { /* Cast function result from I{1,2,4,8,16} to the required type. */ - result = build1 (VIEW_CONVERT_EXPR, TREE_TYPE (new_return), result); + if (TREE_CODE (TREE_TYPE (new_return)) == BITINT_TYPE) + { + struct bitint_info info; + unsigned prec = TYPE_PRECISION (TREE_TYPE (new_return)); + targetm.c.bitint_type_info (prec, &info); + if (!info.extended) + /* For _BitInt which has the padding bits undefined + convert to the _BitInt type rather than VCE to force + zero or sign extension. */ + result = build1 (NOP_EXPR, TREE_TYPE (new_return), result); + } + result + = build1 (VIEW_CONVERT_EXPR, TREE_TYPE (new_return), result); result = build2 (MODIFY_EXPR, TREE_TYPE (new_return), new_return, result); TREE_SIDE_EFFECTS (result) = 1;