From patchwork Tue Aug 16 09:19:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 547 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6a10:38f:b0:2d5:3c95:9e21 with SMTP id 15csp1877676pxh; Tue, 16 Aug 2022 02:20:48 -0700 (PDT) X-Google-Smtp-Source: AA6agR4JomrtmGiTLWB5I3gNL8JTKoUW6wU45sGoffTD403g5W74qTDVcfkWQizJIU5iKgy8Mwf3 X-Received: by 2002:a17:907:6e12:b0:730:bc12:82e3 with SMTP id sd18-20020a1709076e1200b00730bc1282e3mr13263876ejc.36.1660641648582; Tue, 16 Aug 2022 02:20:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660641648; cv=none; d=google.com; s=arc-20160816; b=f/vlBBQHsqUNU6Jqq0Zb9Nt3JwVIT9RCX6Y/xGadn48mim2ZBbg6EWRvrvl+UFgXHb 8ohiCLHHtmgD2pe8VQEcDJvMff0UFWD4Vk8lbN2npFkE5hdJEfc7186lE6RsURRD/Juf 5uVi9K2KN47N4kyDK8yblDROuhkrxa+7Ss2g0JuN3rGdA4sJwy/SOGFI+ELe9Ot53n6a 6sD928jU0ipYEcprxvBPr3nhHuhBeKcgyTkXYuxHGBEM5WGHSq9+mGGCLlxmbp+sxlk8 Uot82PkRxo8JSuZrWuCvMOrnvL6lVL4sK1w7Vbd+C0HbQpsa+8ZYC4g+bH2GESjDJvM5 t/RA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:sender:errors-to:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :mime-version:user-agent:subject:to:date:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=QqRhagFYMl9VHDeffMYo/xMkhSnjxzK+BGsymuqnWG8=; b=0CenvkYFyySE0QLYwWrskk8ye4NFfwRsu5yXZVezKUWkOAKEuaDlHnZ9/LldqvxzhL +u8YbOV1EhfUbRsoS91jzt+9mE1Bf15QouLLd5LlOH6AUy/4gb2wQZKLGFKJbBriv3TD g/iurn084kK+/uq824SMo9nLHXQLTZEKRopZ/0pkZBE65Gj8kwMXpSx+LvHnTIrxbWxz O2QYApmbPtr6kqP9dmcQCtlaAIvgmubFAjA41T/OpQIPokM+ZJi2my4w9Veyzq5JkvLS Ew7VKLXSj0aFomWFr2qHnEIJ2QMjDx4Sb98j++ly0ih1ttOlCoxv9REr1UCQVjh88EBc HT0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=xOT78XOq; 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 gn11-20020a1709070d0b00b00710e9e0a239si12229596ejc.919.2022.08.16.02.20.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Aug 2022 02:20:48 -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=xOT78XOq; 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 7D74E3857BAC for ; Tue, 16 Aug 2022 09:20:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7D74E3857BAC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1660641628; bh=QqRhagFYMl9VHDeffMYo/xMkhSnjxzK+BGsymuqnWG8=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=xOT78XOq295uPNqvbD/ifQZ+JcGxWSVzMXuAYzVLFg/HZqB8TucEnL8LQ4cOkQmm9 t6QnTHaMS7Vqa6GkvdugGnkbkPtUGysmeLOdDEpbl3EjSJ6Xbsey1JJaJJwYracLyz N4S7g/jxXbzQc+Sf7IEevTh73KCwsXGIEADHxX0U= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id BB956385828F for ; Tue, 16 Aug 2022 09:19:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BB956385828F Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id D2B4333B21 for ; Tue, 16 Aug 2022 09:19:43 +0000 (UTC) Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id C3C952C149 for ; Tue, 16 Aug 2022 09:19:43 +0000 (UTC) Date: Tue, 16 Aug 2022 09:19:43 +0000 (UTC) To: gcc-patches@gcc.gnu.org Subject: [PATCH] middle-end/106630 - avoid ping-pong between extract_muldiv and match.pd User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, MISSING_MID, SPF_HELO_NONE, SPF_PASS, 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: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" Message-Id: <20220816092028.7D74E3857BAC@sourceware.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1741308977320961567?= X-GMAIL-MSGID: =?utf-8?q?1741308977320961567?= The following avoids ping-pong between the match.pd pattern changing (sizetype) ((a_9 + 1) * 48) to (sizetype)(a_9 + 1) * 48 and extract_muldiv performing the reverse transform by restricting the match.pd pattern to narrowing conversions as the comment indicates. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR middle-end/106630 * match.pd ((T)(x * CST) -> (T)x * CST): Restrict to narrowing conversions. * gcc.dg/torture/pr106630.c: New testcase. --- gcc/match.pd | 2 +- gcc/testsuite/gcc.dg/torture/pr106630.c | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr106630.c diff --git a/gcc/match.pd b/gcc/match.pd index e32bda64e64..07d0a61fc3a 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -1917,7 +1917,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (convert (mult@0 zero_one_valued_p@1 INTEGER_CST@2)) (if (INTEGRAL_TYPE_P (type) && INTEGRAL_TYPE_P (TREE_TYPE (@0)) - && TYPE_PRECISION (type) <= TYPE_PRECISION (TREE_TYPE (@0))) + && TYPE_PRECISION (type) < TYPE_PRECISION (TREE_TYPE (@0))) (mult (convert @1) (convert @2)))) /* (X << C) != 0 can be simplified to X, when C is zero_one_valued_p. diff --git a/gcc/testsuite/gcc.dg/torture/pr106630.c b/gcc/testsuite/gcc.dg/torture/pr106630.c new file mode 100644 index 00000000000..d608b9151be --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr106630.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ + +short d, e; +int f; +extern short g[][24]; +char c; +void h() { + char a = 6; + c = a; + for (unsigned long a = (d || e) - 1; a < c; a += f) + for (signed b = 0; b < 24; b++) + g[a][b] = 4; +}