From patchwork Sat Jan 27 08:05:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 192987 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2395:b0:106:343:edcb with SMTP id gw21csp374074dyb; Sat, 27 Jan 2024 00:16:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IFKb+ueHz9vPKiClGEqc32vkV7PtkPA5TF7biTuZgCmhZIej+UurWWYr40SC78d489smkng X-Received: by 2002:ac8:5985:0:b0:42a:59f6:2407 with SMTP id e5-20020ac85985000000b0042a59f62407mr1508355qte.76.1706343394670; Sat, 27 Jan 2024 00:16:34 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706343394; cv=pass; d=google.com; s=arc-20160816; b=qO+kp2OKh5zws/O0AJDb9fiKXZ4ezU+67UOvB7SBolfvDi+uFXh94hTQuU5eyOI8x5 HKWKYu3i4l7+aOd2Agn6lfBpG6mSk8VvZhPnZzR9ssNdY0VE1EMyh572LJ86E9J2962j szzG1Ue+GpjSEkXC9D37kCKa77GUfhZPA0jx9dx5SV8OuACioU8J8O1qBP0bcOK8Ifmt IK6bkU9Ri9E4BlvE/9CRQ9/ukbOdqdlY+Ss4d8RFFW3NIz+5OOyudCJBmQjfeEXJ9wLS mZTBFh6qTE5e0q+jyYOWAjtqDq9BeO81MRiQvT0mj1/KiGcI8v1a59Dkk+/h+4qrf/CC T7Bw== 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:resent-to :resent-message-id:resent-date:resent-from:dkim-signature:arc-filter :dmarc-filter:delivered-to; bh=jAb3fJ7z7u5S1FwD6ehQCrmX0vj8DmbR2WyMuCDIAI8=; fh=FCjeRajqaQYHMkQtfIia8KT5yBac53mYOLLyJhYG/AY=; b=evPGeSOqy1i20nLlwF+tLl8UHmMkcM2lIXponqt8d+Hx1dpB4YiQryJwSuXIgfBaa6 1EE8jlQFhoaPV0jrQuIZ/ZyBNPduxLaLhDrVBVr2Cp3HVtOHmmTyCSz5weqK4TDjmQOA ZQaQ3zYGXOqyIGb1qary78q3rHf0YJ8kOJmaMxEngOrgb3bIoOlJ/vZd/0i03HybdNHX xekRj1DLY7vozLlmK8sIIFPDYj8sBVQveoJciHDpT3S+/9weORDZxLUxlUTU/Nmm6Q7m Ptt7BVLxt1uODhAU+nQBapXpQRI2q8eoEtzbyi8vLiMFF1wVrtf/7YtuLr0MVWx6H3py juSw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Pyw5rolX; 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 7-20020ac85707000000b00429cc8cda03si3057385qtw.420.2024.01.27.00.16.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 Jan 2024 00:16:34 -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=Pyw5rolX; 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 5A67C3858436 for ; Sat, 27 Jan 2024 08:16:34 +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 C9F5B3858284 for ; Sat, 27 Jan 2024 08:13:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C9F5B3858284 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 C9F5B3858284 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=1706343241; cv=none; b=rR2h3PRp/uxGgJK8FLnCUrTA4EWf5aEI+obLYasFO5v+tpvaKktdm16U/9iE9kuJwhbqrb7v9tX6rDlgN4LIAR0K1RYUYgrUpjI94K3755e7/RcHygGQ1lIiPPYapLthEvvwbiJtJy802JS1+oSsGgYvvj5sSo0UQV7jPE17d/s= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706343241; c=relaxed/simple; bh=J8r/ek1hHLyFKbGCOYtAb0LsPTf193YupsJ206B7sMI=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=OtUrJooa6ocDOkBHwYE+xjdN6Dl5TZeFl/5+o10jeJN4pG2irGpnibxUCCZZdGSu0HksbQ550LVKVnqNQ8ktZ1aMISw+AlG9eyoYGzKFanhvW9nqWG9Wz3nPZy3NbNupkJgSfBi80EK8NXzJ/BhhU8Jnihp8nLkS/38M+mz7w2M= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706343237; 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:resent-to:resent-from:resent-message-id; bh=jAb3fJ7z7u5S1FwD6ehQCrmX0vj8DmbR2WyMuCDIAI8=; b=Pyw5rolXqZVw5ke8ABoQJOdnq+OVfRkC8azIMa33RUdxLnqLKbMQgh52ZmcuO6BhzmPRSG DngBLGxKH0UCCQRQIZ1Yu3VPcW+XR//FkvNnpsKGMIq/q91cnVNmlS/ftsZFgWW7syDoA7 8uie0twVf4uwaDGikkCzibJiS3q1v4I= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-194-WySvkRCAPHKYTyOwEErwwA-1; Sat, 27 Jan 2024 03:13:55 -0500 X-MC-Unique: WySvkRCAPHKYTyOwEErwwA-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (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 7CBE328AC1F1; Sat, 27 Jan 2024 08:13:55 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.70]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 41FB1492BC6; Sat, 27 Jan 2024 08:13:55 +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 40R8DqSZ141164 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 27 Jan 2024 09:13:53 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 40R8DquJ141163; Sat, 27 Jan 2024 09:13:52 +0100 Resent-From: Jakub Jelinek Resent-Date: Sat, 27 Jan 2024 09:13:52 +0100 Resent-Message-ID: Resent-To: Richard Biener , gcc-patches@gcc.gnu.org Date: Sat, 27 Jan 2024 09:05:20 +0100 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] lower-bitint: Fix up VIEW_CONVERT_EXPR handling in lower_mergeable_stmt [PR113568] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-4.3 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_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: 1789230731156278159 X-GMAIL-MSGID: 1789230731156278159 Hi! We generally allow merging mergeable stmts with some final cast (but not further casts or mergeable operations after the cast). As some casts are handled conditionally, if (idx < cst) handle_operand (idx); else if idx == cst) handle_operand (cst); else ..., we must sure that e.g. the mergeable PLUS_EXPR/MINUS_EXPR/NEGATE_EXPR never appear in handle_operand called from such casts, because it ICEs on invalid SSA_NAME form (that part could be fixable by adding further PHIs) but also because we'd need to correctly propagate the overflow flags from the if to else if. So, instead lower_mergeable_stmt handles an outermost widening cast (or widening cast feeding outermost store) specially. The problem was similar to PR113408, that VIEW_CONVERT_EXPR tree is present in the gimple_assign_rhs1 while it is not for NOP_EXPR/CONVERT_EXPR, so the checks whether the outermost cast should be handled didn't handle the VCE case and so handle_plus_minus was called from the conditional handle_cast. Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-01-27 Jakub Jelinek PR tree-optimization/113568 * gimple-lower-bitint.cc (bitint_large_huge::lower_mergeable_stmt): For VIEW_CONVERT_EXPR use first operand of rhs1 instead of rhs1 in the widening extension checks. * gcc.dg/bitint-78.c: New test. Jakub --- gcc/gimple-lower-bitint.cc.jj 2024-01-26 17:40:29.083814064 +0100 +++ gcc/gimple-lower-bitint.cc 2024-01-26 18:05:24.461891138 +0100 @@ -2401,6 +2401,8 @@ bitint_large_huge::lower_mergeable_stmt rhs1 = gimple_assign_rhs1 (store_operand ? SSA_NAME_DEF_STMT (store_operand) : stmt); + if (TREE_CODE (rhs1) == VIEW_CONVERT_EXPR) + rhs1 = TREE_OPERAND (rhs1, 0); /* Optimize mergeable ops ending with widening cast to _BitInt (or followed by store). We can lower just the limbs of the cast operand and widen afterwards. */ --- gcc/testsuite/gcc.dg/bitint-78.c.jj 2024-01-26 18:11:54.164435951 +0100 +++ gcc/testsuite/gcc.dg/bitint-78.c 2024-01-26 18:11:33.642723218 +0100 @@ -0,0 +1,21 @@ +/* PR tree-optimization/113568 */ +/* { dg-do compile { target bitint } } */ +/* { dg-options "-O2 -std=c23" } */ + +signed char c; +#if __BITINT_MAXWIDTH__ >= 464 +_BitInt(464) g; + +void +foo (void) +{ + _BitInt(464) a[2] = {}; + _BitInt(464) b; + while (c) + { + b = g + 1; + g = a[0]; + a[0] = b; + } +} +#endif