From patchwork Tue Feb 6 10:18:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 197303 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1441648dyb; Tue, 6 Feb 2024 02:19:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IHkjdOibpOBIaj8/YAVXGWTVCUPRe85SbelkgkYsbJ4nduM2CNBQPj4M8GNNHhZrQ2PxXz8 X-Received: by 2002:ad4:5f49:0:b0:68c:928e:6dac with SMTP id p9-20020ad45f49000000b0068c928e6dacmr1847967qvg.58.1707214782854; Tue, 06 Feb 2024 02:19:42 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707214782; cv=pass; d=google.com; s=arc-20160816; b=ETZWDSN+CgOYk90o2Qydwl4aYl2GKmb6FR9X2HIO6rAFa1zWLxWJrCJVwpsr5KjqFB uQARocfplPzV+OtmWSTFbrQKoIkKad0lP7b0EGGl5P4E5SArlquIPuIFe100qpzyItEI GPhcvsyUj7IEiZ53+kXzGwOhuJHjNv3Ym758JuXQtokyhk67ivT7z7p8rpWaQhsAlF22 GHq74C6c37OppEZ+fb2yJyDOMeXOIa+ZWB6l9pN8sN6pWNkU7Ju224jZtaKoISAX2Siw cGwERUlkIQDDToIbeNB+A1EwlDQ3oV0cpKCth0/6oqY9mvXYeOu47xydHnSQphosG6sJ TVzw== 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=DusFYf2h9ssZUnKnYyFKORdDYmO8mKw4XO3s2wU5oXE=; fh=stk2CkBstt0IhxMQ8y7FOjjdOQLSA5uCDO0hlx6JfsI=; b=AbOZ96FqHjLf0w4bpk4RtturnePgNBxkEFA0JWakiwheFe6bFV1avj+zkwTJnzVzR7 6c/9+xreGqBOfbzwUurPpKZu3P9A1t8J0al+rls+B/363NpLbkRsYcVPWELdgazzMn+a bFziCP6iwrf2vhsJlSaeq12aDzXv9RlxY9YlIebdL+byc3lNoiZk6F7C3NWOQp8RYxiD 6GU/na7h8jr+RvE3jx2dTLR0l9W2B0ygtp+beVQNnnodKS/oCyvMtdZXIcuLVEZe9ter ScDXRVS1KzzC+S7wiBK+/TICAnHpXnacOxlCwLdnE6bPVQ5/szZs5kbJVs1OEJNuhMQu eX5Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=bESXYoYf; 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 X-Forwarded-Encrypted: i=1; AJvYcCWoN9Y7MsF3eE5noz9yMFK7DeyahJrvLSlIL2cQzyglUZeiyQs3miKmUY93j0Dpx4cwQZdEJ710Zq9vPlwanMYxBFG84Q== Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id o7-20020ad45c87000000b0068cb809bf8asi61275qvh.352.2024.02.06.02.19.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 02:19:42 -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=bESXYoYf; 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 8FCAA3858D33 for ; Tue, 6 Feb 2024 10:19:42 +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.129.124]) by sourceware.org (Postfix) with ESMTPS id 2AD253858D33 for ; Tue, 6 Feb 2024 10:18:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2AD253858D33 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 2AD253858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707214734; cv=none; b=rgx1b0Ygq7vW4kQh1c5Tsv3DZ1vQ9LU+1FCxhKi96SCOe3tL6y3vwmDhrzc/xa9SN4fGf6t2JDG0FTX0Ih2OBG/WDpY5LVT3y0OQVvwXMWchrcF522/OxNHydzNXyZLZuHeFekZmCxnZvpIjQscDxudYwsexy1vj6HSmedM/SCE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707214734; c=relaxed/simple; bh=Wsnztr9QP4I8+XyKa+NHCriBZL0Ym5azNy/Q1oqMB7Y=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=ejvxGN/qHayeoOZzwwwBH6vpdVsP4BcobIo3pBKK+EnsoNjju1T5ZVdB4O0p1LjTDm3rFI0ukhTvRpHEdHlxIpI1Yg9Kc14nNFNsdu1r4eNrOZo7k0ydW1jxB105e1sk3BOg/0Nrr2mlcxCt3lxkLJiClaRctd3fz30ucMy3b9Y= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707214731; 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=DusFYf2h9ssZUnKnYyFKORdDYmO8mKw4XO3s2wU5oXE=; b=bESXYoYfWolIBqCj71nZlyvUwMSABOwSPx2rf3PgCB67a0DuOcd2QkjKEeJshpRAG8seuB UIe1c95fWKjb/97zpNhtHSifiyD1TLsSX2PwE6BKUsBt8mA5O/3jaz/osdlLsccio/OKx5 X5Yo+/s8G18iT19A+yXulcYxEP8/TPE= 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-641-pOT5QXsxO2SHwClH0zh2Hg-1; Tue, 06 Feb 2024 05:18:48 -0500 X-MC-Unique: pOT5QXsxO2SHwClH0zh2Hg-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 68A71837225; Tue, 6 Feb 2024 10:18:48 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.70]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2C209C07F51; Tue, 6 Feb 2024 10:18:48 +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 416AIj2V3214879 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 6 Feb 2024 11:18:46 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 416AIjsP3214878; Tue, 6 Feb 2024 11:18:45 +0100 Date: Tue, 6 Feb 2024 11:18:44 +0100 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] lower-bitint: Encode address space qualifiers in VIEW_CONVERT_EXPRs [PR113736] 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.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_H2, 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: 1790144448077502437 X-GMAIL-MSGID: 1790144448077502437 Hi! As discussed in the PR, e.g. build_fold_addr_expr needs TYPE_ADDR_SPACE on the outermost reference rather than just on the base, so the following patch makes sure to propagate the address space from the accessed var to the MEM_REFs and/or VIEW_CONVERT_EXPRs used to access those. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-02-06 Jakub Jelinek PR tree-optimization/113736 * gimple-lower-bitint.cc (bitint_large_huge::limb_access): Use var's address space for MEM_REF or VIEW_CONVERT_EXPRs. * gcc.dg/bitint-86.c: New test. Jakub --- gcc/gimple-lower-bitint.cc.jj 2024-02-05 10:57:32.946941767 +0100 +++ gcc/gimple-lower-bitint.cc 2024-02-05 11:41:28.352436669 +0100 @@ -601,12 +601,17 @@ bitint_large_huge::limb_access (tree typ { tree atype = (tree_fits_uhwi_p (idx) ? limb_access_type (type, idx) : m_limb_type); + tree ltype = m_limb_type; + addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (var)); + if (as != TYPE_ADDR_SPACE (ltype)) + ltype = build_qualified_type (ltype, TYPE_QUALS (ltype) + | ENCODE_QUAL_ADDR_SPACE (as)); tree ret; if (DECL_P (var) && tree_fits_uhwi_p (idx)) { tree ptype = build_pointer_type (strip_array_types (TREE_TYPE (var))); unsigned HOST_WIDE_INT off = tree_to_uhwi (idx) * m_limb_size; - ret = build2 (MEM_REF, m_limb_type, + ret = build2 (MEM_REF, ltype, build_fold_addr_expr (var), build_int_cst (ptype, off)); TREE_THIS_VOLATILE (ret) = TREE_THIS_VOLATILE (var); @@ -615,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, m_limb_type, TREE_OPERAND (var, 0), + = build2 (MEM_REF, ltype, 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) @@ -633,10 +638,10 @@ bitint_large_huge::limb_access (tree typ { unsigned HOST_WIDE_INT nelts = CEIL (tree_to_uhwi (TYPE_SIZE (type)), limb_prec); - tree atype = build_array_type_nelts (m_limb_type, nelts); + tree atype = build_array_type_nelts (ltype, nelts); var = build1 (VIEW_CONVERT_EXPR, atype, var); } - ret = build4 (ARRAY_REF, m_limb_type, var, idx, NULL_TREE, NULL_TREE); + ret = build4 (ARRAY_REF, ltype, var, idx, NULL_TREE, NULL_TREE); } if (!write_p && !useless_type_conversion_p (atype, m_limb_type)) { --- gcc/testsuite/gcc.dg/bitint-86.c.jj 2024-02-05 12:11:03.582868774 +0100 +++ gcc/testsuite/gcc.dg/bitint-86.c 2024-02-05 12:15:14.322401544 +0100 @@ -0,0 +1,40 @@ +/* PR tree-optimization/113736 */ +/* { dg-do compile { target bitint } } */ +/* { dg-options "-O2 -std=gnu23 -w" } */ + +#if __BITINT_MAXWIDTH__ >= 710 +struct S { _BitInt(710) a; }; +struct T { struct S b[4]; }; + +#ifdef __x86_64__ +#define SEG __seg_gs +#elif defined __i386__ +#define SEG __seg_fs +#else +#define SEG +#endif + +void +foo (__seg_gs struct T *p) +{ + struct S s; + p->b[0] = s; +} + +void +bar (__seg_gs struct T *p, _BitInt(710) x, int y, double z) +{ + p->b[0].a = x + 42; + p->b[1].a = x << y; + p->b[2].a = x >> y; + p->b[3].a = z; +} + +int +baz (__seg_gs struct T *p, _BitInt(710) x, _BitInt(710) y) +{ + return __builtin_add_overflow (x, y, &p->b[1].a); +} +#else +int i; +#endif