From patchwork Mon Mar 4 08:51:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1907418 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=QzvSS05s; 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 4TpC9H51HRz23fC for ; Mon, 4 Mar 2024 19:51:31 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 469283858413 for ; Mon, 4 Mar 2024 08:51:29 +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 0ECE73858D33 for ; Mon, 4 Mar 2024 08:51:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0ECE73858D33 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 0ECE73858D33 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=1709542270; cv=none; b=WlPg5uV8Gt+VCRVkCOsBzCLdru3AMXNZr+wd4VE/2X+NnPUgSM6mIy4NedIA+SmUH5O6vstM3eNl0dyv/m5wMnplpwE9pjF0RaLiMgCJsy6KPq3HhKcI64BbHnmm8gJ952voCy9LjUWVI9Tq3qSVIhSw1pirlT85B6DrHUtZ5N8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709542270; c=relaxed/simple; bh=iM5k6qhyezQJYMAwlJ0aQaw8nY16wUI3/YvinvqZWvw=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=s2bZh2RN/x8EEePU6+shjC1BCsE/8hR9yT5IaZEB6s3f8H/xr40eUxHS9kUN8kCSX25xHRtetB3qkbfgcpDo4uyqAIr29aMit6BYvuuEjXyffORaed9xTf9a+m+P8wIZQoNY7PIDNiGaUkgtdG3fBg5ssXOz+aD0GzR07xGQmJA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709542267; 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=cC6zAyziV5+O74y308XCGfu/MgozeaHxLszEsMl13jI=; b=QzvSS05simWEmK1FEOYWuerLh0EehV7x73s7AnHpWpGtmf73WQ579Jw1eadV00NzvbENPI qc/GSWsl79yG8mP3Hb14bRm/D3eShDxT85UqcYYX35l0yxfjhOZXH7Lb7MEroDkjtD9MxX FgG7mDWfO2nVWassCMb7D+72L43dOBA= 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-582-cOhRfEYqPxu5I2EpkTHR4A-1; Mon, 04 Mar 2024 03:51:04 -0500 X-MC-Unique: cOhRfEYqPxu5I2EpkTHR4A-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 3D6F1106D064; Mon, 4 Mar 2024 08:51:04 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.226.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 03A39C185C0; Mon, 4 Mar 2024 08:51:03 +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 4248p2bQ1793457 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 4 Mar 2024 09:51:02 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 4248p2eu1793456; Mon, 4 Mar 2024 09:51:02 +0100 Date: Mon, 4 Mar 2024 09:51:02 +0100 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] bitint: Fix tree node sharing bug [PR114209] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.7 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, T_SCC_BODY_TEXT_LINE 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! We ICE on the following testcase due to invalid tree sharing. The second hunk fixes that, the first one is from me looking around at other spots which might need end up with invalid tree sharing too. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-03-04 Jakub Jelinek PR middle-end/114209 * gimple-lower-bitint.cc (bitint_large_huge::limb_access): Call unshare_expr when creating a MEM_REF from MEM_REF. (bitint_large_huge::lower_stmt): Call unshare_expr. * gcc.dg/bitint-97.c: New test. Jakub --- gcc/gimple-lower-bitint.cc.jj 2024-03-01 11:04:44.623537149 +0100 +++ gcc/gimple-lower-bitint.cc 2024-03-03 19:18:30.017909558 +0100 @@ -620,7 +620,7 @@ bitint_large_huge::limb_access (tree typ else if (TREE_CODE (var) == MEM_REF && tree_fits_uhwi_p (idx)) { ret - = build2 (MEM_REF, ltype, TREE_OPERAND (var, 0), + = build2 (MEM_REF, ltype, unshare_expr (TREE_OPERAND (var, 0)), size_binop (PLUS_EXPR, TREE_OPERAND (var, 1), build_int_cst (TREE_TYPE (TREE_OPERAND (var, 1)), tree_to_uhwi (idx) @@ -5342,7 +5342,7 @@ bitint_large_huge::lower_stmt (gimple *s = build_qualified_type (ltype, TYPE_QUALS (ltype) | ENCODE_QUAL_ADDR_SPACE (as)); - rhs1 = build1 (VIEW_CONVERT_EXPR, ltype, mem); + rhs1 = build1 (VIEW_CONVERT_EXPR, ltype, unshare_expr (mem)); gimple_assign_set_rhs1 (stmt, rhs1); } else --- gcc/testsuite/gcc.dg/bitint-97.c.jj 2024-03-03 18:59:31.084588944 +0100 +++ gcc/testsuite/gcc.dg/bitint-97.c 2024-03-03 19:16:50.114284071 +0100 @@ -0,0 +1,18 @@ +/* PR middle-end/114209 */ +/* { dg-do compile { target bitint } } */ +/* { dg-options "-Og -std=c23 -fno-strict-aliasing" } */ +/* { dg-add-options float128 } */ +/* { dg-require-effective-target float128 } */ + +typedef signed char V __attribute__((__vector_size__(16))); +typedef _Float128 W __attribute__((__vector_size__(16))); + +_Float128 +foo (void *p) +{ + signed char c = *(_BitInt(128) *) p; + _Float128 f = *(_Float128 *) p; + W w = *(W *) p; + signed char r = ((union { W a; signed char b[16]; }) w).b[1]; + return r + f; +}