From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686925340; 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=n2bsvII2i7TUV1GZqPbU3rC+joY2dxH3ECWM2gfkS2w=; b=jC8Dj3ZqcPfz7f/+X/4c8butaqJpt90ndqYi1khCxCKpdms8Df4eoveb200ph7XkQyWUV2 KJTex3NvbOw+slUL7Lx7H4HopPr78zLFm97JnhHZ4Syh5O3F4bI2MjAcBAEepP4yCT70hq LTYSs+cjPzmlGtd3Lrps1zHPQTZCYCY= 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 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-ssa-math-opts: Fix up uaddc/usubc pattern matching [PR110271] Message-ID: Reply-To: Jakub Jelinek 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-Type: text/plain; charset=us-ascii 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 List-Id: 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. --- 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); +} Jakub