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: 201254 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:b825:b0:106:860b:bbdd with SMTP id da37csp227927dyb; Wed, 14 Feb 2024 23:39:09 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX+p3PwE/oNx5sbFJanukEWKRNhj+ABcU43/+m6k0f2LBnD8NnErMLm3QamA95d/nu0FseclAQhJWNp5NqW5GMTT5aUMw== X-Google-Smtp-Source: AGHT+IHbcqZLqDlDOkIQryvY9ZO6xRiWeQDBrF4Kgyuq0HY4YvHMv+A2iLQHZK5IG8j2GYOyhVIU X-Received: by 2002:a05:6808:38cc:b0:3c1:32a0:8c1a with SMTP id el12-20020a05680838cc00b003c132a08c1amr1695948oib.47.1707982749759; Wed, 14 Feb 2024 23:39:09 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707982749; cv=pass; d=google.com; s=arc-20160816; b=rjK+6cxtCJBosF5Ih1Y0jLV1h60g8Y727HrIG+PH+PsNgb1eNpShKUBd41NEVs3Bd3 r9h11PUH6qclMViunysE6lvMwAQqQ99MyrYwSP9sBt2AYlpRVEtzLV0DZET23IM0HJfE NyvFAnGhCX8b29rO7Vfd0ts/ihB0ypjXZIGgXWZZuoxm5eSZe8Zo69qAszDCx1QN0OFX fpFHuVtIa1+YfL/W8k7Wcz+x+hbJROlwgUQjJzCXTto/GMhNf2TRSzKYMTIbqzrmUzJx YVAbRENNQGPfmiaPyQo9O4bDUhv2kMgMUxXQImT5j7xMwb/dZmmzdoEh5oixgDTEGgja mnXQ== 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=uu2c0taWWg4J+WWfhBzdqQJ00KVGjN19NoYAC3s0sKw=; fh=FCjeRajqaQYHMkQtfIia8KT5yBac53mYOLLyJhYG/AY=; b=Lg3OSTm9Yx2ZJ/CCTY1t3//XO8IQqep2zvsapSiddJYmpyJDwcoygWLLckBlo1ijVR PLBhEvZx9/WrPYySZ0+bVr9CK0gsUGD7C1yPTjK1G2aTuX6qompJARlHYCoMBq4l6wkC LizdJSB0vbrOKbjgjBPVzLPJOxAlieeIZDxsxPX5SB7l9XZ7uQbFmCx+kQA9U+SOT6S7 S+7Czjl9h32AbEwUpx6j/ZyTnwX8Dj6Ha2INQc/Nvw7KRn7mjC/JKbeiVznddMxstKT5 EqrvWdH+j67x5cijc911GqfVSZwQFlUQqsM3WkxkXm/6+mq7tLuob6HNaDf2cYqgx1K0 AHHQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=bjOFwsYL; 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 m11-20020ad45dcb000000b0068cb950df8asi880223qvh.5.2024.02.14.23.39.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 23:39:09 -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=bjOFwsYL; 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 761D33861849 for ; Thu, 15 Feb 2024 07:39:09 +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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790949719997849000 X-GMAIL-MSGID: 1790949719997849000 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