From patchwork Wed Jan 17 09:52:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 188751 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:42cf:b0:101:a8e8:374 with SMTP id q15csp799750dye; Wed, 17 Jan 2024 01:53:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IE4WHEmGMwYy9wyv7hDdHqeZQMf+pVYmn/Q5emMNIH0unu711N9M/xu+9tFcCh2SttlnMYo X-Received: by 2002:a05:620a:2620:b0:783:53f0:5084 with SMTP id z32-20020a05620a262000b0078353f05084mr8030504qko.9.1705485226664; Wed, 17 Jan 2024 01:53:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705485226; cv=pass; d=google.com; s=arc-20160816; b=j9VTJm9/nfveFMMUWqqC+KKsZKJzAwI3UWovnMR159TX7MADuX9cSd74b1N/aGFP1Q TCtJjqa/WtWtD4GdZQc+5zZN7rqV4Ww9a0vJHh8drX3gGi7ynFmL/lkRrtCsrurruKDG rBCyObrb2OfByi2JwLvVdBV1xuxznVPglcHMWnU5Jkhvv4EYPkYJYfZCIR4Zd6u9wi38 C2gDjqEPGC6v4mYTZmOniFTmyGlxRUA/qvlz9AFcGbiP8mI49coL9YKs68UTHWgaUpzG l8p47o3FX2ETlhx4Js61M76R17qtFWEf98wvd7A8hnv0bAqdOMmopL1cHHh3S+HK5EHb 5LnA== 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=l0iV6ibjeWFBvgA2U/houGYMIkMqPhguwx3nGHcyVjo=; fh=0Ub9zfDBeLI7BXT+FxfQFJoJGL6kK2GHTNWPjrbpzVA=; b=gMcwYUpy5MxHk5Qz9EthMS5uiAFkrRByfbSi1bgeRFc9AMTj1j7jBv4qGz+D+DGCBK s47/SLdsDLooYjxNP9XRwiGRSedyST/yNmUSfUwhV1Ab2zmA7Bx0NeRKcmNgmV1D7P7/ 8Va9S10NNfhA0fWR9F4boxcsuaYHeb4ji6wHD3KR3ZXX0EVdrhj2LVaB7kgTOrlfAZUj xfPkxzic4aKu/ihhuGUcBa03ip4TitAZVCSMdgXDJ2hINd7T38Cfnp/Vxn47tZ0vpzQx mjVpz8Pg5yh4cRnROvvAkpXh4yJ3kb/usQAIYDLb7M+vmcTPFN+oDuSMt6qieIOHQZx/ g0IA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QooQ64fh; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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. [8.43.85.97]) by mx.google.com with ESMTPS id j10-20020a37ef0a000000b0078154e525besi11308004qkk.485.2024.01.17.01.53.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 01:53:46 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QooQ64fh; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 5E08E3858C52 for ; Wed, 17 Jan 2024 09:53:46 +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 B81AE385842A for ; Wed, 17 Jan 2024 09:52:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B81AE385842A 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 B81AE385842A 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=1705485173; cv=none; b=joKiOtGQzqT2WGT0O5a7NqMuSCn806wbyNoWGy+KtAjJVb4xVYj2sGhuPkPW60ODk0rgIBLyFA34YDm2xuZnCAF8AIprIyAAKvKQycGuReIemGLhuYhG6FqjoQ7MyyyakkuuL2ZzDYIhMmBegxPumoHA6yU2L5HBB342sVIfIUM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705485173; c=relaxed/simple; bh=WijiYIGbUxDrGhl4NR7DHEVc2G92kmxrZ69H4kDKWl0=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=PC6voh6ow3lhHd+leZmtWA97sLzS2GLP6n6eMYEMhdQdgsylA4e/4hWMW5BuPnkdYD0rQUtYhUR6nTzVOQ6zOxCKlrkB/amOXFlN4wv3iQLj/sdREnqH6+j702CDM9js652JT4go4+YRTNlaISBVQfi4AjhWjY+bJ/4NZ74RJbY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705485171; 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=l0iV6ibjeWFBvgA2U/houGYMIkMqPhguwx3nGHcyVjo=; b=QooQ64fheGvpHP4xeraDnPBqxz+1tK3JerGuql8WR7BMxaHWyS9jbXkviP0hJLaZYCSNW9 7DGjl4Z+sRR+O9vfHEDmrBeIZYMm6mIF25YePoDgiXVo6EhdKENabHkVbU5UlnTFBxNkuR +8WWTmIN/hQEjEZdm87YBp4zj5e8BBs= 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-54-8HQNdtk8OzeeK4roQTdilg-1; Wed, 17 Jan 2024 04:52:47 -0500 X-MC-Unique: 8HQNdtk8OzeeK4roQTdilg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 1C92785A588; Wed, 17 Jan 2024 09:52:47 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.70]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C9F5E51E3; Wed, 17 Jan 2024 09:52: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 40H9qi8T2307234 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 17 Jan 2024 10:52:44 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 40H9qhXX2307233; Wed, 17 Jan 2024 10:52:43 +0100 Date: Wed, 17 Jan 2024 10:52:43 +0100 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Cc: Tobias Burnus Subject: [committed] openmp: Add OpenMP _BitInt support [PR113409] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_LOTSOFHASH, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, 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: 1788330877289846506 X-GMAIL-MSGID: 1788330877289846506 Hi! The following patch adds support for _BitInt iterators of OpenMP canonical loops (with the preexisting limitation that when not using compile time static scheduling the iterators in the library are at most unsigned long long or signed long, so one can't in the runtime/dynamic/guided etc. cases iterate more than what those types can represent, like is the case of e.g. __int128 iterators too) and the testcase also covers linear/reduction clauses for them. Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk. 2024-01-17 Jakub Jelinek PR middle-end/113409 * omp-general.cc (omp_adjust_for_condition): Handle BITINT_TYPE like INTEGER_TYPE. (omp_extract_for_data): Use build_bitint_type rather than build_nonstandard_integer_type if either iter_type or loop->v type is BITINT_TYPE. * omp-expand.cc (expand_omp_for_generic, expand_omp_taskloop_for_outer, expand_omp_taskloop_for_inner): Handle BITINT_TYPE like INTEGER_TYPE. * testsuite/libgomp.c/bitint-1.c: New test. Jakub --- gcc/omp-general.cc.jj 2024-01-04 09:10:56.590914073 +0100 +++ gcc/omp-general.cc 2024-01-16 16:08:15.160663134 +0100 @@ -115,7 +115,8 @@ omp_adjust_for_condition (location_t loc case NE_EXPR: gcc_assert (TREE_CODE (step) == INTEGER_CST); - if (TREE_CODE (TREE_TYPE (v)) == INTEGER_TYPE) + if (TREE_CODE (TREE_TYPE (v)) == INTEGER_TYPE + || TREE_CODE (TREE_TYPE (v)) == BITINT_TYPE) { if (integer_onep (step)) *cond_code = LT_EXPR; @@ -409,6 +410,7 @@ omp_extract_for_data (gomp_for *for_stmt loop->v = gimple_omp_for_index (for_stmt, i); gcc_assert (SSA_VAR_P (loop->v)); gcc_assert (TREE_CODE (TREE_TYPE (loop->v)) == INTEGER_TYPE + || TREE_CODE (TREE_TYPE (loop->v)) == BITINT_TYPE || TREE_CODE (TREE_TYPE (loop->v)) == POINTER_TYPE); var = TREE_CODE (loop->v) == SSA_NAME ? SSA_NAME_VAR (loop->v) : loop->v; loop->n1 = gimple_omp_for_initial (for_stmt, i); @@ -479,9 +481,17 @@ omp_extract_for_data (gomp_for *for_stmt else if (i == 0 || TYPE_PRECISION (iter_type) < TYPE_PRECISION (TREE_TYPE (loop->v))) - iter_type - = build_nonstandard_integer_type - (TYPE_PRECISION (TREE_TYPE (loop->v)), 1); + { + if (TREE_CODE (iter_type) == BITINT_TYPE + || TREE_CODE (TREE_TYPE (loop->v)) == BITINT_TYPE) + iter_type + = build_bitint_type (TYPE_PRECISION (TREE_TYPE (loop->v)), + 1); + else + iter_type + = build_nonstandard_integer_type + (TYPE_PRECISION (TREE_TYPE (loop->v)), 1); + } } else if (iter_type != long_long_unsigned_type_node) { @@ -747,7 +757,8 @@ omp_extract_for_data (gomp_for *for_stmt if (t && integer_zerop (t)) count = build_zero_cst (long_long_unsigned_type_node); else if ((i == 0 || count != NULL_TREE) - && TREE_CODE (TREE_TYPE (loop->v)) == INTEGER_TYPE + && (TREE_CODE (TREE_TYPE (loop->v)) == INTEGER_TYPE + || TREE_CODE (TREE_TYPE (loop->v)) == BITINT_TYPE) && TREE_CONSTANT (loop->n1) && TREE_CONSTANT (loop->n2) && TREE_CODE (loop->step) == INTEGER_CST) --- gcc/omp-expand.cc.jj 2024-01-03 11:51:39.095626210 +0100 +++ gcc/omp-expand.cc 2024-01-16 13:17:47.367928336 +0100 @@ -4075,7 +4075,7 @@ expand_omp_for_generic (struct omp_regio /* See if we need to bias by LLONG_MIN. */ if (fd->iter_type == long_long_unsigned_type_node - && TREE_CODE (type) == INTEGER_TYPE + && (TREE_CODE (type) == INTEGER_TYPE || TREE_CODE (type) == BITINT_TYPE) && !TYPE_UNSIGNED (type) && fd->ordered == 0) { @@ -7191,7 +7191,7 @@ expand_omp_taskloop_for_outer (struct om /* See if we need to bias by LLONG_MIN. */ if (fd->iter_type == long_long_unsigned_type_node - && TREE_CODE (type) == INTEGER_TYPE + && (TREE_CODE (type) == INTEGER_TYPE || TREE_CODE (type) == BITINT_TYPE) && !TYPE_UNSIGNED (type)) { tree n1, n2; @@ -7352,7 +7352,7 @@ expand_omp_taskloop_for_inner (struct om /* See if we need to bias by LLONG_MIN. */ if (fd->iter_type == long_long_unsigned_type_node - && TREE_CODE (type) == INTEGER_TYPE + && (TREE_CODE (type) == INTEGER_TYPE || TREE_CODE (type) == BITINT_TYPE) && !TYPE_UNSIGNED (type)) { tree n1, n2; --- libgomp/testsuite/libgomp.c/bitint-1.c.jj 2024-01-16 13:47:24.880153301 +0100 +++ libgomp/testsuite/libgomp.c/bitint-1.c 2024-01-16 16:04:43.242609845 +0100 @@ -0,0 +1,65 @@ +/* PR middle-end/113409 */ +/* { dg-do run { target bitint } } */ + +extern void abort (void); + +#if __BITINT_MAXWIDTH__ >= 1023 +typedef _BitInt(931) B931; +typedef _BitInt(1023) B1023; +#else +typedef _BitInt(31) B931; +typedef _BitInt(63) B1023; +#endif + +__attribute__((noipa)) B931 +bar (B931 x) +{ + return x; +} + +B931 +foo (B931 x) +{ + B931 r = 0; + B1023 l = 56wb; + #pragma omp parallel for reduction(+: r) linear(l : 3wb) + for (B931 i = 0; i < x; ++i) + { + r += bar (i); + l += 3wb; + } + if (l != (B1023) 56wb + x * 3wb) + abort (); + return r; +} + +B931 +baz (B931 a, B931 b, B931 c, B931 d, B931 e, B931 f) +{ + B931 r = 0; + #pragma omp parallel for collapse (2wb) reduction(+: r) + for (B931 i = a; i < b; i += c) + for (B931 j = d; j > e; j += f) +{ + r += (j - d) / f; +__builtin_printf ("%d\n", (int) r); +} + return r; +} + +int +main () +{ + if (foo (16wb) != (B931) 15wb * 16wb / 2 + || foo (256wb) != (B931) 255wb * 256wb / 2) + abort (); +#if __BITINT_MAXWIDTH__ >= 1023 + if (baz (5019676379303764570412381742937286053482001129028025397398691108125646744814606405323608429353439158482254231750681261083217232780938592007150824765654203477280876662295642053702075485153212701225737143207062700602509893062044376997132415613866154761073993220684129908568716699977wb, + 5019676379303764570412381742937286053482001129028025397398691108125646744814606405323608429353439158482254231750681261083217232780938592007150824765654203477280876662295642053702075485153212701225737143207062700602509893062044376997132415613866154761074023903103954348393149593648wb, + 398472984732984732894723wb, + 5145599438319070078334010989312672300490893251953772234670751860213136881221517063143096309285807356778798661066289865489661268190588670564647904159660341525674865064477335008915374460378741763629714814990575971883514175167056160470289039998140910732382754821232566561860399556131wb, + 5145599438319070078334010989312672300490893251953772234670751860213136881221517063143096309285807356778798661066289865489661268190588670564647904159660341525674865064477335008915374460378741763629714814990575971883514175167056160470289039995725068563774878643356388697468035164019wb, + -89475635874365784365784365347865347856wb) != (B931) 26wb * 27wb / 2wb * 77wb) + abort (); +#endif +}