From patchwork Tue Dec 5 07:21:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 173756 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3261282vqy; Mon, 4 Dec 2023 23:21:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IHvD6F+9juE6Bu4LES4GRCBmKAUHYcZEcOxMO4j6/GcpLkzQF1zj3FAlPspNSGDCFG7wHal X-Received: by 2002:ad4:584f:0:b0:67a:ba98:b16e with SMTP id de15-20020ad4584f000000b0067aba98b16emr878685qvb.83.1701760906879; Mon, 04 Dec 2023 23:21:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701760906; cv=pass; d=google.com; s=arc-20160816; b=B1iD54kQgn6kqWCHoAzOPa4NLJBw7nsd71Chl3kewPsY/XGDWhklWh20fW6cQ/K27b rpykSKi5WFXe0gQR1YXhS7dEtuHZ3QHYpAfCxipDuIoXOPmJO3/dG8eDecg4eFHpAMJf kD9VSGHMn7GRAm4mgPdjIEANqOPRPINyOsFtGqBbUee6ehqBTLiVDBdBiJ+pSXhwg6KF UNLV9lqfoU+s+jQL/8Q9FbBdEn+CfQ6D+W313DJRkFUzSQp9trDUFfmzrpOhpNBBO3XJ 2lAfpPjbnccMoRAog+EGPZI+bPBlSR4eSxF48Ll2zkJkKZPj2X8z8aubujymFyAGzpHl 86vg== 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-transfer-encoding :content-disposition:mime-version:message-id:subject:cc:to:from:date :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=qrmN2nZTAsFL3A1H8sHbpjCc+fqRUbXNuKP5RpZAUs4=; fh=FCjeRajqaQYHMkQtfIia8KT5yBac53mYOLLyJhYG/AY=; b=1DLAbc4GIvRDUaqctur4xrmhCjbaW/o5B88gwxAZQtLbZFoHqb8qgHeZiRlRIS/4oI whz7H1TWXDUlqCvhK55rzWLJxdoQpNLU6jU4Fj5ZLFQJ1hV2S0HLdKsijkZTGAIwSw2x P4ndxfMTEJ72smfeAj7qwJku6yvHuxjs/HD0y26uZuD+r9E/soIo2+7wPNjSxgH77CDi 68vW0OgHZULDp4s+F/u78RJwy2Pm+aBJcnHqvw2Vfsm1rMo8crelCg8bY+kjhothRFHs lAayCGTCkNbZNQ6OCIQL2vgT+5+0HNnWndpro76zXM9Tl9Z+6nc7Nn7qJX9btVQVVyz/ 7Fkg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ZV15DU0Q; 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 mh2-20020a056214564200b0067ab3389663si6091121qvb.293.2023.12.04.23.21.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 23:21: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=ZV15DU0Q; 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 A07133858024 for ; Tue, 5 Dec 2023 07:21: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.129.124]) by sourceware.org (Postfix) with ESMTPS id ACAAD3858C5F for ; Tue, 5 Dec 2023 07:21:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ACAAD3858C5F 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 ACAAD3858C5F 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=1701760883; cv=none; b=TAOqBpxjwH+ohQG2h+zw4CLj96N7aVYQuEbPxcoFmXM1nzrHh77CGSWt5vA3664dk2k3txHi7uzBFB2Zk2PO9dLiGvrnJQB4+Jl5H6Xyqwf0kV9UIzosppVN4Hh793aNxsCdNHBSmlyEzzqZiUAJ9HM7XcMH5Av+PEr45fUSF/g= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701760883; c=relaxed/simple; bh=Gr7+9JIkM3t4u4wAs3cRH6mdbxaiC02AxSExMiY7j68=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=OIt4nOzySX1eSGP7PvBF2Fqzg/quqAaGJyZKZtZ16DOMw8TCKwEL+5f0QDZikdUvFgJrlSF4CrC8iYaECDlljvCtdGB7+JKJR6P7icq289y06HwcOncF63SoxtKsY0UHBUMZGFwd7iChDGgkYWuaBt6ut54Ec7gJXMoVvK5TEQo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701760881; 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: content-transfer-encoding:content-transfer-encoding; bh=qrmN2nZTAsFL3A1H8sHbpjCc+fqRUbXNuKP5RpZAUs4=; b=ZV15DU0Q/0HvdnFpdLFOIDyVBmtwRYb5vYjEE3/iXIiQA7ZDnGtXC84hTYXZfb7zh2UXxG uOegZL4+z9JcUk0OImO8laFMxzDdNxW21WJgrrKcfjRjDkeUr/bWgLcsl/BLwiieCKXh4E U/3ercMWKtNQzHxKVLho8c3pg+8Nhf8= 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-331-mnmljRWsMUugsSmMZvhavA-1; Tue, 05 Dec 2023 02:21:19 -0500 X-MC-Unique: mnmljRWsMUugsSmMZvhavA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 37F83185A782; Tue, 5 Dec 2023 07:21:19 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.195.157]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F042E40C6EB9; Tue, 5 Dec 2023 07:21:18 +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 3B57LGQ8693911 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 5 Dec 2023 08:21:16 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3B57LFM8693910; Tue, 5 Dec 2023 08:21:15 +0100 Date: Tue, 5 Dec 2023 08:21:15 +0100 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] lower-bitint: Make temporarily wrong IL less wrong [PR112843] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.4 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, T_SCC_BODY_TEXT_LINE, WEIRD_PORT 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: 1784425644853560120 X-GMAIL-MSGID: 1784425644853560120 Hi! As discussed in the PR, for the middle (on x86-64 65..128 bit) _BitInt types like _1 = x_4(D) * 5; where _1 and x_4(D) have _BitInt(128) type and x is PARM_DECL, the bitint lowering pass wants to replace this with _13 = (int128_t) x_4(D); _12 = _13 * 5; _1 = (_BitInt(128)) _12; where _13 and _12 have int128_t type and the ranger ICEs when the IL is temporarily invalid: during GIMPLE pass: bitintlower pr112843.c: In function ‘foo’: pr112843.c:7:1: internal compiler error: Segmentation fault 7 | foo (_BitInt (128) x, _BitInt (256) y) | ^~~ 0x152943f crash_signal ../../gcc/toplev.cc:316 0x25c21c8 ranger_cache::range_of_expr(vrange&, tree_node*, gimple*) ../../gcc/gimple-range-cache.cc:1204 0x25cdcf9 fold_using_range::range_of_range_op(vrange&, gimple_range_op_handler&, fur_source&) ../../gcc/gimple-range-fold.cc:671 0x25cf9a0 fold_using_range::fold_stmt(vrange&, gimple*, fur_source&, tree_node*) ../../gcc/gimple-range-fold.cc:602 0x25b5520 gimple_ranger::update_stmt(gimple*) ../../gcc/gimple-range.cc:564 0x16f1234 update_stmt_operands(function*, gimple*) ../../gcc/tree-ssa-operands.cc:1150 0x117a5b6 update_stmt_if_modified(gimple*) ../../gcc/gimple-ssa.h:187 0x117a5b6 update_stmt_if_modified(gimple*) ../../gcc/gimple-ssa.h:184 0x117a5b6 update_modified_stmt ../../gcc/gimple-iterator.cc:44 0x117a5b6 gsi_insert_after(gimple_stmt_iterator*, gimple*, gsi_iterator_update) ../../gcc/gimple-iterator.cc:544 0x25abc2f gimple_lower_bitint ../../gcc/gimple-lower-bitint.cc:6348 What the code does right now is, it first creates a new SSA_NAME (_12 above), adds the _1 = (_BitInt(128)) _12; stmt after it (where it crashes, because _12 has no SSA_NAME_DEF_STMT yet), then sets lhs of the previous stmt to _12 (this is also temporarily incorrect, there are incompatible types involved in the stmt), later on changes also operands and finally update_stmt it. The following patch instead changes the lhs of the stmt before adding the cast after it. The question is if this is less or more wrong temporarily (but the ICE is gone). Yet another possibility would be to first adjust the operands of stmt (without update_stmt), then set_lhs to a new lhs (still without update_stmt), then add the cast after it and finally update_stmt (stmt). Maybe that would be less wrong (still, before it is updated some chains might think it is still the setter of _1 when it is not anymore). Anyway, should I go with that order then instead of the patch below? The reason I tweaked the lhs first is that it then just uses gimple_op and iterates over all ops, if that is done before lhs it would need to special case which op to skip because it is lhs (I'm using gimple_get_lhs for the lhs, but this isn't done for GIMPLE_CALL nor GIMPLE_PHI, so GIMPLE_ASSIGN or say GIMPLE_GOTO etc. are the only options, so I could just start with op 1 rather than 0 for is_gimple_assign). 2023-12-04 Jakub Jelinek PR tree-optimization/112843 * gimple-lower-bitint.cc (gimple_lower_bitint): Change lhs of stmt to lhs2 before building and inserting lhs = (cast) lhs2; assignment. * gcc.dg/bitint-47.c: New test. Jakub --- gcc/gimple-lower-bitint.cc.jj 2023-12-03 17:53:55.604855552 +0100 +++ gcc/gimple-lower-bitint.cc 2023-12-04 14:39:20.352057389 +0100 @@ -6338,6 +6338,7 @@ gimple_lower_bitint (void) int uns = TYPE_UNSIGNED (TREE_TYPE (lhs)); type = build_nonstandard_integer_type (prec, uns); tree lhs2 = make_ssa_name (type); + gimple_set_lhs (stmt, lhs2); gimple *g = gimple_build_assign (lhs, NOP_EXPR, lhs2); if (stmt_ends_bb_p (stmt)) { @@ -6346,7 +6347,6 @@ gimple_lower_bitint (void) } else gsi_insert_after (&gsi, g, GSI_SAME_STMT); - gimple_set_lhs (stmt, lhs2); } unsigned int nops = gimple_num_ops (stmt); for (unsigned int i = 0; i < nops; ++i) --- gcc/testsuite/gcc.dg/bitint-47.c.jj 2023-12-04 14:53:19.784200724 +0100 +++ gcc/testsuite/gcc.dg/bitint-47.c 2023-12-04 14:42:07.251699994 +0100 @@ -0,0 +1,13 @@ +/* PR tree-optimization/112843 */ +/* { dg-do compile { target bitint } } */ +/* { dg-options "-O2" } */ + +#if __BITINT_MAXWIDTH__ >= 256 +_BitInt (256) +foo (_BitInt (128) x, _BitInt (256) y) +{ + return x * 5 * y; +} +#else +int x; +#endif