From patchwork Fri Jun 16 14:22:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 109171 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1380827vqr; Fri, 16 Jun 2023 07:23:06 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6djNbMgbTZWaAyNMv7qXASa1X9K/6Vcx3aBr18Bl1zYT6jvLOlUv5u7dZz5jGHfk97hjz/ X-Received: by 2002:a2e:b0ef:0:b0:2b3:be08:19f8 with SMTP id h15-20020a2eb0ef000000b002b3be0819f8mr1715658ljl.50.1686925386383; Fri, 16 Jun 2023 07:23:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686925386; cv=none; d=google.com; s=arc-20160816; b=tJ2Qg2z9QriUQ0MbQYLH4Q1p7LKPgLYqZRvf429k3Lk1cH3sFLpZH7cnH0wJBWJuby khSh0FJyUQzeBtjN3mmiqiXrCcntKPUzTZHUzxq9NdTa6+Lo2t9kV8iF11Hoe+L3XfLz PpMQbqF6E5fDTgKNpKexzWayJdNepvk9ACPm6XowtYCVLOVHkhof63OlN6mulCQHaMwD 0lgeqUxEcCRtMi/M09CTiNZysTipltG49+Ub/uJPGmRrl4O6ahJCT+F0y28O/XK7Sij0 UR3YQofdmrZbK3FGxClZ6ZE9JraDg7803AXkvB7fAy7rYj89fnZdbPfdH7Zq61rzXrfy cOwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:cc:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=n2bsvII2i7TUV1GZqPbU3rC+joY2dxH3ECWM2gfkS2w=; b=s1e2+/SqQ62lr5Y+h2DIOl3uuk6fEBrayokdag14hbD12yo2iywkNhgis8fPNXEccj HARE78kpAvELE+4O3BWGh1N5V6TPEJzegc0hKX/GUFSWUJCNCC8/fb3/q/AruhAnX+ff M3pJD5aC0ImPuGBROttHlBtkKNLSp0W5oDlPvS0+m7+zgETkKEBlWC1sx36WQAzQZTrf NuQMDSBsEDHqZHWvM9g0coQlk3k+xiX6rF+bZAsmwYOdpa4TTts7etCU4tukGkHwcYIw ySGKgvwDwAaYmcm7vHzpSYS+ylcLObUnHHDgT3t6yDe0JxvkUAISxLU47H2JWyIsLqMN snZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=BqE+D7Re; 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=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id m16-20020a170906259000b0097894b09c9asi113843ejb.213.2023.06.16.07.23.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jun 2023 07:23:06 -0700 (PDT) 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=@gcc.gnu.org header.s=default header.b=BqE+D7Re; 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=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0B3EF385770A for ; Fri, 16 Jun 2023 14:23:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0B3EF385770A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686925385; bh=n2bsvII2i7TUV1GZqPbU3rC+joY2dxH3ECWM2gfkS2w=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=BqE+D7ReQPEWKKoW2DGLpW6/vcILdeACDLDpHgsq/4wzkfQxJoxd0dE+fGEZKo11l U6+7uPZaqt1et65H5mWsgBPrJ7mOQKIs5/pkPLDK79OrhN77ZK+mVr11dxYTGAplx2 B20U99smZo8Z7e5dn2pSJwPcKNW2b5iOrQQAVahk= 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 96F1D3858D35 for ; Fri, 16 Jun 2023 14:22:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 96F1D3858D35 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-491-0iYtntXuMimifCn_ANsAYw-1; Fri, 16 Jun 2023 10:22:18 -0400 X-MC-Unique: 0iYtntXuMimifCn_ANsAYw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2A2538022EF; Fri, 16 Jun 2023 14:22:18 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.194.30]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DEFFA2026D49; Fri, 16 Jun 2023 14:22:17 +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 35GEM7fu1649768 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 16 Jun 2023 16:22:12 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 35GEM6jS1649767; Fri, 16 Jun 2023 16:22:06 +0200 Date: Fri, 16 Jun 2023 16:22:06 +0200 To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-ssa-math-opts: Fix up uaddc/usubc pattern matching [PR110271] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 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, 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768869473965166920?= X-GMAIL-MSGID: =?utf-8?q?1768869473965166920?= Hi! The following testcase ICEs, because I misremembered what the return value from match_arith_overflow is. It isn't true if __builtin_*_overflow was matched, but it is true only in the BIT_NOT_EXPR case if stmt was removed. So, if match_arith_overflow matches something, gsi_stmt (gsi) will not be stmt and match_uaddc_usubc will be confused and can ICE. The following patch fixes it by checking if gsi_stmt (gsi) == stmt, in that case we know it is still a PLUS_EXPR/MINUS_EXPR and we can try to pattern match it further as UADDC/USUBC. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2023-06-16 Jakub Jelinek PR tree-optimization/110271 * tree-ssa-math-opts.cc (math_opts_dom_walker::after_dom_children) : Ignore return value from match_arith_overflow, instead call match_uaddc_usubc only if gsi_stmt (gsi) is still stmt. * gcc.c-torture/compile/pr110271.c: New test. Jakub --- gcc/tree-ssa-math-opts.cc.jj 2023-06-15 09:12:28.777829348 +0200 +++ gcc/tree-ssa-math-opts.cc 2023-06-16 10:44:31.231798664 +0200 @@ -5558,9 +5558,12 @@ math_opts_dom_walker::after_dom_children case PLUS_EXPR: case MINUS_EXPR: - if (!convert_plusminus_to_widen (&gsi, stmt, code) - && !match_arith_overflow (&gsi, stmt, code, m_cfg_changed_p)) - match_uaddc_usubc (&gsi, stmt, code); + if (!convert_plusminus_to_widen (&gsi, stmt, code)) + { + match_arith_overflow (&gsi, stmt, code, m_cfg_changed_p); + if (gsi_stmt (gsi) == stmt) + match_uaddc_usubc (&gsi, stmt, code); + } break; case BIT_NOT_EXPR: --- gcc/testsuite/gcc.c-torture/compile/pr110271.c.jj 2023-06-16 10:57:32.757621687 +0200 +++ gcc/testsuite/gcc.c-torture/compile/pr110271.c 2023-06-16 10:57:15.298871335 +0200 @@ -0,0 +1,24 @@ +/* PR tree-optimization/110271 */ + +unsigned a, b, c, d, e; + +void +foo (unsigned *x, int y, unsigned int *z) +{ + for (int i = 0; i < y; i++) + { + b += d; + a += b < d; + a += c = (__PTRDIFF_TYPE__) x > 3; + d = z[1] + (a < c); + a += e; + d += a < e; + } +} + +void +bar (unsigned int *z) +{ + unsigned *x = x; + foo (x, 9, z); +}