From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x22e.google.com (mail-lj1-x22e.google.com [IPv6:2a00:1450:4864:20::22e]) by sourceware.org (Postfix) with ESMTPS id 6D6803857343 for ; Wed, 19 Jul 2023 07:15:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6D6803857343 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-x22e.google.com with SMTP id 38308e7fff4ca-2b743161832so100990681fa.1 for ; Wed, 19 Jul 2023 00:15:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689750929; x=1692342929; 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=ZP3pStcaev+dTbXbu/0/gVKTYdo2GwHNYLEf7bgdQ/o=; b=sMdzsYeJb3+rRiXQREDaVmTUZ8K8v5xdACl5wY2eNEw9biAmzApcg5DGPWxzkiA5oy XHeqz8Slu7ZPd+kFtRhcQuMLc8v3kmKMGahebWo75ZXkO0+YcvYw4MhvoTD1EBx7TKx5 CjMiZ5k3mnWu0doUfHZEFIbJOa+2rrcmSqc4riEmTJ0UritfbsRzhsF4JLP6ZCqmra2k SuUVAZ+EUsgzMfeNWjHkdkTL5E9Za2f8mhX+wgXzDz34f2KjL3CgpSuCNJH2Yswct6zF zdeh9ZEld+x2coeajjovoDb8gLJvCH6ofcpKc7WTnuIDoI/A7pGAM1ey6ocfX6vn3HHz JzYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689750929; x=1692342929; 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=ZP3pStcaev+dTbXbu/0/gVKTYdo2GwHNYLEf7bgdQ/o=; b=GHkS5NDmD0nWeC2TYNblKqqN1e9CVYYk4b55MfC1y33YUjPTdetPIlUaDuWMGYMrzs P6MRg1gdMpDCKJLndOJdgC4FPDX07l+WtQYSQ4kGaBsEFXpLPpY60aD3+g/9jbqo7Hp/ WpYSV6ExUT85izLDn2mLl550kefdXgLrBnLnHhQjR76w/mwAVHIYqEHxpoOHSLTEhb8s B+1E/INll2RYlgD1rm83aIDOUb8KYYTFCpxHctLseyTKPFIPw2pXGTt2ETX2bXOFiEqZ FzgWyvSDA7K+yEqn/78De/vmicYVkA+9p3rZTScamnlfDz5f22ptFphVz+xnxZEc+oDs s+vQ== X-Gm-Message-State: ABy/qLaFma5ePa+EpPvEleDygU02btMhtWOvevUHajLZtHphKlefZLrO amJF5MICDykg/lcraKZ/ZobNCzvWYehKCmHqozxoDmXe X-Google-Smtp-Source: APBJJlF2snKNycFTqGWNVtvzi1+HBNDIYHrOSW8bqITkVWrYUgkpZL14Gl0r/uutfgJrMVRr0Uh/hqfX4Zg3Vdk21Ng= X-Received: by 2002:a2e:8943:0:b0:2b6:ece0:a3c1 with SMTP id b3-20020a2e8943000000b002b6ece0a3c1mr1207028ljk.35.1689750928605; Wed, 19 Jul 2023 00:15:28 -0700 (PDT) MIME-Version: 1.0 References: <20230719015221.1383859-1-apinski@marvell.com> In-Reply-To: <20230719015221.1383859-1-apinski@marvell.com> From: Richard Biener Date: Wed, 19 Jul 2023 09:14:55 +0200 Message-ID: Subject: Re: [PATCH] Fix PR110726: a | (a == b) can sometimes produce 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.8 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, Jul 19, 2023 at 3:53=E2=80=AFAM Andrew Pinski via Gcc-patches wrote: > > So I had missed/forgot that EQ_EXPR could have an non boolean > type for generic when I implemented r14-2556-g0407ae8a7732d9. > This patch adds check for one bit precision intergal type > which fixes the problem. > > OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. > > PR tree-optimization/110726 > > gcc/ChangeLog: > > * match.pd ((a|b)&(a=3D=3Db),a|(a=3D=3Db),(a&b)|(a=3D=3Db)): > Add checks to make sure the type was one bit precision > intergal type. > > gcc/testsuite/ChangeLog: > > * gcc.c-torture/execute/bitops-1.c: New test. > --- > gcc/match.pd | 12 +++++-- > .../gcc.c-torture/execute/bitops-1.c | 33 +++++++++++++++++++ > 2 files changed, 42 insertions(+), 3 deletions(-) > create mode 100644 gcc/testsuite/gcc.c-torture/execute/bitops-1.c > > diff --git a/gcc/match.pd b/gcc/match.pd > index 054e6585876..4dfe92623f7 100644 > --- a/gcc/match.pd > +++ b/gcc/match.pd > @@ -1229,7 +1229,9 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > /* (a | b) & (a =3D=3D b) --> a & b (boolean version of the above). *= / > (simplify > (bit_and:c (bit_ior @0 @1) (nop_convert? (eq:c @0 @1))) > - (bit_and @0 @1)) > + (if (INTEGRAL_TYPE_P (TREE_TYPE (@0)) that's really a constraint on 'type', not sure if it would be clearer to test that. What's the nop_convert you've seen in practice here? With integer comparis= on result shouldn't those be convert? instead? > + && TYPE_PRECISION (TREE_TYPE (@0)) =3D=3D 1) > + (bit_and @0 @1))) > > /* a | ~(a ^ b) --> a | ~b */ > (simplify > @@ -1239,7 +1241,9 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > /* a | (a =3D=3D b) --> a | (b^1) (boolean version of the above). */ > (simplify > (bit_ior:c @0 (nop_convert? (eq:c @0 @1))) > - (bit_ior @0 (bit_xor @1 { build_one_cst (type); }))) > + (if (INTEGRAL_TYPE_P (TREE_TYPE (@0)) > + && TYPE_PRECISION (TREE_TYPE (@0)) =3D=3D 1) > + (bit_ior @0 (bit_xor @1 { build_one_cst (type); })))) > > /* (a | b) | (a &^ b) --> a | b */ > (for op (bit_and bit_xor) > @@ -1255,7 +1259,9 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > /* (a & b) | (a =3D=3D b) --> a =3D=3D b */ > (simplify > (bit_ior:c (bit_and:c @0 @1) (nop_convert?@2 (eq @0 @1))) > - @2) > + (if (INTEGRAL_TYPE_P (TREE_TYPE (@0)) > + && TYPE_PRECISION (TREE_TYPE (@0)) =3D=3D 1) > + @2)) > > /* ~(~a & b) --> a | ~b */ > (simplify > diff --git a/gcc/testsuite/gcc.c-torture/execute/bitops-1.c b/gcc/testsui= te/gcc.c-torture/execute/bitops-1.c > new file mode 100644 > index 00000000000..cfaa6b9fd26 > --- /dev/null > +++ b/gcc/testsuite/gcc.c-torture/execute/bitops-1.c > @@ -0,0 +1,33 @@ > +/* PR tree-optimization/110726 */ > + > +#define DECLS(n,VOL) \ > +__attribute__((noinline,noclone)) \ > +int h##n(VOL int A, VOL int B){ \ > + return (A | B) & (A =3D=3D B); \ > +} \ > +__attribute__((noinline,noclone)) \ > +int i##n(VOL int A, VOL int B){ \ > + return A | (A =3D=3D B); \ > +} \ > +__attribute__((noinline,noclone)) \ > +int k##n(VOL int A, VOL int B){ \ > + return (A & B) | (A =3D=3D B); \ > +} \ > + > +DECLS(0,) > +DECLS(1,volatile) > + > +int values[] =3D { 0, 1, 2, 3, -1, -2, -3, 0x10080 }; > +int numvalues =3D sizeof(values)/sizeof(values[0]); > + > +int main(){ > + for(int A =3D 0; A < numvalues; A++) > + for(int B =3D 0; B < numvalues; B++) > + { > + int a =3D values[A]; > + int b =3D values[B]; > + if (h0 (a, b) !=3D h1 (a, b)) __builtin_abort(); > + if (i0 (a, b) !=3D i1 (a, b)) __builtin_abort(); > + if (k0 (a, b) !=3D k1 (a, b)) __builtin_abort(); > + } > +} > -- > 2.31.1 >