From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by sourceware.org (Postfix) with ESMTPS id 3EB0A3858D39 for ; Wed, 24 May 2023 16:43:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3EB0A3858D39 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-x1029.google.com with SMTP id 98e67ed59e1d1-2535edae73cso441961a91.2 for ; Wed, 24 May 2023 09:43:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684946589; x=1687538589; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=EwT/UdN+DXz0nbY8Q+pHoO7+RF+GMjNLXyCkzJywRvk=; b=O20ntF6ppSnIt4vEGCY4qr8j0T5MTUhqoPcVYKtfY+T56jftp99LOq8Cp4JzieXzZ/ D7nutOdzT4/+r7BLLKBFtH4WXXOP4AewfC8xmg2tL+tsIBQ97OhkUXqsaIKN+ivDXuAc sd0/j6D9dpHMmQWHVsUr98W3ZTq7XN6RUXc0vzYmuOTWafwz0rlyLDGaqWEAcaHMhxkv oaTuLqR9hA9fIBTZ9YuQ7lc8howBvOAXyeDuo66mT/+vNc5kovMXvDdJuMp2Fmv5jB/E 6a9Lvhy1yRpCe3Vc2MRALdA0rhLIQ6YpSKRjUrispat5SzUGidHI/ODyfqoOSC1DlwV5 ywxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684946589; x=1687538589; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EwT/UdN+DXz0nbY8Q+pHoO7+RF+GMjNLXyCkzJywRvk=; b=NLF5JRxlid+WwI6YFRjpxosLqa341U2tRQu3QKRC+qMnJMtK43oNCx73TTsugGSl/V PNhPAU7saw3K8Ur31Yf3Ypmacc8BAGnfrsFHBow7G0au5Tp+gOpYuPtaaqKluRBaL26c wI6vpicS7lEdG+w/cvNQKeexv0vPOYBr8KCfjv1gX0OfcVWDFmQj6bKHDC55+nIvGDwg ijD0q6yQyMgZZIzq0Vmu/b95Rfjos7jU7Bv/g1MA31FJKdG3uBR0Rtp6zXsEEdC0gmLP VeS5OK0TICbZ7iuIsMZa7gmVEw/u/HUoRx8/y3Cr4yYl3T8Xb05dyefjMgiD89WZF8Sv S/vg== X-Gm-Message-State: AC+VfDwPnhIlcOlpyaZPcoXFTpHFGwHK8KBM33ySoFkeo7q0W32tMP7P 2+Cj82hviIo/WyED0wJVTINVbaTu9gA+bRpVoKc= X-Google-Smtp-Source: ACHHUZ6tL66GKMgOkVGqycUyVp8oQiXiDhN1hSLxt9mdy7Hqrhn1aGrGfhG4ohBdk7nUvuaUhUUpIu4RRrnwh36mAxw= X-Received: by 2002:a17:90a:ab06:b0:255:8a33:858c with SMTP id m6-20020a17090aab0600b002558a33858cmr7814603pjq.23.1684946589061; Wed, 24 May 2023 09:43:09 -0700 (PDT) MIME-Version: 1.0 References: <20230523231601.2130715-1-apinski@marvell.com> In-Reply-To: From: Andrew Pinski Date: Wed, 24 May 2023 09:42:56 -0700 Message-ID: Subject: Re: [PATCH] Dump if a pattern fails after having printed applying it To: Richard Biener Cc: Andrew Pinski , gcc-patches@gcc.gnu.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,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 List-Id: On Wed, May 24, 2023 at 2:03=E2=80=AFAM Richard Biener via Gcc-patches wrote: > > On Wed, May 24, 2023 at 1:16=E2=80=AFAM Andrew Pinski via Gcc-patches > wrote: > > > > While trying to understand how to use the ! operand for match > > patterns, I noticed that the debug dumps would print out applying > > a pattern but nothing when it was rejected in the end. This was confusi= ng > > me. > > This adds that by emitting a dump for the failed case. > > Note the patch is little more complex as we don't want to print out > > if debug counter rejected the pattern and then we need to fix up > > when we mark needing a label or not. > > > > OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. > > Hmm, can we maybe simply move the > > if (UNLIKELY > (debug_dump)) fprintf (dump_file, "Applying pattern %s:%d, %s:%d\n", > "match.pd", 1157, __FILE__, __LINE__); > > right before the return true; instead? Yes that should work. Let me do a patch for that. Thanks, Andrew > > > gcc/ChangeLog: > > > > * genmatch.cc (needs_label): New variable > > (expr::gen_transform): Set needs_label > > if we use the local_label. > > (dt_simplify::gen_1): Use `_1` for the debug count label. > > After the local label, emit debug print for the failure. > > Emit `_1` label if needed. > > --- > > gcc/genmatch.cc | 28 ++++++++++++++++++++++++---- > > 1 file changed, 24 insertions(+), 4 deletions(-) > > > > diff --git a/gcc/genmatch.cc b/gcc/genmatch.cc > > index 177c13d87cb..2ea80d341a2 100644 > > --- a/gcc/genmatch.cc > > +++ b/gcc/genmatch.cc > > @@ -2433,6 +2433,7 @@ capture_info::walk_c_expr (c_expr *e) > > /* The current label failing the current matched pattern during > > code generation. */ > > static char *fail_label; > > +static bool needs_label; > > > > /* Code generation off the decision tree and the refered AST nodes. *= / > > > > @@ -2611,6 +2612,7 @@ expr::gen_transform (FILE *f, int indent, const c= har *dest, bool gimple, > > fprintf_indent (f, indent, > > "if (!_r%d) goto %s;\n", > > depth, fail_label); > > + needs_label =3D true; > > if (*opr =3D=3D CONVERT_EXPR) > > { > > indent -=3D 4; > > @@ -2640,11 +2642,13 @@ expr::gen_transform (FILE *f, int indent, const= char *dest, bool gimple, > > { > > fprintf_indent (f, indent, "if (!_r%d)\n", depth); > > fprintf_indent (f, indent, " goto %s;\n", fail_label); > > + needs_label =3D true; > > } > > if (force_leaf) > > { > > fprintf_indent (f, indent, "if (EXPR_P (_r%d))\n", depth); > > fprintf_indent (f, indent, " goto %s;\n", fail_label); > > + needs_label =3D true; > > } > > if (*opr =3D=3D CONVERT_EXPR) > > { > > @@ -3409,7 +3413,8 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gim= ple, operand *result) > > char local_fail_label[256]; > > snprintf (local_fail_label, 256, "next_after_fail%u", ++fail_label_c= nt); > > fail_label =3D local_fail_label; > > - bool needs_label =3D false; > > + needs_label =3D false; > > + bool needs_label_1 =3D false; > > > > /* Analyze captures and perform early-outs on the incoming arguments > > that cover cases we cannot handle. */ > > @@ -3484,8 +3489,8 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gim= ple, operand *result) > > > > if (s->kind =3D=3D simplify::SIMPLIFY) > > { > > - fprintf_indent (f, indent, "if (UNLIKELY (!dbg_cnt (match))) got= o %s;\n", fail_label); > > - needs_label =3D true; > > + fprintf_indent (f, indent, "if (UNLIKELY (!dbg_cnt (match))) got= o %s_1;\n", fail_label); > > + needs_label_1 =3D true; > > } > > > > fprintf_indent (f, indent, "if (UNLIKELY (debug_dump)) " > > @@ -3718,7 +3723,22 @@ dt_simplify::gen_1 (FILE *f, int indent, bool gi= mple, operand *result) > > indent -=3D 2; > > fprintf_indent (f, indent, "}\n"); > > if (needs_label) > > - fprintf (f, "%s:;\n", fail_label); > > + { > > + fprintf (f, "%s:;\n", fail_label); > > + if (s->kind =3D=3D simplify::SIMPLIFY) > > + { > > + fprintf_indent (f, indent, "if (UNLIKELY (debug_dump)) " > > + "fprintf (dump_file, \"Pattern failed "); > > + fprintf (f, "%%s:%%d, %%s:%%d\\n\", "); > > + output_line_directive (f, > > + result ? result->location : s->match->= location, true, > > + true); > > + fprintf (f, ", __FILE__, __LINE__);\n"); > > + } > > + } > > + if (needs_label_1) > > + fprintf (f, "%s_1:;\n", fail_label); > > + needs_label =3D false; > > fail_label =3D NULL; > > } > > > > -- > > 2.31.1 > >