From patchwork Thu Feb 15 07:38:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1899190 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=bjOFwsYL; 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 4Tb6Pl34p4z23gM for ; Thu, 15 Feb 2024 18:38:51 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BF2ED386184B for ; Thu, 15 Feb 2024 07:38: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.129.124]) by sourceware.org (Postfix) with ESMTPS id 7DFA23861802 for ; Thu, 15 Feb 2024 07:38:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7DFA23861802 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 7DFA23861802 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=1707982712; cv=none; b=MstHEdWzlA2lhpigyyrwo0PW4xBpptFaZ7GL6RYgV2+ySDPUeFZJz3MggyBjQQf7uQIc8ok2KRyl3l8Szad3HkKbEBpROpOPgSvzUgTZmJ/5Z9Bf/ioV5eWPccurVhV/awuo87tsmOmimSfXUB+EPZcAdMnQuWISopNQZzINopE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707982712; c=relaxed/simple; bh=ZWdhxn8h5nCBkJ0D2vX5cjaEHxnUDyqW9dnAc7tqqUA=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=VLPgq0yEXEffSVPM6QuQgkzZef2bvwqMrhoEE9qpYopUqWg+tRbmJFAsD8d6154anoH2hl31qEPyNitKP53gtwIxZdlp1NUDtG1y3C55dCtwnklq1ymWoLFzIwisQLrEai5f3dSPrwtJFL1EnoPfZ7gD7dUYNvb6xpu26M7ErNc= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707982710; 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=uu2c0taWWg4J+WWfhBzdqQJ00KVGjN19NoYAC3s0sKw=; b=bjOFwsYLlu2NUvBTJ0KEwb+Le3fFc7CBRcOM+hug6KpT6HQwq1Z7CtQMyUbJS4fT6A3fwY ZoDoAjMVAgI5PJ6jrMvNdWRMm96Q6H0aTp21QaRKXA407Ubol/8QbroOfzXW3lo1VSGyon ep2jg8FvCnNjle4kG4KKIhkGQ6bNBfg= 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-651-id6Qut8pM--VqXnHdXgEBA-1; Thu, 15 Feb 2024 02:38:27 -0500 X-MC-Unique: id6Qut8pM--VqXnHdXgEBA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (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 96470101A52A; Thu, 15 Feb 2024 07:38:26 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.8]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 59AF91121337; Thu, 15 Feb 2024 07:38:26 +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 41F7cNJ61207457 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 15 Feb 2024 08:38:24 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 41F7cNFf1207456; Thu, 15 Feb 2024 08:38:23 +0100 Date: Thu, 15 Feb 2024 08:38:22 +0100 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] lower-bitint: Ensure we don't get coalescing ICEs for (ab) SSA_NAMEs used in mul/div/mod [PR113567] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.8 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Hi! The build_bitint_stmt_ssa_conflicts hook has a special case for multiplication, division and modulo, where to ensure there is no overlap between lhs and rhs1/rhs2 arrays we make the lhs conflict with the operands. On the following testcase, we have # a_1(ab) = PHI lab: a_3(ab) = a_1(ab) % 3; before lowering and this special case causes a_3(ab) and a_1(ab) to conflict, but the PHI requires them not to conflict, so we ICE because we can't find some partitioning that will work. The following patch fixes this by special casing such statements before the partitioning, force the inputs of the multiplication/division which have large/huge _BitInt (ab) lhs into new non-(ab) SSA_NAMEs initialized right before the multiplication/division. This allows the partitioning to work then, as it has the possibility to use a different partition for the */% operands. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-02-15 Jakub Jelinek PR tree-optimization/113567 * gimple-lower-bitint.cc (gimple_lower_bitint): For large/huge _BitInt multiplication, division or modulo with SSA_NAME_OCCURS_IN_ABNORMAL_PHI lhs and at least one of rhs1 and rhs2 force the affected inputs into a new SSA_NAME. * gcc.dg/bitint-90.c: New test. Jakub --- gcc/gimple-lower-bitint.cc.jj 2024-02-12 20:45:50.156275452 +0100 +++ gcc/gimple-lower-bitint.cc 2024-02-14 18:17:36.630664828 +0100 @@ -5973,6 +5973,47 @@ gimple_lower_bitint (void) { default: break; + case MULT_EXPR: + case TRUNC_DIV_EXPR: + case TRUNC_MOD_EXPR: + if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (s)) + { + location_t loc = gimple_location (stmt); + gsi = gsi_for_stmt (stmt); + tree rhs1 = gimple_assign_rhs1 (stmt); + tree rhs2 = gimple_assign_rhs2 (stmt); + /* For multiplication and division with (ab) + lhs and one or both operands force the operands + into new SSA_NAMEs to avoid coalescing failures. */ + if (TREE_CODE (rhs1) == SSA_NAME + && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (rhs1)) + { + first_large_huge = 0; + tree t = make_ssa_name (TREE_TYPE (rhs1)); + g = gimple_build_assign (t, SSA_NAME, rhs1); + gsi_insert_before (&gsi, g, GSI_SAME_STMT); + gimple_set_location (g, loc); + gimple_assign_set_rhs1 (stmt, t); + if (rhs1 == rhs2) + { + gimple_assign_set_rhs2 (stmt, t); + rhs2 = t; + } + update_stmt (stmt); + } + if (TREE_CODE (rhs2) == SSA_NAME + && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (rhs2)) + { + first_large_huge = 0; + tree t = make_ssa_name (TREE_TYPE (rhs2)); + g = gimple_build_assign (t, SSA_NAME, rhs2); + gsi_insert_before (&gsi, g, GSI_SAME_STMT); + gimple_set_location (g, loc); + gimple_assign_set_rhs2 (stmt, t); + update_stmt (stmt); + } + } + break; case LROTATE_EXPR: case RROTATE_EXPR: { --- gcc/testsuite/gcc.dg/bitint-90.c.jj 2024-02-14 18:24:20.546018881 +0100 +++ gcc/testsuite/gcc.dg/bitint-90.c 2024-02-14 18:24:09.900167668 +0100 @@ -0,0 +1,23 @@ +/* PR tree-optimization/113567 */ +/* { dg-do compile { target bitint } } */ +/* { dg-options "-O2" } */ + +#if __BITINT_MAXWIDTH__ >= 129 +_BitInt(129) v; + +void +foo (_BitInt(129) a, int i) +{ + __label__ l1, l2; + i &= 1; + void *p[] = { &&l1, &&l2 }; +l1: + a %= 3; + v = a; + i = !i; + goto *(p[i]); +l2:; +} +#else +int i; +#endif