From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x22d.google.com (mail-lj1-x22d.google.com [IPv6:2a00:1450:4864:20::22d]) by sourceware.org (Postfix) with ESMTPS id EDB303858D20 for ; Fri, 11 Aug 2023 09:50:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EDB303858D20 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-x22d.google.com with SMTP id 38308e7fff4ca-2b9bb097c1bso27565411fa.0 for ; Fri, 11 Aug 2023 02:50:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691747428; x=1692352228; 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=MnSHrJ0SKpXkv4IIm1XhPqNqXoBkDBaKAz41mye8W3o=; b=PGLSDtbDL5uiZMiN1GyvjT/0jUG3U6EPAruLQxxzvS7Qb4lEICbqMI1wcFeVVJCMA4 hXYskf5LoEHj5OwbuzevccMS5LEqTS6mUuuNsltr4OsIRkXXw5iJxMVDQuedkIx6Sm7Q 6VI3t2HndI8xqy8Ur/LbeElJX05mDY/crpMMPM891mpsd53k5M1EJRgJQYArDssLnjo+ 6jA3EU0KylIQqEoW/eU1Oio+2LNpigjvmBTEsMmHxpzJTHlvSwk/nlD5ray1hHtTHOHG UCT+OCsbR2RhITnyiiVatQAQkk2Jfva8e0tRGFJurfxsWnWKXtrjjKbbPkTdEFki5YJs rbLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691747428; x=1692352228; 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=MnSHrJ0SKpXkv4IIm1XhPqNqXoBkDBaKAz41mye8W3o=; b=hJUKxFg0pP1DURaul6wP8j1BzzgJ814Zluh00boeFTK0BCAR0TKsvSBJZnqCTkyMHX FMqdVpB1tk4e/SatTlnJYyTbSH+khjt0nZf2TqWzUw47h/0g492Nz1R5RDV/kG6RlYJa Kld1eO6UwEeVxAseM1vNbnYSXkj/5t73A0ecumERRu50ziw8++6CnRafKoVNTDOKSaLl fb8VPDH9YmYWZ1kAxrxBXdxQHEwv2YYZdr2fyOrV8Ps6Hcr6uxAA/L0KRcVfh6AuaZTf /rYFd60lIJwpqQf7r7WdAcvNTu0xlASOZ3aK6QFRYaYXv5HoueK6QOOFelrHs4XP3WQ9 wTlw== X-Gm-Message-State: AOJu0YwAcIDQg0u/hGtcSiQnDNDDO5vi7STkSDKU531seqwUXb5DF5i+ 81iWG05Qz7+eedcLokhU2aiwRX6Xb+9pU8dpok4= X-Google-Smtp-Source: AGHT+IF3Rc+K4af6ddylFuhK84zLG/SVVuX6LO9hd+tesRCKp+50Sgn3WenqD6BnGx/txq7yJ3QHYCvpWNnd9EIhe3s= X-Received: by 2002:a2e:a287:0:b0:2b6:e7ff:4b2e with SMTP id k7-20020a2ea287000000b002b6e7ff4b2emr1170555lja.33.1691747427306; Fri, 11 Aug 2023 02:50:27 -0700 (PDT) MIME-Version: 1.0 References: <20230811091551.2758227-1-apinski@marvell.com> In-Reply-To: <20230811091551.2758227-1-apinski@marvell.com> From: Richard Biener Date: Fri, 11 Aug 2023 11:50:14 +0200 Message-ID: Subject: Re: [PATCH 1/2] PHI-OPT [PR 110984]: Add support for NE_EXPR/EQ_EXPR with casts to spaceship_replacement 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=-6.1 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_10_SHORT_WORD_LINES,SCC_20_SHORT_WORD_LINES,SCC_5_SHORT_WORD_LINES,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 Fri, Aug 11, 2023 at 11:17=E2=80=AFAM Andrew Pinski via Gcc-patches wrote: > > So with my next VRP patch, VRP causes: > ``` > # c$_M_value_18 =3D PHI <-1(3), 0(2), 1(4)> > _11 =3D (unsigned int) c$_M_value_18; > _16 =3D _11 <=3D 1; > ``` > To be changed to: > ``` > # c$_M_value_18 =3D PHI <-1(3), 0(2), 1(4)> > _11 =3D (unsigned int) c$_M_value_18; > _16 =3D _11 !=3D 4294967295; > ``` > > So let's add support for the above. > A few changes was needed, first to change > the range check of the rhs of the comparison to possibly > integer_all_onesp also. > > The next is to add support for the cast and EQ/NE case. > > Note on the testcases pr110984-1.c is basically pr94589-2.c but > with what the C++ code is doing with the signed char type; > pr110984-2.c is pr110984-1.c with the cast added to give an > explicit testcase to test against. > > OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. LGTM. > Thanks, > Andrew Pinski > > PR tree-optimization/110984 > > gcc/ChangeLog: > > * tree-ssa-phiopt.cc (spaceship_replacement): Add support for > NE/EQ for the cast case. > > gcc/testsuite/ChangeLog: > > * gcc.dg/pr110984-1.c: New test. > * gcc.dg/pr110984-2.c: New test. > --- > gcc/testsuite/gcc.dg/pr110984-1.c | 37 +++++++++++++++++++++++++++++++ > gcc/testsuite/gcc.dg/pr110984-2.c | 21 ++++++++++++++++++ > gcc/tree-ssa-phiopt.cc | 19 +++++++++++++--- > 3 files changed, 74 insertions(+), 3 deletions(-) > create mode 100644 gcc/testsuite/gcc.dg/pr110984-1.c > create mode 100644 gcc/testsuite/gcc.dg/pr110984-2.c > > diff --git a/gcc/testsuite/gcc.dg/pr110984-1.c b/gcc/testsuite/gcc.dg/pr1= 10984-1.c > new file mode 100644 > index 00000000000..85b19eb8279 > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/pr110984-1.c > @@ -0,0 +1,37 @@ > +/* PR tree-optimization/110984 */ > +/* { dg-do compile } */ > +/* { dg-options "-O2 -g0 -ffast-math -fdump-tree-optimized" } */ > +/* { dg-final { scan-tree-dump-times "\[ij]_\[0-9]+\\(D\\) (?:<|<=3D|=3D= =3D|!=3D|>|>=3D) \[ij]_\[0-9]+\\(D\\)" 14 "optimized" } } */ > +/* { dg-final { scan-tree-dump-times "i_\[0-9]+\\(D\\) (?:<|<=3D|=3D=3D|= !=3D|>|>=3D) 5\\.0" 14 "optimized" } } */ > + > +/* This is similar to pr94589-2.c except use signed char as the type for= the [-1,2] case */ > + > +#define A __attribute__((noipa)) > +A int f1 (double i, double j) { signed char c; if (i =3D=3D j) c =3D 0; = else if (i < j) c =3D -1; else if (i > j) c =3D 1; else c =3D 2; return c = =3D=3D 0; } > +A int f2 (double i, double j) { signed char c; if (i =3D=3D j) c =3D 0; = else if (i < j) c =3D -1; else if (i > j) c =3D 1; else c =3D 2; return c != =3D 0; } > +A int f3 (double i, double j) { signed char c; if (i =3D=3D j) c =3D 0; = else if (i < j) c =3D -1; else if (i > j) c =3D 1; else c =3D 2; return c >= 0; } > +A int f4 (double i, double j) { signed char c; if (i =3D=3D j) c =3D 0; = else if (i < j) c =3D -1; else if (i > j) c =3D 1; else c =3D 2; return c <= 0; } > +A int f5 (double i, double j) { signed char c; if (i =3D=3D j) c =3D 0; = else if (i < j) c =3D -1; else if (i > j) c =3D 1; else c =3D 2; return c >= =3D 0; } > +A int f6 (double i, double j) { signed char c; if (i =3D=3D j) c =3D 0; = else if (i < j) c =3D -1; else if (i > j) c =3D 1; else c =3D 2; return c <= =3D 0; } > +A int f7 (double i, double j) { signed char c; if (i =3D=3D j) c =3D 0; = else if (i < j) c =3D -1; else if (i > j) c =3D 1; else c =3D 2; return c = =3D=3D -1; } > +A int f8 (double i, double j) { signed char c; if (i =3D=3D j) c =3D 0; = else if (i < j) c =3D -1; else if (i > j) c =3D 1; else c =3D 2; return c != =3D -1; } > +A int f9 (double i, double j) { signed char c; if (i =3D=3D j) c =3D 0; = else if (i < j) c =3D -1; else if (i > j) c =3D 1; else c =3D 2; return c >= -1; } > +A int f10 (double i, double j) { signed char c; if (i =3D=3D j) c =3D 0;= else if (i < j) c =3D -1; else if (i > j) c =3D 1; else c =3D 2; return c = <=3D -1; } > +A int f11 (double i, double j) { signed char c; if (i =3D=3D j) c =3D 0;= else if (i < j) c =3D -1; else if (i > j) c =3D 1; else c =3D 2; return c = =3D=3D 1; } > +A int f12 (double i, double j) { signed char c; if (i =3D=3D j) c =3D 0;= else if (i < j) c =3D -1; else if (i > j) c =3D 1; else c =3D 2; return c = !=3D 1; } > +A int f13 (double i, double j) { signed char c; if (i =3D=3D j) c =3D 0;= else if (i < j) c =3D -1; else if (i > j) c =3D 1; else c =3D 2; return c = < 1; } > +A int f14 (double i, double j) { signed char c; if (i =3D=3D j) c =3D 0;= else if (i < j) c =3D -1; else if (i > j) c =3D 1; else c =3D 2; return c = >=3D 1; } > +A int f15 (double i) { signed char c; if (i =3D=3D 5.0) c =3D 0; else if= (i < 5.0) c =3D -1; else if (i > 5.0) c =3D 1; else c =3D 2; return c =3D= =3D 0; } > +A int f16 (double i) { signed char c; if (i =3D=3D 5.0) c =3D 0; else if= (i < 5.0) c =3D -1; else if (i > 5.0) c =3D 1; else c =3D 2; return c !=3D= 0; } > +A int f17 (double i) { signed char c; if (i =3D=3D 5.0) c =3D 0; else if= (i < 5.0) c =3D -1; else if (i > 5.0) c =3D 1; else c =3D 2; return c > 0;= } > +A int f18 (double i) { signed char c; if (i =3D=3D 5.0) c =3D 0; else if= (i < 5.0) c =3D -1; else if (i > 5.0) c =3D 1; else c =3D 2; return c < 0;= } > +A int f19 (double i) { signed char c; if (i =3D=3D 5.0) c =3D 0; else if= (i < 5.0) c =3D -1; else if (i > 5.0) c =3D 1; else c =3D 2; return c >=3D= 0; } > +A int f20 (double i) { signed char c; if (i =3D=3D 5.0) c =3D 0; else if= (i < 5.0) c =3D -1; else if (i > 5.0) c =3D 1; else c =3D 2; return c <=3D= 0; } > +A int f21 (double i) { signed char c; if (i =3D=3D 5.0) c =3D 0; else if= (i < 5.0) c =3D -1; else if (i > 5.0) c =3D 1; else c =3D 2; return c =3D= =3D -1; } > +A int f22 (double i) { signed char c; if (i =3D=3D 5.0) c =3D 0; else if= (i < 5.0) c =3D -1; else if (i > 5.0) c =3D 1; else c =3D 2; return c !=3D= -1; } > +A int f23 (double i) { signed char c; if (i =3D=3D 5.0) c =3D 0; else if= (i < 5.0) c =3D -1; else if (i > 5.0) c =3D 1; else c =3D 2; return c > -1= ; } > +A int f24 (double i) { signed char c; if (i =3D=3D 5.0) c =3D 0; else if= (i < 5.0) c =3D -1; else if (i > 5.0) c =3D 1; else c =3D 2; return c <=3D= -1; } > +A int f25 (double i) { signed char c; if (i =3D=3D 5.0) c =3D 0; else if= (i < 5.0) c =3D -1; else if (i > 5.0) c =3D 1; else c =3D 2; return c =3D= =3D 1; } > +A int f26 (double i) { signed char c; if (i =3D=3D 5.0) c =3D 0; else if= (i < 5.0) c =3D -1; else if (i > 5.0) c =3D 1; else c =3D 2; return c !=3D= 1; } > +A int f27 (double i) { signed char c; if (i =3D=3D 5.0) c =3D 0; else if= (i < 5.0) c =3D -1; else if (i > 5.0) c =3D 1; else c =3D 2; return c < 1;= } > +A int f28 (double i) { signed char c; if (i =3D=3D 5.0) c =3D 0; else if= (i < 5.0) c =3D -1; else if (i > 5.0) c =3D 1; else c =3D 2; return c >=3D= 1; } > diff --git a/gcc/testsuite/gcc.dg/pr110984-2.c b/gcc/testsuite/gcc.dg/pr1= 10984-2.c > new file mode 100644 > index 00000000000..cddce045745 > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/pr110984-2.c > @@ -0,0 +1,21 @@ > +/* PR tree-optimization/110984 */ > +/* { dg-do compile } */ > +/* { dg-options "-O2 -g0 -ffast-math -fdump-tree-optimized" } */ > +/* { dg-final { scan-tree-dump-times "\[ij]_\[0-9]+\\(D\\) (?:<|<=3D|=3D= =3D|!=3D|>|>=3D) \[ij]_\[0-9]+\\(D\\)" 6 "optimized" } } */ > +/* { dg-final { scan-tree-dump-times "i_\[0-9]+\\(D\\) (?:<|<=3D|=3D=3D|= !=3D|>|>=3D) 5\\.0" 6 "optimized" } } */ > + > +/* This is similar to pr94589-2.c except use signed char and use unsigne= d types to check against the variable, which means removing the non !=3D/= =3D=3D comparisons. */ > + > +#define A __attribute__((noipa)) > +A int f1 (double i, double j) { signed char c; if (i =3D=3D j) c =3D 0; = else if (i < j) c =3D -1; else if (i > j) c =3D 1; else c =3D 2; unsigned t= =3D c; return t =3D=3D 0; } > +A int f2 (double i, double j) { signed char c; if (i =3D=3D j) c =3D 0; = else if (i < j) c =3D -1; else if (i > j) c =3D 1; else c =3D 2; unsigned t= =3D c; return t !=3D 0; } > +A int f7 (double i, double j) { signed char c; if (i =3D=3D j) c =3D 0; = else if (i < j) c =3D -1; else if (i > j) c =3D 1; else c =3D 2; unsigned t= =3D c; return t =3D=3D -1; } > +A int f8 (double i, double j) { signed char c; if (i =3D=3D j) c =3D 0; = else if (i < j) c =3D -1; else if (i > j) c =3D 1; else c =3D 2; unsigned t= =3D c; return t !=3D -1; } > +A int f11 (double i, double j) { signed char c; if (i =3D=3D j) c =3D 0;= else if (i < j) c =3D -1; else if (i > j) c =3D 1; else c =3D 2; unsigned = t =3D c; return t =3D=3D 1; } > +A int f12 (double i, double j) { signed char c; if (i =3D=3D j) c =3D 0;= else if (i < j) c =3D -1; else if (i > j) c =3D 1; else c =3D 2; unsigned = t =3D c; return t !=3D 1; } > +A int f15 (double i) { signed char c; if (i =3D=3D 5.0) c =3D 0; else if= (i < 5.0) c =3D -1; else if (i > 5.0) c =3D 1; else c =3D 2; unsigned t = =3D c; return t =3D=3D 0; } > +A int f16 (double i) { signed char c; if (i =3D=3D 5.0) c =3D 0; else if= (i < 5.0) c =3D -1; else if (i > 5.0) c =3D 1; else c =3D 2; unsigned t = =3D c; return t !=3D 0; } > +A int f21 (double i) { signed char c; if (i =3D=3D 5.0) c =3D 0; else if= (i < 5.0) c =3D -1; else if (i > 5.0) c =3D 1; else c =3D 2; unsigned t = =3D c; return t =3D=3D -1; } > +A int f22 (double i) { signed char c; if (i =3D=3D 5.0) c =3D 0; else if= (i < 5.0) c =3D -1; else if (i > 5.0) c =3D 1; else c =3D 2; unsigned t = =3D c; return t !=3D -1; } > +A int f25 (double i) { signed char c; if (i =3D=3D 5.0) c =3D 0; else if= (i < 5.0) c =3D -1; else if (i > 5.0) c =3D 1; else c =3D 2; unsigned t = =3D c; return t =3D=3D 1; } > +A int f26 (double i) { signed char c; if (i =3D=3D 5.0) c =3D 0; else if= (i < 5.0) c =3D -1; else if (i > 5.0) c =3D 1; else c =3D 2; unsigned t = =3D c; return t !=3D 1; } > diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc > index 485662dfcc7..5f24d62c49a 100644 > --- a/gcc/tree-ssa-phiopt.cc > +++ b/gcc/tree-ssa-phiopt.cc > @@ -2346,7 +2346,8 @@ spaceship_replacement (basic_block cond_bb, basic_b= lock middle_bb, > } > if (lhs !=3D (orig_use_lhs ? orig_use_lhs : phires) > || !tree_fits_shwi_p (rhs) > - || !IN_RANGE (tree_to_shwi (rhs), -1, 1)) > + || !(IN_RANGE (tree_to_shwi (rhs), 0, 1) > + || integer_all_onesp (rhs))) > return false; > > if (is_cast) > @@ -2356,9 +2357,20 @@ spaceship_replacement (basic_block cond_bb, basic_= block middle_bb, > /* As for -ffast-math we assume the 2 return to be > impossible, canonicalize (unsigned) res <=3D 1U or > (unsigned) res < 2U into res >=3D 0 and (unsigned) res > 1U > - or (unsigned) res >=3D 2U as res < 0. */ > + or (unsigned) res >=3D 2U as res < 0. > + Sometimes we get (unsigned)res !=3D N. Support those cases too.= */ > switch (cmp) > { > + case NE_EXPR: > + case EQ_EXPR: > + { > + tree newrhs =3D fold_convert (TREE_TYPE (phires), rhs); > + tree tmp =3D fold_convert (TREE_TYPE (rhs), newrhs); > + if (!tree_int_cst_equal (rhs, tmp)) > + return false; > + rhs =3D newrhs; > + break; > + } > case LE_EXPR: > if (!integer_onep (rhs)) > return false; > @@ -2382,7 +2394,8 @@ spaceship_replacement (basic_block cond_bb, basic_b= lock middle_bb, > default: > return false; > } > - rhs =3D build_zero_cst (TREE_TYPE (phires)); > + if (cmp !=3D EQ_EXPR && cmp !=3D NE_EXPR) > + rhs =3D build_zero_cst (TREE_TYPE (phires)); > } > else if (orig_use_lhs) > { > -- > 2.31.1 >