From patchwork Sun Jul 2 14:53:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1802382 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=OX4ASBjd; dkim-atps=neutral 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 (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QvBsD5PmSz242R for ; Mon, 3 Jul 2023 00:54:08 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8C70E385842D for ; Sun, 2 Jul 2023 14:54:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8C70E385842D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1688309646; bh=/ZyHEUnqf/oEgcjFCJSHgRLaBjTZiFHMIxjFGmXN2oY=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=OX4ASBjdMf0EFBbtUbETBjSl6T0aoZl9ZT+gV5FpGng9/wBSX+/WmjR+TuQKlAuKi 1rcGUblX6l8qlrZ6VLn73y7Q2FnO8K3ezFJeZtQjrCE2Nn0cTe4ZYoSzY358fZlAs/ Q6sPrE0JN/OONK58x20UM0a/z4IfgUFK10ESD5HQ= 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 4A2023858412 for ; Sun, 2 Jul 2023 14:53:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4A2023858412 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-353-kVj_n4W6NYmmzLoJ9eHW3g-1; Sun, 02 Jul 2023 10:53:46 -0400 X-MC-Unique: kVj_n4W6NYmmzLoJ9eHW3g-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 172D0858EED; Sun, 2 Jul 2023 14:53:46 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.224.167]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D20BB492C13; Sun, 2 Jul 2023 14:53:45 +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 362Erh4V3533217 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sun, 2 Jul 2023 16:53:43 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 362ErgFZ3533216; Sun, 2 Jul 2023 16:53:42 +0200 Date: Sun, 2 Jul 2023 16:53:42 +0200 To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-ssa-math-opts: Fix up ICE in match_uaddc_usubc [PR110508] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 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 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Hi! The match_uaddc_usubc matching doesn't require that the second .{ADD,SUB}_OVERFLOW has REALPART_EXPR of its lhs used, only that there is at most one. So, in the weird case where the REALPART_EXPR of it isn't present, we shouldn't ICE trying to replace that REALPART_EXPR with REALPART_EXPR of .U{ADD,SUB}C result. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2023-07-02 Jakub Jelinek PR tree-optimization/110508 * tree-ssa-math-opts.cc (match_uaddc_usubc): Only replace re2 with REALPART_EXPR opf nlhs if re2 is non-NULL. * gcc.dg/pr110508.c: New test. Jakub --- gcc/tree-ssa-math-opts.cc.jj 2023-06-20 11:22:26.726887276 +0200 +++ gcc/tree-ssa-math-opts.cc 2023-07-01 00:29:48.554230914 +0200 @@ -4856,11 +4856,14 @@ match_uaddc_usubc (gimple_stmt_iterator gsi_remove (&gsi2, true); /* Replace the re2 statement with __real__ of the newly added .UADDC/.USUBC call. */ - gsi2 = gsi_for_stmt (re2); - tree rlhs = gimple_assign_lhs (re2); - g = gimple_build_assign (rlhs, REALPART_EXPR, - build1 (REALPART_EXPR, TREE_TYPE (rlhs), nlhs)); - gsi_replace (&gsi2, g, true); + if (re2) + { + gsi2 = gsi_for_stmt (re2); + tree rlhs = gimple_assign_lhs (re2); + g = gimple_build_assign (rlhs, REALPART_EXPR, + build1 (REALPART_EXPR, TREE_TYPE (rlhs), nlhs)); + gsi_replace (&gsi2, g, true); + } if (rhs[2]) { /* If this is the arg1 + arg2 + (ovf1 + ovf2) or --- gcc/testsuite/gcc.dg/pr110508.c.jj 2023-07-01 00:33:12.494405901 +0200 +++ gcc/testsuite/gcc.dg/pr110508.c 2023-07-01 00:32:24.115075870 +0200 @@ -0,0 +1,9 @@ +/* PR tree-optimization/110508 */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +void +foo (unsigned a, unsigned b, unsigned *c, _Bool d) +{ + __builtin_addc (a, b, d, c); +}