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: 209434 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:fa17:b0:10a:f01:a869 with SMTP id ju23csp1294926dyc; Mon, 4 Mar 2024 00:51:49 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUNGj8i6nkR6wXyIwoz8SZTCua9BDEgvQMwNwp0D0DMhFv67dRVouDV65+RFF1gDbijc4tTo9NcWZ2vYeoXjF2pdzLxGA== X-Google-Smtp-Source: AGHT+IHLUNUVNnJimGXq1RtCdFVM6ins8bhblHgWdUb2bf9VzYRyjtiTr2j+a+NCY+BRaYl7Sl1h X-Received: by 2002:a0c:bf09:0:b0:68f:6f92:d291 with SMTP id m9-20020a0cbf09000000b0068f6f92d291mr9227982qvi.4.1709542308832; Mon, 04 Mar 2024 00:51:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709542308; cv=pass; d=google.com; s=arc-20160816; b=cFyq5RL+NDrDFc+hBzKPDLoZkGGujGn4RK0NWgeFBEf367Nzyyc1PpEdGgix7yKqJU fUclMzragP6+TZlwc+Cswqyvbp+f9+UYrEgdK0o6FYK4VExB7ZBBIFhQJTyiP0jROWhA RRcLSEuoNyNNAKTP5CqspjPWjflC+1O6QhbV3JYGfXoYHQXSn7sA3JPQOBF3XxITTIDU /UwoHhe7ZDBRv2BHaBndUBPDzc9mCGw2mm52Gd9hGyXQneYtcPMOKLLcjMVsyc5L88EQ o1zCxBfSNwGxhliXZmnEyfmbTs8P2UaDRmk5prbfdpLKSt+qD8HbIm8U4/obrNDSr5UC rjag== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:reply-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=cC6zAyziV5+O74y308XCGfu/MgozeaHxLszEsMl13jI=; fh=FCjeRajqaQYHMkQtfIia8KT5yBac53mYOLLyJhYG/AY=; b=FrZc5N6E+mx23adxiFTynLsyReiA+mre9VN+wh5fhGZzAzZfb2AKEtwWg+q1TlL4tZ SvC2nHdnnLvR3QTaxO31Yl3Va55NPg2RkpxGAsShtizrQHpUQZUdE/eh7kbpCM43HxG0 SXEvX/e+gLC5k3mjDj44/pV+UCuLcNlQ55STP0n7NOTDxMdcZeWqqIUIVtMJpwmXqQTt NkD2IT5vT6xNWXhcifqSyORsRZQIu30dGSmRVo8EkuSYs/RN2HNR7sqZ+u4HY3lkqps9 dUszPOhBsj6efBP9RZdDrG58WTLbj2y71YZ72vWhWtFz49BEBu3RpbPu+4if3nuEGrOo UCTQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QzvSS05s; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id fv6-20020a056214240600b00690197c48e2si9576913qvb.236.2024.03.04.00.51.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 00:51:48 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QzvSS05s; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 892913858C54 for ; Mon, 4 Mar 2024 08:51:48 +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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792585035908511319 X-GMAIL-MSGID: 1792585035908511319 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; +}