From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [IPv6:2a00:1450:4864:20::12d]) by sourceware.org (Postfix) with ESMTPS id 84E763858D1E for ; Thu, 3 Aug 2023 07:22:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 84E763858D1E 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-lf1-x12d.google.com with SMTP id 2adb3069b0e04-4fe2503e3easo1033439e87.2 for ; Thu, 03 Aug 2023 00:22:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691047376; x=1691652176; 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=utzajzYpuaaQH/wJPoPa6xlD064nuVKM8zuudOVEOR4=; b=sbgezxMGesKuFoPV1a4icYQTcyW5l3JkDMIDjg4zEift3YRGqaIgAZZg3okvw1ikjF f3FjBCxcZeVkJIvX/meEyatbC7ex8FEYhUlYzKzlvWkFefdG2tNR5C06iNcUdrmnI9fP L5GgCBuSzP0meub+EYCNMC727vpXhMrwpYY+hKBzJ4hKec1QTBrjXqOm+M1xDKyifqXG JUqSnceOGFrL6wIh7qsiVy77HYw51JLIZSIxaWBSyFa9A7sf7KuSuS7d7B2ynuBd6XXl wPv+xZy84lHhulGNqx29zPJpQWKufjhsOTsy1Ermo99HIRG4ZH2b2HAOz8gCqfYx9iAz 0bvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691047376; x=1691652176; 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=utzajzYpuaaQH/wJPoPa6xlD064nuVKM8zuudOVEOR4=; b=kaGe97DHzE0fENIo87Q3LcAK3fr10xPWQch2p0eZKYsTLRvZH475r7NwjQSzuPslr9 ka33xmLQbmj4kpvw5tPvq3I465HApb6wYDepMN9H3Yko2iqBt+PrpdhzvhO5n5PXRjhs BT8FNaA+MjrI/lL/hhZLLPWk8NTfmSqWCm37i4dnakPWAJRHhxkXv+QsKr3oW+3sVLit Xly727/btkh9h3Fq68rzN1y1YFVNnQ41mKUqYcOD3gjaXIEQaBV6Em1LeY3bVH9qGJoH R2Yf18LIkOK5F/BEqJ8omMLiq5s8TfXCCmNtpkAp5UQYJqB+G7BOaPVHdoqvY+WIUtB+ rT2Q== X-Gm-Message-State: ABy/qLaQ+M5BEkQob/tSvNvbxS7pjL6/AVHJpbARYi8VMGBR/FI0iL3a SufNTr1Lr0mR9teNmPx4nc+SsjkoJ+Nym5fRgzNSx7vu X-Google-Smtp-Source: APBJJlGpA2l2xTqjVCOee+4WwPKpM8R+b4YcbTjSv5QhtdY4iATiL8hQ3QCgX95bS7RHHSiYixZ2I0VCUuDBpGuO5DI= X-Received: by 2002:a2e:840b:0:b0:2b6:eb68:fe76 with SMTP id z11-20020a2e840b000000b002b6eb68fe76mr6327704ljg.25.1691047375603; Thu, 03 Aug 2023 00:22:55 -0700 (PDT) MIME-Version: 1.0 References: <20230803023404.2271442-1-apinski@marvell.com> In-Reply-To: <20230803023404.2271442-1-apinski@marvell.com> From: Richard Biener Date: Thu, 3 Aug 2023 09:21:57 +0200 Message-ID: Subject: Re: [PATCH] Fix PR 110874: infinite loop in gimple_bitwise_inverted_equal_p with fre 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 Thu, Aug 3, 2023 at 4:34=E2=80=AFAM Andrew Pinski via Gcc-patches wrote: > > So I didn't expect valueization to cause calling gimple_nop_convert > to iterate between 2 different SSA names causing an infinite loop > in gimple_bitwise_inverted_equal_p. > So we should cause a bound on gimple_bitwise_inverted_equal_p calling > gimple_nop_convert and only look through one rather than always. > > OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. > > gcc/ChangeLog: > > PR tree-optimization/110874 > * gimple-match-head.cc (gimple_bitwise_inverted_equal_p): > Add new argument, again with default value of true. > Don't try gimple_nop_convert if again is false. > Update call to gimple_bitwise_inverted_equal_p for > new argument. > > gcc/testsuite/ChangeLog: > > PR tree-optimization/110874 > * gcc.c-torture/compile/pr110874-a.c: New test. > --- > gcc/gimple-match-head.cc | 14 +++++++++----- > .../gcc.c-torture/compile/pr110874-a.c | 17 +++++++++++++++++ > 2 files changed, 26 insertions(+), 5 deletions(-) > create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr110874-a.c > > diff --git a/gcc/gimple-match-head.cc b/gcc/gimple-match-head.cc > index b1e96304d7c..e91aaab86dd 100644 > --- a/gcc/gimple-match-head.cc > +++ b/gcc/gimple-match-head.cc > @@ -273,7 +273,7 @@ gimple_bitwise_equal_p (tree expr1, tree expr2, tree = (*valueize) (tree)) > /* Helper function for bitwise_equal_p macro. */ > > static inline bool > -gimple_bitwise_inverted_equal_p (tree expr1, tree expr2, tree (*valueize= ) (tree)) > +gimple_bitwise_inverted_equal_p (tree expr1, tree expr2, tree (*valueize= ) (tree), bool again =3D true) > { > if (expr1 =3D=3D expr2) > return false; > @@ -285,12 +285,16 @@ gimple_bitwise_inverted_equal_p (tree expr1, tree e= xpr2, tree (*valueize) (tree) > return false; > > tree other; > - if (gimple_nop_convert (expr1, &other, valueize) > - && gimple_bitwise_inverted_equal_p (other, expr2, valueize)) > + if (again > + && gimple_nop_convert (expr1, &other, valueize) > + && other !=3D expr1 > + && gimple_bitwise_inverted_equal_p (other, expr2, valueize, false)= ) > return true; > > - if (gimple_nop_convert (expr2, &other, valueize) > - && gimple_bitwise_inverted_equal_p (expr1, other, valueize)) > + if (again > + && gimple_nop_convert (expr2, &other, valueize) > + && other !=3D expr2 > + && gimple_bitwise_inverted_equal_p (expr1, other, valueize, false)= ) > return true; Hmm, I don't think this tests all three relevant combinations? I think the= way gimple_bitwise_equal_p handles this is better (not recursing). I'd split o= ut the "tail" matching the BIT_NOT to another helper, I suppose that could even be a (match ...) pattern here. > if (TREE_CODE (expr1) !=3D SSA_NAME > diff --git a/gcc/testsuite/gcc.c-torture/compile/pr110874-a.c b/gcc/tests= uite/gcc.c-torture/compile/pr110874-a.c > new file mode 100644 > index 00000000000..b314410a892 > --- /dev/null > +++ b/gcc/testsuite/gcc.c-torture/compile/pr110874-a.c > @@ -0,0 +1,17 @@ > +struct S1 { > + unsigned f0; > +}; > +static int g_161; > +void func_109(unsigned g_227, unsigned t) { > + struct S1 l_178; > + int l_160 =3D 0x1FAE99D5L; > + int *l_230[] =3D {&l_160}; > + if (l_160) { > + for (l_178.f0 =3D -7; l_178.f0;) { > + ++g_227; > + break; > + } > + (g_161) =3D g_227; > + } > + (g_161) &=3D t; > +} > -- > 2.31.1 >