From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 6E7823858C60 for ; Thu, 2 Feb 2023 11:33:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6E7823858C60 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 798171FEBC for ; Thu, 2 Feb 2023 11:33:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1675337602; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=r1dMja59shSvYuMNtjPgrXU6vD8zvK3wI7wRkyHnwRQ=; b=EsXSaa2e7ChGdHvRf5uBkeul4pfnODd7BXhJvRDzxRd+Kb/6Jtf94NEfFWPCh+kkG/w5Br ru6ZWMY1rDGbfgmPAIhA6HdRM+I/NbCEup2A4CuOz8TtSeN3vXJ3liv1SaiSaTjkPVq/uc LyHW7ZtQmdpJ5TTj3ctfHJu3tYuzbTE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1675337602; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=r1dMja59shSvYuMNtjPgrXU6vD8zvK3wI7wRkyHnwRQ=; b=seNlEsQ/cPWGGH7Hn+L9wjutn5QQ0ee+eY3fCSv3nXqD8tlzyDc0Rve5gHizkWVmM1XChb JJAErnv2wPt+voBA== 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 6FD662C141 for ; Thu, 2 Feb 2023 11:33:22 +0000 (UTC) Date: Thu, 2 Feb 2023 11:33:22 +0000 (UTC) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] middle-end/108625 - wrong folding due to misinterpreted ! User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII 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 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: Message-ID: <20230202113322.cdumL4MTp0IbzacmTXawinlPAUhuxiqJjg-sQFnWuSY@z> The following fixes a problem with ! handling in genmatch which isn't conservative enough when intermediate simplifications push to the sequence but the final operation appears to just pick an existing (but in this case newly defined in the sequence) operand. The easiest fix is to disallow adding to the sequence when processing !. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR middle-end/108625 * genmatch.cc (expr::gen_transform): Also disallow resimplification from pushing to lseq with force_leaf. (dt_simplify::gen_1): Likewise. * gcc.dg/pr108625.c: New testcase. --- gcc/genmatch.cc | 6 ++++-- gcc/testsuite/gcc.dg/pr108625.c | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr108625.c diff --git a/gcc/genmatch.cc b/gcc/genmatch.cc index e147ab9db7a..43bd0212d0e 100644 --- a/gcc/genmatch.cc +++ b/gcc/genmatch.cc @@ -2541,7 +2541,8 @@ expr::gen_transform (FILE *f, int indent, const char *dest, bool gimple, for (unsigned i = 0; i < ops.length (); ++i) fprintf (f, ", _o%d[%u]", depth, i); fprintf (f, ");\n"); - fprintf_indent (f, indent, "tem_op.resimplify (lseq, valueize);\n"); + fprintf_indent (f, indent, "tem_op.resimplify (%s, valueize);\n", + !force_leaf ? "lseq" : "NULL"); fprintf_indent (f, indent, "_r%d = maybe_push_res_to_seq (&tem_op, %s);\n", depth, !force_leaf ? "lseq" : "NULL"); @@ -3451,7 +3452,8 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gimple, operand *result) if (!is_predicate) { fprintf_indent (f, indent, - "res_op->resimplify (lseq, valueize);\n"); + "res_op->resimplify (%s, valueize);\n", + !e->force_leaf ? "lseq" : "NULL"); if (e->force_leaf) fprintf_indent (f, indent, "if (!maybe_push_res_to_seq (res_op, NULL)) " diff --git a/gcc/testsuite/gcc.dg/pr108625.c b/gcc/testsuite/gcc.dg/pr108625.c new file mode 100644 index 00000000000..03fc2889c4f --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr108625.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-forwprop1 -fdump-tree-optimized" } */ + +unsigned char foo(int x) +{ + int t = -x; + unsigned char t1 = t; + unsigned char t2 = t; + /* We may not rewrite this as (unsigned char)(t - x). */ + return t1 + t2; +} + +/* { dg-final { scan-tree-dump-times "x_" 1 "forwprop1" } } */ +/* { dg-final { scan-tree-dump-times "x_" 1 "optimized" } } */ -- 2.35.3