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 3703C3858C53 for ; Thu, 24 Aug 2023 06:36:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3703C3858C53 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-2bceb02fd2bso2136451fa.1 for ; Wed, 23 Aug 2023 23:36:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1692859015; x=1693463815; 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=f9E3yqCG9TIE3pkWZBHR4/SCV4/gEHKlUVTD00vTljQ=; b=r/7ImE2Mui64HeQ4uXsOe1QsZq9zDvbCXJB7sGM86uYttWVwfutmpumpPbghy4rGEr OBYobYBb70u+xDmGds+0Mfk+LMJjlarTLAekzSR1hIyDHuk83G3140E2QTcPtQogHSRZ Ho7ourFc8vhAbdreU2fP2COaSsi3VTNTbl3BFConcEY4ajShKuFx02IuPZSiHQDL1Ll2 d4U+bUhfGk4QsOURpHBG9QbeofPqA738gZ1Fe94wjq+nAb5TYuqsKW63pnSn0JKFnXDQ N02cQ83abuJHgw6N3lVGT+QKOdl3TZmrFD/CHCA4Y4zrfaV8q15WPGqtS5VjgNgce8QB 5TWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692859015; x=1693463815; 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=f9E3yqCG9TIE3pkWZBHR4/SCV4/gEHKlUVTD00vTljQ=; b=bUGclhk6gMq4pa8RCfxnFfmeZEyzEzHGEl9YYcbeaTADLrdcBWJxiliG20+AHfx5um oxwaFPXw1YP0xaY3kyeBbBPzcTF/m1YLIkK220coRy1YsZtfCrG4lLCpzchm25PSu0R2 cQZDzbDlGrgqPHF41/hyqVEkOBqZs9FoCCHwu0AYNzFucmIyYa1CH6YNxPC6kSQqO9TR abtQuGJVnEzJMQEv3wphgOUS9QlGvVmH9UYMKa2PVIPkYb/Kov2zhRea9P74sm+xy9iP gCecurLFovat8GjyfoWxWsSDxRpxBodkjYZrmET8HEXtj+0HifS9cFCMBXsELNqHnCt6 n7rA== X-Gm-Message-State: AOJu0YwfS1rVe3+MGrmTyKTB2m/wdxDlFUeDwlfA3hvBIrHzib2lkB2a Iipiw37G8Qc6PTq7bTh737Qq93Z6+Rfau1iunOg= X-Google-Smtp-Source: AGHT+IG2qLC49Y0DZLva+jM3Osc7w7v9MnFGBQFp3Fsacl4559iUcMfp+nvOHpZ2eX+EKSIdKJgbfANzGaA7p+eB2uk= X-Received: by 2002:a2e:8914:0:b0:2b9:3db7:322f with SMTP id d20-20020a2e8914000000b002b93db7322fmr11893693lji.18.1692859015286; Wed, 23 Aug 2023 23:36:55 -0700 (PDT) MIME-Version: 1.0 References: <20230823214955.3494903-1-apinski@marvell.com> In-Reply-To: <20230823214955.3494903-1-apinski@marvell.com> From: Richard Biener Date: Thu, 24 Aug 2023 08:35:23 +0200 Message-ID: Subject: Re: [PATCH] MATCH: [PR111109] Fix bit_ior(cond, cond) when comparisons are fp 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 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, Aug 23, 2023 at 11:51=E2=80=AFPM Andrew Pinski via Gcc-patches wrote: > > The patterns that were added in r13-4620-g4d9db4bdd458, missed that > (a > b) and (a <=3D b) are not inverse of each other for floating point > comparisons (if NaNs are supported). Even though there was a check for > intergal types, it was only for the result of the cond rather for the > type of what is being compared. The fix is to check to see if cmp and > icmp are inverse of each other by using the invert_tree_comparison functi= on. > > OK for trunk and GCC 13 branch? Bootstrapped and tested on x86_64-linux-g= nu with no regressions. OK. Thanks, Richard. > I added the testcase to execute/ieee as it requires support for NAN. > > PR tree-optimization/111109 > > gcc/ChangeLog: > > * match.pd (ior(cond,cond), ior(vec_cond,vec_cond)): > Add check to make sure cmp and icmp are inverse. > > gcc/testsuite/ChangeLog: > > * gcc.c-torture/execute/ieee/fp-cmp-cond-1.c: New test. > --- > gcc/match.pd | 11 ++- > .../execute/ieee/fp-cmp-cond-1.c | 78 +++++++++++++++++++ > 2 files changed, 86 insertions(+), 3 deletions(-) > create mode 100644 gcc/testsuite/gcc.c-torture/execute/ieee/fp-cmp-cond-= 1.c > > diff --git a/gcc/match.pd b/gcc/match.pd > index 85b7d323a19..b666d73b189 100644 > --- a/gcc/match.pd > +++ b/gcc/match.pd > @@ -2087,6 +2087,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > (bit_and:c (convert? (cmp@0 @01 @02)) @3) > (bit_and:c (convert? (icmp@4 @01 @02)) @5)) > (if (INTEGRAL_TYPE_P (type) > + && invert_tree_comparison (cmp, HONOR_NANS (@01)) =3D=3D icmp > /* The scalar version has to be canonicalized after vectorizatio= n > because it makes unconditional loads conditional ones, which > means we lose vectorization because the loads may trap. */ > @@ -2101,6 +2102,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > (cond (cmp@0 @01 @02) @3 zerop) > (cond (icmp@4 @01 @02) @5 zerop)) > (if (INTEGRAL_TYPE_P (type) > + && invert_tree_comparison (cmp, HONOR_NANS (@01)) =3D=3D icmp > /* The scalar version has to be canonicalized after vectorizatio= n > because it makes unconditional loads conditional ones, which > means we lose vectorization because the loads may trap. */ > @@ -2113,13 +2115,15 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > (bit_ior > (bit_and:c (vec_cond:s (cmp@0 @6 @7) @4 @5) @2) > (bit_and:c (vec_cond:s (icmp@1 @6 @7) @4 @5) @3)) > - (if (integer_zerop (@5)) > + (if (integer_zerop (@5) > + && invert_tree_comparison (cmp, HONOR_NANS (@6)) =3D=3D icmp) > (switch > (if (integer_onep (@4)) > (bit_and (vec_cond @0 @2 @3) @4)) > (if (integer_minus_onep (@4)) > (vec_cond @0 @2 @3))) > - (if (integer_zerop (@4)) > + (if (integer_zerop (@4) > + && invert_tree_comparison (cmp, HONOR_NANS (@6)) =3D=3D icmp) > (switch > (if (integer_onep (@5)) > (bit_and (vec_cond @0 @3 @2) @5)) > @@ -2132,7 +2136,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > (bit_ior > (vec_cond:s (cmp@0 @4 @5) @2 integer_zerop) > (vec_cond:s (icmp@1 @4 @5) @3 integer_zerop)) > - (vec_cond @0 @2 @3))) > + (if (invert_tree_comparison (cmp, HONOR_NANS (@4)) =3D=3D icmp) > + (vec_cond @0 @2 @3)))) > > /* Transform X & -Y into X * Y when Y is { 0 or 1 }. */ > (simplify > diff --git a/gcc/testsuite/gcc.c-torture/execute/ieee/fp-cmp-cond-1.c b/g= cc/testsuite/gcc.c-torture/execute/ieee/fp-cmp-cond-1.c > new file mode 100644 > index 00000000000..4a3c4b0eee2 > --- /dev/null > +++ b/gcc/testsuite/gcc.c-torture/execute/ieee/fp-cmp-cond-1.c > @@ -0,0 +1,78 @@ > +/* PR tree-optimization/111109 */ > + > +/* > + f should return 0 if either fa and fb are a nan. > + Rather than the value of a or b. > +*/ > +__attribute__((noipa)) > +int f(int a, int b, float fa, float fb) { > + const _Bool c =3D fa < fb; > + const _Bool c1 =3D fa >=3D fb; > + return (c * a) | (c1 * b); > +} > + > +/* > + f1 should return 0 if either fa and fb are a nan. > + Rather than the value of a&1 or b&1. > +*/ > +__attribute__((noipa)) > +int f1(int a, int b, float fa, float fb) { > + const _Bool c =3D fa < fb; > + const _Bool c1 =3D fa >=3D fb; > + return (c & a) | (c1 & b); > +} > + > +#if __SIZEOF_INT__ =3D=3D __SIZEOF_FLOAT__ > +typedef int v4si __attribute__ ((vector_size (1*sizeof(int)))); > +typedef float v4sf __attribute__ ((vector_size (1*sizeof(float)))); > +/* > + fvf0 should return {0} if either fa and fb are a nan. > + Rather than the value of a or b. > +*/ > +__attribute__((noipa)) > +v4si vf0(v4si a, v4si b, v4sf fa, v4sf fb) { > + const v4si c =3D fa < fb; > + const v4si c1 =3D fa >=3D fb; > + return (c & a) | (c1 & b); > +} > + > + > +#endif > + > +int main(void) > +{ > + float a =3D __builtin_nan(""); > + > + if (f(-1,-1, a, a) !=3D 0) > + __builtin_abort(); > + if (f(-1,-1, a, 0) !=3D 0) > + __builtin_abort(); > + if (f(-1,-1, 0, a) !=3D 0) > + __builtin_abort(); > + if (f(-1,-1, 0, 0) !=3D -1) > + __builtin_abort(); > + > + > + if (f1(1,1, a, a) !=3D 0) > + __builtin_abort(); > + if (f1(1,1, a, 0) !=3D 0) > + __builtin_abort(); > + if (f1(1,1, 0, a) !=3D 0) > + __builtin_abort(); > + if (f1(1,1, 0, 0) !=3D 1) > + __builtin_abort(); > + > +#if __SIZEOF_INT__ =3D=3D __SIZEOF_FLOAT__ > + v4si b =3D {-1}; > + v4sf c =3D {a}; > + v4sf d =3D {0.0}; > + if (vf0(b,b, c, c)[0] !=3D 0) > + __builtin_abort(); > + if (vf0(b,b, c, d)[0] !=3D 0) > + __builtin_abort(); > + if (vf0(b,b, d, c)[0] !=3D 0) > + __builtin_abort(); > + if (vf0(b,b, d, d)[0] !=3D b[0]) > + __builtin_abort(); > +#endif > +} > -- > 2.31.1 >