From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-x732.google.com (mail-qk1-x732.google.com [IPv6:2607:f8b0:4864:20::732]) by sourceware.org (Postfix) with ESMTPS id D33D5385782B for ; Mon, 17 Jul 2023 06:21:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D33D5385782B 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-qk1-x732.google.com with SMTP id af79cd13be357-7653bd3ff2fso494675785a.3 for ; Sun, 16 Jul 2023 23:21:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689574865; x=1692166865; 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=Fvi8CbyA0PF5++AUH0fcglS/YV2MejH1/HsJGsHgY0U=; b=ILZ0CrAe9MjdBvpe+v2qi5/2jb8/aKDLjpH9sXc2J4Z0Ofyn9yd1a5gMwyCsa32cu5 y2K2NXelNRPTc0QkYsXgHRaSB4fq7j+0hEzS4SId6EFQRW8QDpWTGZ+2aEFN/uEHvKUr MYgpR5WjhjhC7LpenKitN5SQeFAjDULIVkXiML6r3iVIdV8e+7Sct8dxvx0xqUIVEH07 qBiVlz3cD1Mo6bPgMgTC535efC2Bs6AozTxVpCFs8r7WlY8mwkuT7+4At+iVmi9xKXC/ k6FoLbeHZazEMgPQ5U6Mgw4Xbn9qKf/9gvmCe7MOgxS3Y3Pa9sc+qCeCHmD2xP0OyvYy VZSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689574865; x=1692166865; 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=Fvi8CbyA0PF5++AUH0fcglS/YV2MejH1/HsJGsHgY0U=; b=MsDQ9f0LrfIj4wKlWDsyM49vAky/qqLZ+GB3E1FInrmF7l+KGJhqOV7J3eVYDImsOJ V1j1eTZvIb0PM5uywh/AQq9bLOkFTPip/Xj7TgGKAsnFJXR8U9qX1unrvEiAZ9e6tuqH 92nSVuGRs58pKonjFlssfDmUVjKoSim2gnDJLfaisuPDjHkVDdOfyvEJOzuR3nkpIw1s CLif9qf3VUL1pZIiY6cDDCr5oGXqpryRnQDOY5se1zNE0sS5z8K2pKpe4nVOELvDVEZF c+FBqbzm3REtVRok2StbpKEQcdqeLpiaG5QUu7aPwZUOFGf4Tp2mrcPdF4Eoxz0qd6fp 8o2A== X-Gm-Message-State: ABy/qLaDfmwQpPBY4PXQDrrdcofRuoKzIawbUayIosbbZ3EWf/I/qpba VupoZqvjxzV5fLOtw4BE5bV1pwXCg1tC/g+PEez+VIl+ X-Google-Smtp-Source: APBJJlHZUWa5l/D3NaTTV4UpUAqu1SmwJE284/DcHToFHneQBRMDxkK3dmdlij7Ueny0J5+zbIS7W4fD6WwXycZSTNM= X-Received: by 2002:a05:620a:80d:b0:767:e785:15cb with SMTP id s13-20020a05620a080d00b00767e78515cbmr13927200qks.76.1689574865203; Sun, 16 Jul 2023 23:21:05 -0700 (PDT) MIME-Version: 1.0 References: <20230714205542.1131700-1-apinski@marvell.com> In-Reply-To: <20230714205542.1131700-1-apinski@marvell.com> From: Richard Biener Date: Mon, 17 Jul 2023 08:20:21 +0200 Message-ID: Subject: Re: [PATCH] Fix PR 110666: `(a != 2) == a` produces wrong code 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.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,SCC_5_SHORT_WORD_LINES,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 Fri, Jul 14, 2023 at 10:56=E2=80=AFPM Andrew Pinski via Gcc-patches wrote: > > I had messed up the case where the outer operator is `=3D=3D`. > The check for the resulting should have been `=3D=3D` and not `!=3D`. > This patch fixes that and adds a full runtime testcase now for > all cases to make sure it works. > > OK? Bootstrapped and tested on x86-64-linux-gnu with no regressions. OK. > gcc/ChangeLog: > > PR tree-optimization/110666 > * match.pd (A NEEQ (A NEEQ CST)): Fix Outer EQ case. > > gcc/testsuite/ChangeLog: > > PR tree-optimization/110666 > * gcc.c-torture/execute/pr110666-1.c: New test. > --- > gcc/match.pd | 34 ++++++++----- > .../gcc.c-torture/execute/pr110666-1.c | 51 +++++++++++++++++++ > 2 files changed, 71 insertions(+), 14 deletions(-) > create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr110666-1.c > > diff --git a/gcc/match.pd b/gcc/match.pd > index 351d9285e92..88061fa4a6f 100644 > --- a/gcc/match.pd > +++ b/gcc/match.pd > @@ -6431,8 +6431,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > > /* x !=3D (typeof x)(x =3D=3D CST) -> CST =3D=3D 0 ? 1 : (CST =3D=3D 1 ?= (x!=3D0&&x!=3D1) : x !=3D 0) */ > /* x !=3D (typeof x)(x !=3D CST) -> CST =3D=3D 1 ? 1 : (CST =3D=3D 0 ? (= x!=3D0&&x!=3D1) : x !=3D 1) */ > -/* x =3D=3D (typeof x)(x =3D=3D CST) -> CST =3D=3D 0 ? 0 : (CST =3D=3D 1= ? (x=3D=3D0||x=3D=3D1) : x !=3D 0) */ > -/* x =3D=3D (typeof x)(x !=3D CST) -> CST =3D=3D 1 ? 0 : (CST =3D=3D 0 ?= (x=3D=3D0||x=3D=3D1) : x !=3D 1) */ > +/* x =3D=3D (typeof x)(x =3D=3D CST) -> CST =3D=3D 0 ? 0 : (CST =3D=3D 1= ? (x=3D=3D0||x=3D=3D1) : x =3D=3D 0) */ > +/* x =3D=3D (typeof x)(x !=3D CST) -> CST =3D=3D 1 ? 0 : (CST =3D=3D 0 ?= (x=3D=3D0||x=3D=3D1) : x =3D=3D 1) */ > (for outer (ne eq) > (for inner (ne eq) > (simplify > @@ -6443,23 +6443,29 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > bool innereq =3D inner =3D=3D EQ_EXPR; > bool outereq =3D outer =3D=3D EQ_EXPR; > } > - (switch > - (if (innereq ? cst0 : cst1) > - { constant_boolean_node (!outereq, type); }) > - (if (innereq ? cst1 : cst0) > + (switch > + (if (innereq ? cst0 : cst1) > + { constant_boolean_node (!outereq, type); }) > + (if (innereq ? cst1 : cst0) > + (with { > + tree utype =3D unsigned_type_for (TREE_TYPE (@0)); > + tree ucst1 =3D build_one_cst (utype); > + } > + (if (!outereq) > + (gt (convert:utype @0) { ucst1; }) > + (le (convert:utype @0) { ucst1; }) > + ) > + ) > + ) > (with { > - tree utype =3D unsigned_type_for (TREE_TYPE (@0)); > - tree ucst1 =3D build_one_cst (utype); > + tree value =3D build_int_cst (TREE_TYPE (@0), !innereq); > } > - (if (!outereq) > - (gt (convert:utype @0) { ucst1; }) > - (le (convert:utype @0) { ucst1; }) > + (if (outereq) > + (eq @0 { value; }) > + (ne @0 { value; }) > ) > ) > ) > - (if (innereq) > - (ne @0 { build_zero_cst (TREE_TYPE (@0)); })) > - (ne @0 { build_one_cst (TREE_TYPE (@0)); })) > ) > ) > ) > diff --git a/gcc/testsuite/gcc.c-torture/execute/pr110666-1.c b/gcc/tests= uite/gcc.c-torture/execute/pr110666-1.c > new file mode 100644 > index 00000000000..b22eb7781da > --- /dev/null > +++ b/gcc/testsuite/gcc.c-torture/execute/pr110666-1.c > @@ -0,0 +1,51 @@ > + > +#define func_name(outer,inner,cst) outer##inner##_##cst > +#define func_name_v(outer,inner,cst) outer##inner##_##cst##_v > + > +#define func_decl(outer,inner,cst) \ > +int outer##inner##_##cst (int) __attribute__((noipa)); \ > +int outer##inner##_##cst (int a) { \ > + return (a op_##inner cst) op_##outer a; \ > +} \ > +int outer##inner##_##cst##_v (int) __attribute__((noipa)); \ > +int outer##inner##_##cst##_v (volatile int a) { \ > + return (a op_##inner cst) op_##outer a; \ > +} > + > +#define functions_n(outer, inner) \ > +func_decl(outer,inner,0) \ > +func_decl(outer,inner,1) \ > +func_decl(outer,inner,2) > + > +#define functions() \ > +functions_n(eq,eq) \ > +functions_n(eq,ne) \ > +functions_n(ne,eq) \ > +functions_n(ne,ne) > + > +#define op_ne !=3D > +#define op_eq =3D=3D > + > +#define test(inner,outer,cst,arg) \ > +func_name_v (inner,outer,cst)(arg) !=3D func_name(inner,outer,cst)(arg) > + > +functions() > + > +#define tests_n(inner,outer,arg) \ > +if (test(inner,outer,0,arg)) __builtin_abort(); \ > +if (test(inner,outer,1,arg)) __builtin_abort(); \ > +if (test(inner,outer,2,arg)) __builtin_abort(); > + > +#define tests(arg) \ > +tests_n(eq,eq,arg) \ > +tests_n(eq,ne,arg) \ > +tests_n(ne,eq,arg) \ > +tests_n(ne,ne,arg) > + > + > +int main() > +{ > + for(int n =3D -1; n <=3D 2; n++) { > + tests(n) > + } > +} > -- > 2.31.1 >