From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x234.google.com (mail-lj1-x234.google.com [IPv6:2a00:1450:4864:20::234]) by sourceware.org (Postfix) with ESMTPS id 6B76E3857710 for ; Wed, 24 May 2023 09:02:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6B76E3857710 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-lj1-x234.google.com with SMTP id 38308e7fff4ca-2af28a07be9so9378251fa.2 for ; Wed, 24 May 2023 02:02:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684918929; x=1687510929; 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=gGTTSiTTGh8upzTNhXwM3ZVof6o6hiVDwQIXol4IRxA=; b=oBRP+iYcNqHC4fSURVwo4HcclUsH6+cSeZsq7YEsr3pEV65qy2liHBjuvMxW0qq0aj SNBGc6X439GNlLRas2JBaOBhahz9hSpVEa3s/uwwdWelO2OWMPrp8zxD23J6iLeXUumf 1WLR19nCEOOcEsOULSfWOwyQTlC/ntPX3OoES8AfPpa47ZW/+Kkt5GuSaV+hbeZmS0Hv R3LBMJx0I+4T91BsF1QnCQIhDJQcHEEBxkQJMnw/qp0aRbAZUG0ETFxkTbGbzAGQmV3/ 6hdA2Er5DN3vTv9+gm4F2VuWWrjkwsVQVk3kSyeba0LX4atf2F48Gz2Y/P7pX+AVx2rC 3Q0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684918929; x=1687510929; 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=gGTTSiTTGh8upzTNhXwM3ZVof6o6hiVDwQIXol4IRxA=; b=KTJ5l24D4zRGA4SgfdOjCOOawr5jgOtxlHM12pnPoCJM+F6hESy9l60po5+Wf14YXQ d23ZwHphooy31KnYjZjRjlTkAhxR6DtwJvWVL/f2Z5rQCuptr0fknhAbWxggjVOtuHwc Ir6obfN/SRjKM4wIKrht0S0RJ0Oh8sY9wkZt0YPlD6sfG/wpEMyqgsQwra+8sVu1zlcJ CvdQABZjk0hTruU9b5kAEB/6UA3WXyy/fBzxvA+vO/ZKEheqitvthJ0w6N+MddVa7hrY xne60uimTXmzYhs2r0NLG8Vg91E1GFcuKKumoFpw40Xx/A91xWSTlFSh7TcsfjRsrLah iMbg== X-Gm-Message-State: AC+VfDxwcGj+39RFoRuZ5hveS6hof6dmR7LbT0kbZK7eLm/iCjYMKYcB 26gK7ZQt7QZd6C6WPxsYs0HGQzA074NwBugfeg7GQ5w1kEA= X-Google-Smtp-Source: ACHHUZ6Oj/yASoVoAXaub8Jj6rEdbURX2W49NQ63xgHPq2FtfwKBxGUfxt4IyZoFy7PmZDntQlzygD3I1e4IMWF0UYs= X-Received: by 2002:a2e:99d4:0:b0:2ad:b1cb:faed with SMTP id l20-20020a2e99d4000000b002adb1cbfaedmr6533344ljj.7.1684918928571; Wed, 24 May 2023 02:02:08 -0700 (PDT) MIME-Version: 1.0 References: <20230523231601.2130715-1-apinski@marvell.com> In-Reply-To: <20230523231601.2130715-1-apinski@marvell.com> From: Richard Biener Date: Wed, 24 May 2023 11:00:02 +0200 Message-ID: Subject: Re: [PATCH] Dump if a pattern fails after having printed applying it To: Andrew Pinski Cc: gcc-patches@gcc.gnu.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-7.4 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 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 confusing > 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? > 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 cha= r *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 c= har *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 gimpl= e, operand *result) > char local_fail_label[256]; > snprintf (local_fail_label, 256, "next_after_fail%u", ++fail_label_cnt= ); > 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 gimpl= e, operand *result) > > if (s->kind =3D=3D simplify::SIMPLIFY) > { > - fprintf_indent (f, indent, "if (UNLIKELY (!dbg_cnt (match))) goto = %s;\n", fail_label); > - needs_label =3D true; > + fprintf_indent (f, indent, "if (UNLIKELY (!dbg_cnt (match))) goto = %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 gimp= le, 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->lo= cation, 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 >