From patchwork Sat Mar 23 07:55:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1915106 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=D9Ofe9xL; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; 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 [8.43.85.97]) (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 4V1s2K3d5kz1yXr for ; Sat, 23 Mar 2024 18:55:53 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 57D983858C33 for ; Sat, 23 Mar 2024 07:55:51 +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 139373858D1E for ; Sat, 23 Mar 2024 07:55:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 139373858D1E 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 139373858D1E 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=1711180531; cv=none; b=ERgoXnpJAZdINyWkUIysTYzM2QdN5iTF/eqKQ3CgJW6uTBpcq6dbNXUhTzEs0zmz980pZtiKhRwyZXrOW/XmbItG2Yd8ea4BrFmue0CQyeTaMRrRFRnvYDBAibRTKbvpyX8i9jZxKW8ctHverzqZ3O0GHKQ/rbkcZS61/UHOTDI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711180531; c=relaxed/simple; bh=8tyKNNl1Gk1g1BVu5NcPZny7w65TmpYLwkYzfTCJPZo=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=Yy34Jto53x+/lqr6eT/MRkeeXREfXacRiAdXiRQ8KysSNS3wTYibugD2irgZdCCRySS4Z2lwurmobn+Vk2s9Wc4eNrxtWf9RSYbVZ4bVOl4BVyE0gqJ5i0S8jGCrtBgM9a96v0JkEBC+yxSt5FmJwoD5XLv1siK+G4a3xcWu5EU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711180529; 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=TjGuxmMnBfyPQokD5nt9Dsfg0pZnLJo3RyJ9uy6B6LM=; b=D9Ofe9xLbEh4PCDaQSsqYzC+mRpmKXqv/rswBkQE7pOhHRJfM+heOMHHwPjXY7VexaNB7F 3hnPpkQ/JThvHBUvAGNnetIgka2Z08doYWE8rzwhqt8V3rLqIoWXSGsCA1LSCRcneuGxuE nUGmYqr6muXWlbN9pl7TYHKg6+ddgsg= 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-90-q-6k5JEZP--mG-QzgBEzBw-1; Sat, 23 Mar 2024 03:55:26 -0400 X-MC-Unique: q-6k5JEZP--mG-QzgBEzBw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (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 E5217811E81; Sat, 23 Mar 2024 07:55:25 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.57]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 91FF42022C23; Sat, 23 Mar 2024 07:55:25 +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 42N7tJfr270047 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 23 Mar 2024 08:55:19 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 42N7tIOu270046; Sat, 23 Mar 2024 08:55:18 +0100 Date: Sat, 23 Mar 2024 08:55:18 +0100 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] bitint: Handle complex types in build_bitint_stmt_ssa_conflicts [PR114425] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.5 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! The task of the build_bitint_stmt_ssa_conflicts hook for tree-ssa-coalesce.cc next to special casing the multiplication/division/modulo is to ignore statements with large/huge _BitInt lhs which isn't in names bitmap and on the other side pretend all uses of the stmt are used in a later stmt (single user of that SSA_NAME or perhaps single user of lhs of the single user etc.) where the lowering will actually emit the code. Unfortunately the function wasn't handling COMPLEX_TYPE of the large/huge BITINT_TYPE, while the FE doesn't really support such types, they are used under the hood for __builtin_{add,sub,mul}_overflow{,_p}, they are also present or absent from the names bitmap and should be treated the same. Without this patch, the operands of .ADD_OVERFLOW were incorrectly pretended to be used right in that call statement rather than on the cast stmt from IMAGPART_EXPR of .ADD_OVERFLOW return value to some integral type. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-03-23 Jakub Jelinek PR tree-optimization/114425 * gimple-lower-bitint.cc (build_bitint_stmt_ssa_conflicts): Handle _Complex large/huge _BitInt types like the large/huge _BitInt types. * gcc.dg/torture/bitint-67.c: New test. Jakub --- gcc/gimple-lower-bitint.cc.jj 2024-03-22 09:21:28.350087044 +0100 +++ gcc/gimple-lower-bitint.cc 2024-03-22 14:54:41.767972684 +0100 @@ -5902,20 +5902,25 @@ build_bitint_stmt_ssa_conflicts (gimple if (is_gimple_assign (stmt)) { lhs = gimple_assign_lhs (stmt); - if (TREE_CODE (lhs) == SSA_NAME - && TREE_CODE (TREE_TYPE (lhs)) == BITINT_TYPE - && bitint_precision_kind (TREE_TYPE (lhs)) >= bitint_prec_large) + if (TREE_CODE (lhs) == SSA_NAME) { - if (!bitmap_bit_p (names, SSA_NAME_VERSION (lhs))) - return; - switch (gimple_assign_rhs_code (stmt)) + tree type = TREE_TYPE (lhs); + if (TREE_CODE (type) == COMPLEX_TYPE) + type = TREE_TYPE (type); + if (TREE_CODE (type) == BITINT_TYPE + && bitint_precision_kind (type) >= bitint_prec_large) { - case MULT_EXPR: - case TRUNC_DIV_EXPR: - case TRUNC_MOD_EXPR: - muldiv_p = true; - default: - break; + if (!bitmap_bit_p (names, SSA_NAME_VERSION (lhs))) + return; + switch (gimple_assign_rhs_code (stmt)) + { + case MULT_EXPR: + case TRUNC_DIV_EXPR: + case TRUNC_MOD_EXPR: + muldiv_p = true; + default: + break; + } } } } @@ -5947,27 +5952,37 @@ build_bitint_stmt_ssa_conflicts (gimple auto_vec worklist; FOR_EACH_SSA_TREE_OPERAND (var, stmt, iter, SSA_OP_USE) - if (TREE_CODE (TREE_TYPE (var)) == BITINT_TYPE - && bitint_precision_kind (TREE_TYPE (var)) >= bitint_prec_large) - { - if (bitmap_bit_p (names, SSA_NAME_VERSION (var))) - use (live, var); - else - worklist.safe_push (var); - } + { + tree type = TREE_TYPE (var); + if (TREE_CODE (type) == COMPLEX_TYPE) + type = TREE_TYPE (type); + if (TREE_CODE (type) == BITINT_TYPE + && bitint_precision_kind (type) >= bitint_prec_large) + { + if (bitmap_bit_p (names, SSA_NAME_VERSION (var))) + use (live, var); + else + worklist.safe_push (var); + } + } while (worklist.length () > 0) { tree s = worklist.pop (); FOR_EACH_SSA_TREE_OPERAND (var, SSA_NAME_DEF_STMT (s), iter, SSA_OP_USE) - if (TREE_CODE (TREE_TYPE (var)) == BITINT_TYPE - && bitint_precision_kind (TREE_TYPE (var)) >= bitint_prec_large) - { - if (bitmap_bit_p (names, SSA_NAME_VERSION (var))) - use (live, var); - else - worklist.safe_push (var); - } + { + tree type = TREE_TYPE (var); + if (TREE_CODE (type) == COMPLEX_TYPE) + type = TREE_TYPE (type); + if (TREE_CODE (type) == BITINT_TYPE + && bitint_precision_kind (type) >= bitint_prec_large) + { + if (bitmap_bit_p (names, SSA_NAME_VERSION (var))) + use (live, var); + else + worklist.safe_push (var); + } + } } if (muldiv_p) --- gcc/testsuite/gcc.dg/torture/bitint-67.c.jj 2024-03-22 14:53:52.929642342 +0100 +++ gcc/testsuite/gcc.dg/torture/bitint-67.c 2024-03-22 14:54:29.205144953 +0100 @@ -0,0 +1,29 @@ +/* PR tree-optimization/114425 */ +/* { dg-do run { target bitint } } */ +/* { dg-options "-std=c23" } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "*" } { "-O0" "-O2" } } */ +/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */ + +#if __BITINT_MAXWIDTH__ >= 2000 +_BitInt(8) a; +_BitInt(300) b; +_BitInt(2000) c; + +__attribute__((noipa)) unsigned +foo (_BitInt(2000) d) +{ + int o = __builtin_add_overflow_p (d, 0, b); + _BitInt(2000) m = c * a; + unsigned u = m; + return u + o; +} +#endif + +int +main () +{ +#if __BITINT_MAXWIDTH__ >= 2000 + if (foo (0xfa7ac16f2613255eeb217e871c1f02221e26ce11f82d6a33206ec0ad5d4414722019933c0e2wb) != 1) + __builtin_abort (); +#endif +}