[PATCHv2] Add a couple of A?CST1:CST2 match and simplify optimizations

2021-05-23 Thread apinski--- via Gcc-patches
From: Andrew Pinski 

Instead of some of the more manual optimizations inside phi-opt,
it would be good idea to do a lot of the heavy lifting inside match
and simplify instead. In the process, this moves the three simple
A?CST1:CST2 (where CST1 or CST2 is zero) simplifications.

OK? Boostrapped and tested on x86_64-linux-gnu with no regressions.

Differences from V1:
* Use bit_xor 1 instead of bit_not to fix the problem with boolean types
which are not 1 bit precision.

Thanks,
Andrew Pinski

gcc:
* match.pd (A?CST1:CST2): Add simplifcations for A?0:+-1, A?+-1:0,
A?POW2:0 and A?0:POW2.
---
 gcc/match.pd | 41 +
 1 file changed, 41 insertions(+)

diff --git a/gcc/match.pd b/gcc/match.pd
index 1fc6b7b1557..ad6b057c56d 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -3711,6 +3711,47 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(if (integer_all_onesp (@1) && integer_zerop (@2))
 @0
 
+/* A few simplifications of "a ? CST1 : CST2". */
+/* NOTE: Only do this on gimple as the if-chain-to-switch
+   optimization depends on the gimple to have if statements in it. */
+#if GIMPLE
+(simplify
+ (cond @0 INTEGER_CST@1 INTEGER_CST@2)
+ (switch
+  (if (integer_zerop (@2))
+   (switch
+/* a ? 1 : 0 -> a if 0 and 1 are integral types. */
+(if (integer_onep (@1))
+ (convert (convert:boolean_type_node @0)))
+/* a ? -1 : 0 -> -a. */
+(if (integer_all_onesp (@1))
+ (negate (convert (convert:boolean_type_node @0
+/* a ? powerof2cst : 0 -> a << (log2(powerof2cst)) */
+(if (!POINTER_TYPE_P (type) && integer_pow2p (@1))
+ (with {
+   tree shift = build_int_cst (integer_type_node, tree_log2 (@1));
+  }
+  (lshift (convert (convert:boolean_type_node @0)) { shift; })
+  (if (integer_zerop (@1))
+   (with {
+  tree booltrue = constant_boolean_node (true, boolean_type_node);
+}
+(switch
+ /* a ? 0 : 1 -> !a. */
+ (if (integer_onep (@2))
+  (convert (bit_xor (convert:boolean_type_node @0) { booltrue; } )))
+ /* a ? -1 : 0 -> -(!a). */
+ (if (integer_all_onesp (@2))
+  (negate (convert (bit_xor (convert:boolean_type_node @0) { booltrue; } 

+ /* a ? powerof2cst : 0 -> (!a) << (log2(powerof2cst)) */
+ (if (!POINTER_TYPE_P (type) && integer_pow2p (@2))
+  (with {
+   tree shift = build_int_cst (integer_type_node, tree_log2 (@2));
+   }
+   (lshift (convert (bit_xor (convert:boolean_type_node @0) { booltrue; } 
))
+{ shift; }
+#endif
+
 /* Simplification moved from fold_cond_expr_with_comparison.  It may also
be extended.  */
 /* This pattern implements two kinds simplification:
-- 
2.17.1



Re: [Patch] OpenMP/Fortran: Handle polymorphic scalars in data-sharing FIRSTPRIVATE [PR86470]

2021-05-23 Thread Tobias Burnus

*PING*

(OpenMP patches: I note that the reduction + firstprivate→tofrom patch
is still being reviewed and that there are bunch of recently posted
patches by ChungLin + Julian which are also pending review.)
(There is also one patch (affinity + iterator) I still have to repost –
and will happen soon.)

Tobias

On 10.03.21 11:55, Tobias Burnus wrote:

Belated follow-up to the patch from August ...
https://gcc.gnu.org/pipermail/gcc-patches/2020-August/552588.html

This patch handles CLASS variables in the FIRSTPRIVATE data-sharing
clause, including freeing the memory at the end.

Technically this patch fixes a regression as the ICE is new –
before the code was just rejected. It is also rather contained.

OK for mainline?

Tobias

PS: The dtor can be extended rather simply to support arrays, for
the copy_ctor, some scalarization loop is needed.
Todo: 'private', which has to allocate the
dynamic type and copy the default initialization
for this the dynamic type.


-
Mentor Graphics (Deutschland) GmbH, Arnulfstrasse 201, 80634 München 
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Frank 
Thürauf


[PATCH] Optimize x < 0 ? ~y : y to (x >> 31) ^ y in match.pd

2021-05-23 Thread apinski--- via Gcc-patches
From: Andrew Pinski 

This copies the optimization that is done in phiopt for
"x < 0 ? ~y : y to (x >> 31) ^ y" into match.pd. The code
for phiopt is kept around until phiopt uses match.pd (which
I am working towards).

Note the original testcase is now optimized early on and I added a
new testcase to optimize during phiopt.

OK?  Bootstrapped and tested on x86_64-linux-gnu with no regressions.

Thanks,
Andrew Pinski

gcc:
* match.pd (x < 0 ? ~y : y): New patterns.

gcc/testsuite:
* gcc.dg/tree-ssa/pr96928.c: Update test for slightly different IR.
* gcc.dg/tree-ssa/pr96928-1.c: New testcase.
---
 gcc/match.pd  | 30 +++
 gcc/testsuite/gcc.dg/tree-ssa/pr96928-1.c | 48 +++
 gcc/testsuite/gcc.dg/tree-ssa/pr96928.c   |  7 +++--
 3 files changed, 83 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr96928-1.c

diff --git a/gcc/match.pd b/gcc/match.pd
index ad6b057..6710aa9 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -4875,6 +4875,36 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
   (cmp (bit_and@2 @0 integer_pow2p@1) @1)
   (icmp @2 { build_zero_cst (TREE_TYPE (@0)); })))
 
+(for cmp (ge lt)
+/* x < 0 ? ~y : y into (x >> (prec-1)) ^ y. */
+/* x >= 0 ? ~y : y into ~((x >> (prec-1)) ^ y). */
+ (simplify
+  (cond (cmp @0 integer_zerop) (bit_not @1) @1)
+   (if (INTEGRAL_TYPE_P (TREE_TYPE (@0))
+&& !TYPE_UNSIGNED (TREE_TYPE (@0))
+&& TYPE_PRECISION (TREE_TYPE (@0)) == TYPE_PRECISION (type))
+(with
+ {
+   tree shifter = build_int_cst (integer_type_node, TYPE_PRECISION (type) 
- 1);
+ }
+(if (cmp == LT_EXPR)
+ (bit_xor (convert (rshift @0 {shifter;})) @1)
+ (bit_not (bit_xor (convert (rshift @0 {shifter;})) @1))
+/* x < 0 ? y : ~y into ~((x >> (prec-1)) ^ y). */
+/* x >= 0 ? y : ~y into (x >> (prec-1)) ^ y. */
+ (simplify
+  (cond (cmp @0 integer_zerop) @1 (bit_not @1))
+   (if (INTEGRAL_TYPE_P (TREE_TYPE (@0))
+&& !TYPE_UNSIGNED (TREE_TYPE (@0))
+&& TYPE_PRECISION (TREE_TYPE (@0)) == TYPE_PRECISION (type))
+(with
+ {
+   tree shifter = build_int_cst (integer_type_node, TYPE_PRECISION (type) 
- 1);
+ }
+(if (cmp == GE_EXPR)
+ (bit_xor (convert (rshift @0 {shifter;})) @1)
+ (bit_not (bit_xor (convert (rshift @0 {shifter;})) @1)))
+
 /* If we have (A & C) != 0 ? D : 0 where C and D are powers of 2,
convert this into a shift followed by ANDing with D.  */
 (simplify
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr96928-1.c 
b/gcc/testsuite/gcc.dg/tree-ssa/pr96928-1.c
new file mode 100644
index 000..a2770e5
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr96928-1.c
@@ -0,0 +1,48 @@
+/* PR tree-optimization/96928 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-phiopt2" } */
+/* { dg-final { scan-tree-dump-times " = a_\[0-9]*\\\(D\\\) >> " 5 "phiopt2" } 
} */
+/* { dg-final { scan-tree-dump-times " = ~c_\[0-9]*\\\(D\\\);" 1 "phiopt2" } } 
*/
+/* { dg-final { scan-tree-dump-times " = ~" 1 "phiopt2" } } */
+/* { dg-final { scan-tree-dump-times " = \[abc_0-9\\\(\\\)D]* \\\^ " 5 
"phiopt2" } } */
+/* { dg-final { scan-tree-dump-not "a < 0" "phiopt2" } } */
+
+int
+foo (int a)
+{
+  if (a < 0)
+return ~a;
+  return a;
+}
+
+int
+bar (int a, int b)
+{
+  if (a < 0)
+return ~b;
+  return b;
+}
+
+unsigned
+baz (int a, unsigned int b)
+{
+  if (a < 0)
+return ~b;
+  return b;
+}
+
+unsigned
+qux (int a, unsigned int c)
+{
+  if (a >= 0)
+return ~c;
+  return c;
+}
+
+int
+corge (int a, int b)
+{
+  if (a >= 0)
+return b;
+  return ~b;
+}
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr96928.c 
b/gcc/testsuite/gcc.dg/tree-ssa/pr96928.c
index 2091357..e8fd82f 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/pr96928.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr96928.c
@@ -1,8 +1,11 @@
 /* PR tree-optimization/96928 */
 /* { dg-do compile } */
-/* { dg-options "-O2 -fdump-tree-phiopt2" } */
+/* { dg-options "-O2 -fdump-tree-phiopt2 -fdump-tree-optimized" } */
 /* { dg-final { scan-tree-dump-times " = a_\[0-9]*\\\(D\\\) >> " 5 "phiopt2" } 
} */
-/* { dg-final { scan-tree-dump-times " = ~c_\[0-9]*\\\(D\\\);" 1 "phiopt2" } } 
*/
+/* The following check is done at optimized because a ^ (~b) is rewritten as 
~(a^b)
+   and in the case of match.pd optimizing these ?:, the ~ is moved out already
+   by the time we get to phiopt2. */
+/* { dg-final { scan-tree-dump-times "\\\^ c_\[0-9]*\\\(D\\\);" 1 "optimized" 
} } */
 /* { dg-final { scan-tree-dump-times " = ~" 1 "phiopt2" } } */
 /* { dg-final { scan-tree-dump-times " = \[abc_0-9\\\(\\\)D]* \\\^ " 5 
"phiopt2" } } */
 /* { dg-final { scan-tree-dump-not "a < 0" "phiopt2" } } */
-- 
1.8.3.1



[Patch, committed] fortran/intrinsic.texi: Use proper variable name (Re: online doc corr.)

2021-05-23 Thread Tobias Burnus

Hi Johannes, hi all,

On 22.05.21 23:06, Johannes Nendwich via Gcc wrote:

https://gcc.gnu.org/onlinedocs/gcc-11.1.0/gfortran/ATOMIC_005fADD.html#ATOMIC_005fADD
"ATOMIC_ADD(ATOM, VALUE) atomically adds the value of VAR to the
variable ATOM."
--> "... adds the value of VALUE ..." ?


Indeed – and the same a bit later in ATOMIC_FETCH_ADD.

Now fixed on mainline (GCC 12, commit
r12-1002-g5d3ef9189a7c57679b5fb06e51c90479df0548b0, cf. attachment) and
on GCC 11 (commit r11-8458-g9ee61d2b51df012c659359873637cc2162ecccf3).

Thanks for the report!

Tobias

-
Mentor Graphics (Deutschland) GmbH, Arnulfstrasse 201, 80634 München 
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Frank 
Thürauf
commit 5d3ef9189a7c57679b5fb06e51c90479df0548b0
Author: Tobias Burnus 
Date:   Sun May 23 11:56:39 2021 +0200

fortran/intrinsic.texi: Use proper variable name

gcc/fortran/ChangeLog:

* intrinsic.texi (ATOMIC_ADD, ATOMIC_FETCH_ADD): Use the
proper variable name in the description.

diff --git a/gcc/fortran/intrinsic.texi b/gcc/fortran/intrinsic.texi
index a62508745fd..ad164137986 100644
--- a/gcc/fortran/intrinsic.texi
+++ b/gcc/fortran/intrinsic.texi
@@ -1870,7 +1870,7 @@ Inverse function: @gol
 
 @table @asis
 @item @emph{Description}:
-@code{ATOMIC_ADD(ATOM, VALUE)} atomically adds the value of @var{VAR} to the
+@code{ATOMIC_ADD(ATOM, VALUE)} atomically adds the value of @var{VALUE} to the
 variable @var{ATOM}. When @var{STAT} is present and the invocation was
 successful, it is assigned the value 0. If it is present and the invocation
 has failed, it is assigned a positive value; in particular, for a coindexed
@@ -2090,7 +2090,7 @@ end program atomic
 @table @asis
 @item @emph{Description}:
 @code{ATOMIC_FETCH_ADD(ATOM, VALUE, OLD)} atomically stores the value of
-@var{ATOM} in @var{OLD} and adds the value of @var{VAR} to the
+@var{ATOM} in @var{OLD} and adds the value of @var{VALUE} to the
 variable @var{ATOM}. When @var{STAT} is present and the invocation was
 successful, it is assigned the value 0. If it is present and the invocation
 has failed, it is assigned a positive value; in particular, for a coindexed


Re: [OG11] Merge GCC 11 into branch, cherry picks from mainline

2021-05-23 Thread Tobias Burnus

On 17.05.21 12:33, Tobias Burnus wrote:

On 14.05.21 10:51, Tobias Burnus wrote:

OG11 = devel/omp/gcc-11, a branch with some OpenMP/OpenACC/offload
patches
which are not yet on mainline. Additionally, patches in this area are
cherry-picked from mainline

Changes since last email (cherry pick, merge, post-cherry-pick fix):


(last three now pushed, the others are older)

4d83e2f9d03 Merge branch 'releases/gcc-11' into devel/omp/gcc-11
040aef637b3 openmp: Fix up firstprivate+lastprivate clause handling [PR99928]
dc9d8ebcdcd openmp: Fix up handling of implicit lastprivate on outer constructs 
for implicit linear and lastprivate IVs [PR99928]
a41b3c2af85 Fortran/OpenMP: Add support for 'close' in map clause
41a85e38f14 Merge branch 'releases/gcc-11' into devel/omp/gcc-11
d20715d6eb2 openmp: Handle explicit linear clause properly in combined 
constructs with target [PR99928]
ae40ab0183c openmp: Handle lastprivate on combined target correctly [PR99928]
44f0b0dafeb Merge branch 'releases/gcc-11' into devel/omp/gcc-11
948eb2b2328 Fortran/OpenMP: Add missing EXEC_OMP_DEPOBJ case val [PR100642]
23d1d325422 Merge branch 'releases/gcc-11' into devel/omp/gcc-11

Tobias
-
Mentor Graphics (Deutschland) GmbH, Arnulfstrasse 201, 80634 München 
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Frank 
Thürauf


Re: [Ping^2, Patch, Fortran] PR98301 Re: RANDOM_INIT() and coarray Fortran

2021-05-23 Thread Andre Vehreschild via Gcc-patches
Hi Martin,

thanks for pointing that out. I haven't committed for quite some time now and
could not find on the webpage how this works nowadays. I was thinking that the
special gcc-git-command should have added the Changelog entries automagically
and immediately. That they are added by a daily bump is new to me. Thanks for
giving me more insight.

So do I need to revert the commit c4771b3438a8cd9afcef1762957b763f8df3fa6e to
fix the Changelogs or how do we proceed from here? 

Is there a webpage which describes the current state-of-art of committing to
gcc for folks that do not follow every discussion on the mailing lists?

Thanks for your help,
Andre
On Sat, 22 May 2021 19:58:57 +0200
Martin Liška  wrote:

> On 5/22/21 1:39 PM, Andre Vehreschild via Gcc-patches wrote:
> > Hi Steve and Jerry,
> > 
> > thanks for the ok'ing.
> > 
> > Committed as https://gcc.gnu.org/g:26ca6dbda23bc6dfab96ce07afa70ebacedfaf9c
> > and https://gcc.gnu.org/g:c4771b3438a8cd9afcef1762957b763f8df3fa6e (for the
> > missing changelog entries).  
> 
> Hello.
> 
> About the missing changelog entries. The will be added automatically by Daily
> bump. You can check it with:
> ./contrib/gcc-changelog/git_check_commit.py
> 26ca6dbda23bc6dfab96ce07afa70ebacedfaf9c -p
> 
> What's missing for you so that you pushed
> c4771b3438a8cd9afcef1762957b763f8df3fa6e?
> 
> Thanks,
> Martin
> 
> > 
> > - Andre
> > 
> > On Fri, 21 May 2021 19:38:00 -0700
> > Jerry D  wrote:
> >   
> >> yes, please commit
> >>
> >> On 5/21/21 8:08 AM, Steve Kargl via Fortran wrote:  
> >>> On Fri, May 21, 2021 at 10:09:02AM +0200, Andre Vehreschild wrote:  
>  Ping, ping!
> 
>  Please find attached a rebased version of the patch for the RANDOM_INIT
>  issue with coarray Fortran. Nothing changed to the previous version, just
>  rebased to current master.
> 
>  Regtested fine on x86_64-linux/f33. Ok for trunk?
>   
> >>> I think you've down your due diligence with 2 pings.
> >>> I would commit.
> >>>  
> >>  
> > 
> > 
> > --
> > Andre Vehreschild * Email: vehre ad gmx dot de
> >   
> 


-- 
Andre Vehreschild * Email: vehre ad gmx dot de 


Re: [Ping^2, Patch, Fortran] PR98301 Re: RANDOM_INIT() and coarray Fortran

2021-05-23 Thread Martin Liška

On 5/23/21 1:59 PM, Andre Vehreschild wrote:

Hi Martin,

thanks for pointing that out. I haven't committed for quite some time now and
could not find on the webpage how this works nowadays. I was thinking that the
special gcc-git-command should have added the Changelog entries automagically
and immediately. That they are added by a daily bump is new to me. Thanks for
giving me more insight.


Sure, I'm fully aware that occasional committers are not aware of that.



So do I need to revert the commit c4771b3438a8cd9afcef1762957b763f8df3fa6e to
fix the Changelogs or how do we proceed from here?


I've just done that.


Is there a webpage which describes the current state-of-art of committing to
gcc for folks that do not follow every discussion on the mailing lists?


It's documented here:
https://gcc.gnu.org/codingconventions.html#ChangeLogs

But it's far from a good location. I'm going to improve it.

Cheers,
Martin



Thanks for your help,
Andre
On Sat, 22 May 2021 19:58:57 +0200
Martin Liška  wrote:


On 5/22/21 1:39 PM, Andre Vehreschild via Gcc-patches wrote:

Hi Steve and Jerry,

thanks for the ok'ing.

Committed as https://gcc.gnu.org/g:26ca6dbda23bc6dfab96ce07afa70ebacedfaf9c
and https://gcc.gnu.org/g:c4771b3438a8cd9afcef1762957b763f8df3fa6e (for the
missing changelog entries).


Hello.

About the missing changelog entries. The will be added automatically by Daily
bump. You can check it with:
./contrib/gcc-changelog/git_check_commit.py
26ca6dbda23bc6dfab96ce07afa70ebacedfaf9c -p

What's missing for you so that you pushed
c4771b3438a8cd9afcef1762957b763f8df3fa6e?

Thanks,
Martin



- Andre

On Fri, 21 May 2021 19:38:00 -0700
Jerry D  wrote:
   

yes, please commit

On 5/21/21 8:08 AM, Steve Kargl via Fortran wrote:

On Fri, May 21, 2021 at 10:09:02AM +0200, Andre Vehreschild wrote:

Ping, ping!

Please find attached a rebased version of the patch for the RANDOM_INIT
issue with coarray Fortran. Nothing changed to the previous version, just
rebased to current master.

Regtested fine on x86_64-linux/f33. Ok for trunk?
  

I think you've down your due diligence with 2 pings.
I would commit.
  
  



--
Andre Vehreschild * Email: vehre ad gmx dot de
   









Re: [PATCH] Optimize x < 0 ? ~y : y to (x >> 31) ^ y in match.pd

2021-05-23 Thread Martin Liška

Hello.

Similarly to:
https://gcc.gnu.org/pipermail/gcc-patches/2021-May/571039.html

I've just reverted the ChangeLog commit change. I'm planning update
of the documentation.

Cheers,
Martin


[wwwdocs, committed] htdocs/gitwrite.html: Remove link to nonexisting '#example'

2021-05-23 Thread Tobias Burnus

I did not check svnwrite.html, but since gitwrite.html came into existence,
no example existed ...

Committed as attached.

Tobias

-
Mentor Graphics (Deutschland) GmbH, Arnulfstrasse 201, 80634 München 
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Frank 
Thürauf
commit 512805afa4a8f5db215a483b84347bbe7971da8a
Author: Tobias Burnus 
Date:   Sun May 23 14:23:39 2021 +0200

htdocs/gitwrite.html: Remove link to nonexisting '#example'

* htdocs/gitwrite.html (Contents): Remove link to '#example'
which does not exist.

diff --git a/htdocs/gitwrite.html b/htdocs/gitwrite.html
index 5332e2f5..8363e70c 100644
--- a/htdocs/gitwrite.html
+++ b/htdocs/gitwrite.html
@@ -23,7 +23,6 @@ maintainers and significant developers.
   Write access policies
   Testing changes
   Checking in a change
-  Example check-in session
   Creating and using branches
   Personal and Vendor branches
   Tips&Tricks around your account


[wwwdocs, patch] htdocs/gitwrite.html: Clarify ChangeLog generation

2021-05-23 Thread Tobias Burnus

As there was some confusion regarding when the ChangeLog is generated,
I propose the attached wwwdocs patch. Comments?

(Side remark: The cron-script commit by gccadmin@ is labelled "Daily bump."
and updates gcc/DATESTAMP besides the ChangeLog files.)

Tobias

-
Mentor Graphics (Deutschland) GmbH, Arnulfstrasse 201, 80634 München 
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Frank 
Thürauf
htdocs/gitwrite.html: Clarify ChangeLog generation
diff --git a/htdocs/gitwrite.html b/htdocs/gitwrite.html
index 8363e70c..66ad215f 100644
--- a/htdocs/gitwrite.html
+++ b/htdocs/gitwrite.html
@@ -233,9 +233,9 @@ pull" before attempting a checkin; this will save you a little
 time if someone else has modified the source tree since the last time
 you synced your sources.
 
-Apply the patch to your local tree.  ChangeLog entries will be
-automatically added to the corresponding ChangeLog files based
-on the git commit message.  See the documentation of
+Apply the patch to your local tree.  On the release branches, ChangeLog
+entries will be automatically added to the corresponding ChangeLog files based
+on the git commit message by the daily-bump commit.  See the documentation of
 ChangeLog format.
 
 Make sure to rebuild any generated files affected by


Re: [PATCH] Optimize x < 0 ? ~y : y to (x >> 31) ^ y in match.pd

2021-05-23 Thread Marc Glisse

On Sun, 23 May 2021, apinski--- via Gcc-patches wrote:


+(for cmp (ge lt)
+/* x < 0 ? ~y : y into (x >> (prec-1)) ^ y. */
+/* x >= 0 ? ~y : y into ~((x >> (prec-1)) ^ y). */
+ (simplify
+  (cond (cmp @0 integer_zerop) (bit_not @1) @1)
+   (if (INTEGRAL_TYPE_P (TREE_TYPE (@0))
+&& !TYPE_UNSIGNED (TREE_TYPE (@0))
+&& TYPE_PRECISION (TREE_TYPE (@0)) == TYPE_PRECISION (type))


Is there a risk that x is signed char (precision 8) and y is a vector with 
8 elements?


--
Marc Glisse


Re: [wwwdocs, committed] htdocs/gitwrite.html: Remove link to nonexisting '#example'

2021-05-23 Thread Gerald Pfeifer
On Sun, 23 May 2021, Tobias Burnus wrote:
> I did not check svnwrite.html, but since gitwrite.html came into 
> existence, no example existed ...
> 
> Committed as attached.

Thanks.  

I had a look at the instructions, and they seem to be sufficient,
even for folks not intimately familiar with git.

Gerald


Re: [GOVERNANCE] Where to file complaints re project-maintainers?

2021-05-23 Thread Mike Stump via Gcc-patches
This isn't a patch to gcc, please stop posting non-technical content to this 
list.  Please review what this list is for and the rules for this list before 
you post again, thanks.

> On May 14, 2021, at 7:47 AM, abebeos via Gcc-patches 
>  wrote:
> 
> Hi there IT-fascists, clowns, master-clowns,
> totally-confused-incompetent-code-plumbers,
> activity-trapped-silent-high-performers,
> stay-out-of-trouble-silent-high-performers! (Guess where G.J. Lay fits in
> the collection...).
> 
> Please be aware that I do not read any messages here (including the one I'm
> replying to), in this unregulated circus-show ("The GCC Project"). I've
> polluted my mind enough with your nonsense justifications, to be honest it
> is becoming quite disgusting.
> 
> If any serious person from the FSF (as to my tiny research, the FSF is in
> the end legally and ethically responsible for what happens on GCC) want to
> comment on this, please send me additionally a copy of your message.
> 
> FSF:
> 
> Copyright: https://www.fsf.org/about/dmca-notice
> Privacy: https://www.fsf.org/about/free-software-foundation-privacy-policy
> IT-fascists, Bullying, discrimination, workers-abuse, rigged voting
> processes: ???


Re: [PATCH] Optimize x < 0 ? ~y : y to (x >> 31) ^ y in match.pd

2021-05-23 Thread Andrew Pinski via Gcc-patches
On Sun, May 23, 2021 at 6:14 AM Marc Glisse  wrote:
>
> On Sun, 23 May 2021, apinski--- via Gcc-patches wrote:
>
> > +(for cmp (ge lt)
> > +/* x < 0 ? ~y : y into (x >> (prec-1)) ^ y. */
> > +/* x >= 0 ? ~y : y into ~((x >> (prec-1)) ^ y). */
> > + (simplify
> > +  (cond (cmp @0 integer_zerop) (bit_not @1) @1)
> > +   (if (INTEGRAL_TYPE_P (TREE_TYPE (@0))
> > +&& !TYPE_UNSIGNED (TREE_TYPE (@0))
> > +&& TYPE_PRECISION (TREE_TYPE (@0)) == TYPE_PRECISION (type))
>
> Is there a risk that x is signed char (precision 8) and y is a vector with
> 8 elements?

Yes there should be a check for "INTEGRAL_TYPE_P (type)" there too.  I
had missed it when I was doing the conversion.  I will add it and
resubmit the patch.

Thanks,
Andrew

>
> --
> Marc Glisse


Re: [PATCH] Optimize x < 0 ? ~y : y to (x >> 31) ^ y in match.pd

2021-05-23 Thread Andrew Pinski via Gcc-patches
On Sun, May 23, 2021 at 5:49 AM Martin Liška  wrote:
>
> Hello.
>
> Similarly to:
> https://gcc.gnu.org/pipermail/gcc-patches/2021-May/571039.html
>
> I've just reverted the ChangeLog commit change. I'm planning update
> of the documentation.

Obviously is for the other patch which I pushed and not for this one.
I was trying to figure out why I could not push my changes with the
changelog included, the error message was not so obvious either.

Thanks,
Andrew

>
> Cheers,
> Martin


Re: Add '__OPTIMIZE__' DejaGnu selector

2021-05-23 Thread Mike Stump via Gcc-patches
On May 18, 2021, at 9:02 AM, Thomas Schwinge  wrote:
> Is the attached "Add '__OPTIMIZE__' DejaGnu selector" OK to push after
> testing?

Ok.


Re: [PATCH] PR fortran/100551 - [11/12 Regression] Passing return value to class(*) dummy argument

2021-05-23 Thread Paul Richard Thomas via Gcc-patches
Hi Harald,

I meant to deal with this myself since I am the guilty party. However, the
last two weeks have been taken up by a house move and so gfortran has been
on the backburner.

The patch looks good and seems to do the job - OK for master and 11-branch.

Thanks a million for dealing with it!

Paul

PS If I walk 200m I can now see the "dreaming spires" of Oxford! Better
still, there are no fewer than three very good pub/restaurants within
walking distance :-)


On Thu, 20 May 2021 at 23:22, Harald Anlauf via Fortran 
wrote:

> The fix for PR93924/5 has caused a regression for code such as given
> in the present PR.  This can be remedied by adjusting the check when
> to invoke the implicit conversion of actual argument to an unlimited
> polymorphic procedure argument.
>
> Regtested on x86_64-pc-linux-gnu.
>
> OK for mainline and backport to 11-branch?
>
> Thanks,
> Harald
>
>
> Fortran: fix passing return value to class(*) dummy argument
>
> gcc/fortran/ChangeLog:
>
> PR fortran/100551
> * trans-expr.c (gfc_conv_procedure_call): Adjust check for
> implicit conversion of actual argument to an unlimited polymorphic
> procedure argument.
>
> gcc/testsuite/ChangeLog:
>
> PR fortran/100551
> * gfortran.dg/pr100551.f90: New test.
>
>

-- 
"If you can't explain it simply, you don't understand it well enough" -
Albert Einstein


[PATCH] i386: Add push insns for 4-byte vectors [PR100722]

2021-05-23 Thread Uros Bizjak via Gcc-patches
2021-05-23  Uroš Bizjak  

gcc/
PR target/100722
* config/i386/mmx.md (*push2_rex64):
New instruction pattern.
(*push2): Ditto.
(push splitter for SSE registers): New splitter.

gcc/testsuite/

PR target/100722
* gcc.target/i386/pr100722.c: New test.

Bootstrapped and regression tested on x86_64-linux-gnu {,-m32}.

Pushed to master.

Uros.
diff --git a/gcc/config/i386/mmx.md b/gcc/config/i386/mmx.md
index 4c42e6d93dc..453e8ea406d 100644
--- a/gcc/config/i386/mmx.md
+++ b/gcc/config/i386/mmx.md
@@ -302,6 +302,39 @@ (define_insn "*mov_internal"
   ]
   (symbol_ref "true")))])
 
+;; For TARGET_64BIT we always round up to 8 bytes.
+(define_insn "*push2_rex64"
+  [(set (match_operand:VI_32 0 "push_operand" "=X,X")
+   (match_operand:VI_32 1 "nonmemory_no_elim_operand" "rC,*v"))]
+  "TARGET_SSE2 && TARGET_64BIT"
+  "@
+   push{q}\t%q1
+   #"
+  [(set_attr "type" "push,multi")
+   (set_attr "mode" "DI")])
+
+(define_insn "*push2"
+  [(set (match_operand:VI_32 0 "push_operand" "=<,<")
+   (match_operand:VI_32 1 "general_no_elim_operand" "rC*m,*v"))]
+  "TARGET_SSE2 && !TARGET_64BIT"
+  "@
+   push{l}\t%1
+   #"
+  [(set_attr "type" "push,multi")
+   (set_attr "mode" "SI")])
+
+(define_split
+  [(set (match_operand:VI_32 0 "push_operand")
+   (match_operand:VI_32 1 "sse_reg_operand"))]
+  "TARGET_SSE2 && reload_completed"
+  [(set (reg:P SP_REG) (plus:P (reg:P SP_REG) (match_dup 2)))
+(set (match_dup 0) (match_dup 1))]
+{
+  operands[2] = GEN_INT (-PUSH_ROUNDING (GET_MODE_SIZE (mode)));
+  /* Preserve memory attributes. */
+  operands[0] = replace_equiv_address (operands[0], stack_pointer_rtx);
+})
+
 (define_expand "movmisalign"
   [(set (match_operand:VI_32 0 "nonimmediate_operand")
(match_operand:VI_32 1 "nonimmediate_operand"))]
diff --git a/gcc/testsuite/gcc.target/i386/pr100722.c 
b/gcc/testsuite/gcc.target/i386/pr100722.c
new file mode 100644
index 000..f784039f275
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr100722.c
@@ -0,0 +1,17 @@
+/* PR target/100722 */
+/* { dg-do compile } */
+/* { dg-options "-O -msse2" } */
+
+typedef char int8x4_t __attribute__((vector_size(4)));
+
+void stack_callee (int8x4_t, int8x4_t, int8x4_t, int8x4_t,
+  int8x4_t, int8x4_t, int8x4_t);
+
+int8x4_t stack_caller_x1;
+
+void stack_caller (void)
+{
+  stack_callee (stack_caller_x1, stack_caller_x1, stack_caller_x1,
+   stack_caller_x1, stack_caller_x1, stack_caller_x1,
+   stack_caller_x1);
+}


Re: [PATCH 06/57] rs6000: Add helper functions for parsing

2021-05-23 Thread Bernhard Reutner-Fischer via Gcc-patches
On 21 May 2021 22:56:09 CEST, Bill Schmidt via Gcc-patches 
 wrote:

>>> +  if (lastpos < pos)
>>> +return 0;
>>> +
>>> +  char *buf = (char *) malloc (lastpos - pos + 2);
>>> +  memcpy (buf, &linebuf[pos], lastpos - pos + 1);
>>> +  buf[lastpos - pos + 1] = '\0';
>>> +
>>> +  pos = lastpos + 1;
>>> +  return buf;
>>> +}
>> Are there no utility routines you can use?  It would be useful to
>have
>> something that all gen* can use (something less bare than what there
>is
>> now...)
>
>I didn't find anything great as I was poking around, hence I wrote my 
>own low level utilities.  It goes back to my desire to track line/pos 
>information for debug.
>
>Thanks for the review!

You saw the unchecked usage of the malloc return value, did you?

We certainly warn about that, I'd hope.
thanks,


[PATCH] config: Backport "Rely less on internal symbols" (serial 68) to gettext.m4

2021-05-23 Thread Michael Forney
GNU gettext introduced this change[0] in version 0.19.8 to fix
gettext detection with musl libc, since it does not define these
internal symbols.

This allows gcc to build with musl gettext rather than falling back
to the bundled version.

[0] https://git.savannah.gnu.org/gitweb/?p=gettext.git;a=commit;h=b67399b4

2021-05-23  Michael Forney  

config/ChangeLog:

* gettext.m4 (AM_GNU_GETTEXT): Skip checks for the internal
symbols _nl_msg_cat_cntr, _nl_domain_bindings, and
_nl_expand_alias, if __GNU_GETTEXT_SUPPORTED_REVISION is defined.
Backport of gettext serial 68 patch.

intl/ChangeLog:

* configure: Regenerate.
---
 config/gettext.m4 | 52 +++
 1 file changed, 35 insertions(+), 17 deletions(-)

diff --git a/config/gettext.m4 b/config/gettext.m4
index 45fa6b4ab76..5b42bb16523 100644
--- a/config/gettext.m4
+++ b/config/gettext.m4
@@ -128,6 +128,13 @@ AC_DEFUN([AM_GNU_GETTEXT],
 
 AC_CACHE_CHECK([for GNU gettext in libc], gt_cv_func_gnugettext_libc,
  [AC_TRY_LINK([#include 
+#ifndef __GNU_GETTEXT_SUPPORTED_REVISION
+extern int _nl_msg_cat_cntr;
+extern int *_nl_domain_bindings;
+#define __GNU_GETTEXT_SYMBOL_EXPRESSION (_nl_msg_cat_cntr + 
*_nl_domain_bindings)
+#else
+#define __GNU_GETTEXT_SYMBOL_EXPRESSION 0
+#endif
 ]ifelse([$2], [need-formatstring-macros],
 [#ifndef __GNU_GETTEXT_SUPPORTED_REVISION
 #define __GNU_GETTEXT_SUPPORTED_REVISION(major) ((major) == 0 ? 0 : -1)
@@ -135,10 +142,9 @@ AC_DEFUN([AM_GNU_GETTEXT],
 changequote(,)dnl
 typedef int array [2 * (__GNU_GETTEXT_SUPPORTED_REVISION(0) >= 1) - 1];
 changequote([,])dnl
-], [])[extern int _nl_msg_cat_cntr;
-extern int *_nl_domain_bindings;],
+], []),
 [bindtextdomain ("", "");
-return (int) gettext ("")]ifelse([$2], [need-ngettext], [ + (int) ngettext 
("", "", 0)], [])[ + _nl_msg_cat_cntr + *_nl_domain_bindings],
+return (int) gettext ("")]ifelse([$2], [need-ngettext], [ + (int) ngettext 
("", "", 0)], [])[ + __GNU_GETTEXT_SYMBOL_EXPRESSION],
 gt_cv_func_gnugettext_libc=yes,
 gt_cv_func_gnugettext_libc=no)])
 
@@ -160,6 +166,17 @@ return (int) gettext ("")]ifelse([$2], [need-ngettext], [ 
+ (int) ngettext ("",
 LIBS="$LIBS $LIBINTL"
 dnl Now see whether libintl exists and does not depend on libiconv.
 AC_TRY_LINK([#include 
+#ifndef __GNU_GETTEXT_SUPPORTED_REVISION
+extern int _nl_msg_cat_cntr;
+extern
+#ifdef __cplusplus
+"C"
+#endif
+const char *_nl_expand_alias ();
+#define __GNU_GETTEXT_SYMBOL_EXPRESSION (_nl_msg_cat_cntr + *_nl_expand_alias 
(0))
+#else
+#define __GNU_GETTEXT_SYMBOL_EXPRESSION 0
+#endif
 ]ifelse([$2], [need-formatstring-macros],
 [#ifndef __GNU_GETTEXT_SUPPORTED_REVISION
 #define __GNU_GETTEXT_SUPPORTED_REVISION(major) ((major) == 0 ? 0 : -1)
@@ -167,20 +184,26 @@ return (int) gettext ("")]ifelse([$2], [need-ngettext], [ 
+ (int) ngettext ("",
 changequote(,)dnl
 typedef int array [2 * (__GNU_GETTEXT_SUPPORTED_REVISION(0) >= 1) - 1];
 changequote([,])dnl
-], [])[extern int _nl_msg_cat_cntr;
-extern
-#ifdef __cplusplus
-"C"
-#endif
-const char *_nl_expand_alias ();],
+], []),
   [bindtextdomain ("", "");
-return (int) gettext ("")]ifelse([$2], [need-ngettext], [ + (int) ngettext 
("", "", 0)], [])[ + _nl_msg_cat_cntr + *_nl_expand_alias (0)],
+return (int) gettext ("")]ifelse([$2], [need-ngettext], [ + (int) ngettext 
("", "", 0)], [])[ + __GNU_GETTEXT_SYMBOL_EXPRESSION],
   gt_cv_func_gnugettext_libintl=yes,
   gt_cv_func_gnugettext_libintl=no)
 dnl Now see whether libintl exists and depends on libiconv.
 if test "$gt_cv_func_gnugettext_libintl" != yes && test -n 
"$LIBICONV"; then
   LIBS="$LIBS $LIBICONV"
   AC_TRY_LINK([#include 
+#ifndef __GNU_GETTEXT_SUPPORTED_REVISION
+extern int _nl_msg_cat_cntr;
+extern
+#ifdef __cplusplus
+"C"
+#endif
+const char *_nl_expand_alias ();
+#define __GNU_GETTEXT_SYMBOL_EXPRESSION (_nl_msg_cat_cntr + *_nl_expand_alias 
(0))
+#else
+#define __GNU_GETTEXT_SYMBOL_EXPRESSION 0
+#endif
 ]ifelse([$2], [need-formatstring-macros],
 [#ifndef __GNU_GETTEXT_SUPPORTED_REVISION
 #define __GNU_GETTEXT_SUPPORTED_REVISION(major) ((major) == 0 ? 0 : -1)
@@ -188,14 +211,9 @@ return (int) gettext ("")]ifelse([$2], [need-ngettext], [ 
+ (int) ngettext ("",
 changequote(,)dnl
 typedef int array [2 * (__GNU_GETTEXT_SUPPORTED_REVISION(0) >= 1) - 1];
 changequote([,])dnl
-], [])[extern int _nl_msg_cat_cntr;
-extern
-#ifdef __cplusplus
-"C"
-#endif
-const char *_nl_expand_alias ();],
+], []),
 [bindtextdomain ("", "");
-return (int) gettext ("")]ifelse([$2], [need-ngettext], [ + (int) ngettext 
("", "", 0)], [])[ + _nl_msg_cat_cntr + *_nl_expand_alias (0)],
+return (int) gettext ("")]ifelse([$2], [need-ngettext], [ + (int) ngettext 
("", "", 0)], [])[ + __GNU_GETTEXT_SYMBOL_EXPRESSION],
[LIBINTL="$LIBINTL $LIBICONV"
   

[PATCH] Fix two testcases for ssa names which are more than 1 digit

2021-05-23 Thread apinski--- via Gcc-patches
From: Andrew Pinski 

phi-opt-10.c and phi-opt-7.c both depend on currently that some ssa name
versions are one digit long which is not always correct. This fixes the
problem by detecting digits rather than just using '.'.

Committed as obvious after a bootstrap/test.

Thanks,
Andrew Pinski

gcc/testsuite/ChangeLog
* gcc.dg/tree-ssa/phi-opt-10.c: Use "\[0-9\]*" instead of '.'
when matching ssa name version.
* gcc.dg/tree-ssa/phi-opt-7.c: Likewise.
---
 gcc/testsuite/gcc.dg/tree-ssa/phi-opt-10.c | 2 +-
 gcc/testsuite/gcc.dg/tree-ssa/phi-opt-7.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-10.c 
b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-10.c
index 4c190e6af7d..3681fa78836 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-10.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-10.c
@@ -7,4 +7,4 @@ int eqm1_phi (unsigned long a) { return a ? 0 : -1; }
 int spaceship1 (long a) { return a > 0 ? 1 : a < 0 ? -1 : 0; }
 int spaceship2 (long a) { return a > 0 ? 1 : a == 0 ? 0 : -1; }
 
-/* { dg-final { scan-tree-dump-times " = -\[^\r\n\]*_.;" 4 "optimized"} } */
+/* { dg-final { scan-tree-dump-times " = -\[^\r\n\]*_\[0-9\]*;" 4 "optimized"} 
} */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-7.c 
b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-7.c
index 18ecbd52aa2..51e1f6dfa75 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-7.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-7.c
@@ -18,5 +18,5 @@ int f(int t, int c)
 /* There should be one ifs as one of them should be changed into
a conditional and the other should be there still.  */
 /* { dg-final { scan-tree-dump-times "if" 1 "optimized" }  }*/
-/* { dg-final { scan-tree-dump-times "\[^\r\n\]*_. = c_\[0-9\]*.D. != 0" 1 
"optimized"  } } */
+/* { dg-final { scan-tree-dump-times "\[^\r\n\]*_\[0-9\]* = c_\[0-9\]*.D. != 
0" 1 "optimized"  } } */
 
-- 
2.17.1



[PATCHv2] Optimize x < 0 ? ~y : y to (x >> 31) ^ y in match.pd

2021-05-23 Thread apinski--- via Gcc-patches
From: Andrew Pinski 

This copies the optimization that is done in phiopt for
"x < 0 ? ~y : y to (x >> 31) ^ y" into match.pd. The code
for phiopt is kept around until phiopt uses match.pd (which
I am working towards).

Note the original testcase is now optimized early on and I added a
new testcase to optimize during phiopt.

OK?  Bootstrapped and tested on x86_64-linux-gnu with no regressions.

Thanks,
Andrew Pinski

Differences from v1:
V2: Add check for integeral type to make sure vector types are not done.

gcc:
* match.pd (x < 0 ? ~y : y): New patterns.

gcc/testsuite:
* gcc.dg/tree-ssa/pr96928.c: Update test for slightly different IR.
* gcc.dg/tree-ssa/pr96928-1.c: New testcase.
---
 gcc/match.pd  | 32 +++
 gcc/testsuite/gcc.dg/tree-ssa/pr96928-1.c | 48 +++
 gcc/testsuite/gcc.dg/tree-ssa/pr96928.c   |  7 +++-
 3 files changed, 85 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr96928-1.c

diff --git a/gcc/match.pd b/gcc/match.pd
index ad6b057c56d..dd730814942 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -4875,6 +4875,38 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
   (cmp (bit_and@2 @0 integer_pow2p@1) @1)
   (icmp @2 { build_zero_cst (TREE_TYPE (@0)); })))
 
+(for cmp (ge lt)
+/* x < 0 ? ~y : y into (x >> (prec-1)) ^ y. */
+/* x >= 0 ? ~y : y into ~((x >> (prec-1)) ^ y). */
+ (simplify
+  (cond (cmp @0 integer_zerop) (bit_not @1) @1)
+   (if (INTEGRAL_TYPE_P (type)
+   && INTEGRAL_TYPE_P (TREE_TYPE (@0))
+&& !TYPE_UNSIGNED (TREE_TYPE (@0))
+&& TYPE_PRECISION (TREE_TYPE (@0)) == TYPE_PRECISION (type))
+(with
+ {
+   tree shifter = build_int_cst (integer_type_node, TYPE_PRECISION (type) 
- 1);
+ }
+(if (cmp == LT_EXPR)
+ (bit_xor (convert (rshift @0 {shifter;})) @1)
+ (bit_not (bit_xor (convert (rshift @0 {shifter;})) @1))
+/* x < 0 ? y : ~y into ~((x >> (prec-1)) ^ y). */
+/* x >= 0 ? y : ~y into (x >> (prec-1)) ^ y. */
+ (simplify
+  (cond (cmp @0 integer_zerop) @1 (bit_not @1))
+   (if (INTEGRAL_TYPE_P (type)
+   && INTEGRAL_TYPE_P (TREE_TYPE (@0))
+&& !TYPE_UNSIGNED (TREE_TYPE (@0))
+&& TYPE_PRECISION (TREE_TYPE (@0)) == TYPE_PRECISION (type))
+(with
+ {
+   tree shifter = build_int_cst (integer_type_node, TYPE_PRECISION (type) 
- 1);
+ }
+(if (cmp == GE_EXPR)
+ (bit_xor (convert (rshift @0 {shifter;})) @1)
+ (bit_not (bit_xor (convert (rshift @0 {shifter;})) @1)))
+
 /* If we have (A & C) != 0 ? D : 0 where C and D are powers of 2,
convert this into a shift followed by ANDing with D.  */
 (simplify
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr96928-1.c 
b/gcc/testsuite/gcc.dg/tree-ssa/pr96928-1.c
new file mode 100644
index 000..a2770e5e896
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr96928-1.c
@@ -0,0 +1,48 @@
+/* PR tree-optimization/96928 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-phiopt2" } */
+/* { dg-final { scan-tree-dump-times " = a_\[0-9]*\\\(D\\\) >> " 5 "phiopt2" } 
} */
+/* { dg-final { scan-tree-dump-times " = ~c_\[0-9]*\\\(D\\\);" 1 "phiopt2" } } 
*/
+/* { dg-final { scan-tree-dump-times " = ~" 1 "phiopt2" } } */
+/* { dg-final { scan-tree-dump-times " = \[abc_0-9\\\(\\\)D]* \\\^ " 5 
"phiopt2" } } */
+/* { dg-final { scan-tree-dump-not "a < 0" "phiopt2" } } */
+
+int
+foo (int a)
+{
+  if (a < 0)
+return ~a;
+  return a;
+}
+
+int
+bar (int a, int b)
+{
+  if (a < 0)
+return ~b;
+  return b;
+}
+
+unsigned
+baz (int a, unsigned int b)
+{
+  if (a < 0)
+return ~b;
+  return b;
+}
+
+unsigned
+qux (int a, unsigned int c)
+{
+  if (a >= 0)
+return ~c;
+  return c;
+}
+
+int
+corge (int a, int b)
+{
+  if (a >= 0)
+return b;
+  return ~b;
+}
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr96928.c 
b/gcc/testsuite/gcc.dg/tree-ssa/pr96928.c
index 20913572691..e8fd82fc26e 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/pr96928.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr96928.c
@@ -1,8 +1,11 @@
 /* PR tree-optimization/96928 */
 /* { dg-do compile } */
-/* { dg-options "-O2 -fdump-tree-phiopt2" } */
+/* { dg-options "-O2 -fdump-tree-phiopt2 -fdump-tree-optimized" } */
 /* { dg-final { scan-tree-dump-times " = a_\[0-9]*\\\(D\\\) >> " 5 "phiopt2" } 
} */
-/* { dg-final { scan-tree-dump-times " = ~c_\[0-9]*\\\(D\\\);" 1 "phiopt2" } } 
*/
+/* The following check is done at optimized because a ^ (~b) is rewritten as 
~(a^b)
+   and in the case of match.pd optimizing these ?:, the ~ is moved out already
+   by the time we get to phiopt2. */
+/* { dg-final { scan-tree-dump-times "\\\^ c_\[0-9]*\\\(D\\\);" 1 "optimized" 
} } */
 /* { dg-final { scan-tree-dump-times " = ~" 1 "phiopt2" } } */
 /* { dg-final { scan-tree-dump-times " = \[abc_0-9\\\(\\\)D]* \\\^ " 5 
"phiopt2" } } */
 /* { dg-final { scan-tree-dump-not "a < 0" "phiopt2" } } */
-- 
2.17.1



[PATCH] Use match-and-simplify in phi-opt

2021-05-23 Thread apinski--- via Gcc-patches
From: Andrew Pinski 

To simplify PHI-OPT and future improvements to it in most
(but not all) cases, using match-and-simplify simplifies how
much code is needed to be added.

This depends on the following two patches:
https://gcc.gnu.org/pipermail/gcc-patches/2021-May/571033.html
https://gcc.gnu.org/pipermail/gcc-patches/2021-May/571054.html
As this patch removes those parts from phiopt.

Note I will be looking to move two_value_replacement and
value_replacement to match-and-simplify next.

Note also there is one latent bug found while working
on this: https://gcc.gnu.org/PR100733 .

OK?  Bootstrapped and tested on x86_64-linux-gnu with no regressions and all 
languages.

Thanks,
Andrew Pinski

gcc/ChangeLog:

* tree-ssa-phiopt.c: Include explow.h.
Fix up comment before the pass struction.
(conditional_replacement): Remove function.
(xor_replacement): Remove function.
(match_simplify_replacement): New function.
(tree_ssa_phiopt_worker): Don't call conditional_replacement
or xor_replacement. Call match_simplify_replacement
if everything else fails to happen.
(block_with_single_simple_statement): New function.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/pr96928-1.c: Fix testcase for now that ~
happens on the outside of the bit_xor.
---
 gcc/testsuite/gcc.dg/tree-ssa/pr96928-1.c |   4 +-
 gcc/tree-ssa-phiopt.c | 478 ++
 2 files changed, 229 insertions(+), 253 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr96928-1.c 
b/gcc/testsuite/gcc.dg/tree-ssa/pr96928-1.c
index a2770e5e896..2e86620da11 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/pr96928-1.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr96928-1.c
@@ -1,9 +1,9 @@
 /* PR tree-optimization/96928 */
 /* { dg-do compile } */
-/* { dg-options "-O2 -fdump-tree-phiopt2" } */
+/* { dg-options "-O2 -fdump-tree-phiopt2 -fdump-tree-optimized" } */
 /* { dg-final { scan-tree-dump-times " = a_\[0-9]*\\\(D\\\) >> " 5 "phiopt2" } 
} */
 /* { dg-final { scan-tree-dump-times " = ~c_\[0-9]*\\\(D\\\);" 1 "phiopt2" } } 
*/
-/* { dg-final { scan-tree-dump-times " = ~" 1 "phiopt2" } } */
+/* { dg-final { scan-tree-dump-times " = ~" 1 "optimized" } } */
 /* { dg-final { scan-tree-dump-times " = \[abc_0-9\\\(\\\)D]* \\\^ " 5 
"phiopt2" } } */
 /* { dg-final { scan-tree-dump-not "a < 0" "phiopt2" } } */
 
diff --git a/gcc/tree-ssa-phiopt.c b/gcc/tree-ssa-phiopt.c
index f133659a781..f7c82cf192f 100644
--- a/gcc/tree-ssa-phiopt.c
+++ b/gcc/tree-ssa-phiopt.c
@@ -48,12 +48,11 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-eh.h"
 #include "gimple-fold.h"
 #include "internal-fn.h"
+#include "explow.h" /* For promote_mode. */
 
 static unsigned int tree_ssa_phiopt_worker (bool, bool, bool);
 static bool two_value_replacement (basic_block, basic_block, edge, gphi *,
   tree, tree);
-static bool conditional_replacement (basic_block, basic_block,
-edge, edge, gphi *, tree, tree);
 static gphi *factor_out_conditional_conversion (edge, edge, gphi *, tree, tree,
gimple *);
 static int value_replacement (basic_block, basic_block,
@@ -62,8 +61,6 @@ static bool minmax_replacement (basic_block, basic_block,
edge, edge, gphi *, tree, tree);
 static bool abs_replacement (basic_block, basic_block,
 edge, edge, gphi *, tree, tree);
-static bool xor_replacement (basic_block, basic_block,
-edge, edge, gphi *, tree, tree);
 static bool spaceship_replacement (basic_block, basic_block,
   edge, edge, gphi *, tree, tree);
 static bool cond_removal_in_popcount_clz_ctz_pattern (basic_block, basic_block,
@@ -71,6 +68,8 @@ static bool cond_removal_in_popcount_clz_ctz_pattern 
(basic_block, basic_block,
  tree, tree);
 static bool cond_store_replacement (basic_block, basic_block, edge, edge,
hash_set *);
+static bool match_simplify_replacement (basic_block, basic_block,
+   edge, edge, gimple_seq, bool, bool);
 static bool cond_if_else_store_replacement (basic_block, basic_block, 
basic_block);
 static hash_set * get_non_trapping ();
 static void replace_phi_edge_with_variable (basic_block, edge, gphi *, tree);
@@ -319,7 +318,7 @@ tree_ssa_phiopt_worker (bool do_store_elim, bool 
do_hoist_loads, bool early_p)
 
  phi = single_non_singleton_phi_for_edges (phis, e1, e2);
  if (!phi)
-   continue;
+   goto try_match_simplify;
 
  arg0 = gimple_phi_arg_def (phi, e1->dest_idx);
  arg1 = gimple_phi_arg_def (phi, e2->dest_idx);
@@ -345,14 +344,9 @@ tree_ssa_phiopt_worker (bool do_store_elim, bool 
do_hoist_loads, bool early_p)
  /* Do the replacement of condit

[PATCH 1/2] [i386] Fold blendv builtins into gimple.

2021-05-23 Thread Hongtao Liu via Gcc-patches
Hi:
  This patch is about to Fold __builtin_ia32_pblendvb128 (a, b, c) as
 VEC_COND_EXPR (c < 0, b, a), similar for float version but with
 mask operand VIEW_CONVERT_EXPR to same sized integer vectype.

After folding, blendv related patterns can be redefined as
vec_merge since all elements of mask operand is either const0_rtx or
constm1_rtx now. It could potentially enable more rtl optimizations.

Besides, although there's no pblendv{d,q} instructions, backend can
still define their patterns and generate blendv{ps,pd} instead.

  Bootstrap and regtested on x86_64-linux-gnu{-m32,}.
  Ok for trunk?

gcc/ChangeLog:

* config/i386/i386-builtin.def (IX86_BUILTIN_BLENDVPD256,
IX86_BUILTIN_BLENDVPS256, IX86_BUILTIN_PBLENDVB256,
IX86_BUILTIN_BLENDVPD, IX86_BUILTIN_BLENDVPS,
IX86_BUILTIN_PBLENDVB128): Replace icode with
CODE_FOR_nothing.
* config/i386/i386-expand.c (ix86_expand_sse_movcc): Use

gen_avx_blendvd256/gen_avx_blendvq256/gen_sse4_1_blendvd/gen_sse4_1_blendvq
for V8SI/V4DI/V4SI/V2DImode.
* config/i386/i386.c (ix86_gimple_fold_builtin): Fold blendv
builtins.
* config/i386/mmx.md (mmx_blendvps): Change to define_expand.
(*mmx_blendvps): New pattern implemented as vec_merge.
* config/i386/sse.md
(_blendv): Change to
define_expand.
(_pblendvb): Ditto.
(*_blendv): New pattern
implemented as vec_merge.
(*_pblendvb): Ditto.
(*_pblendvb_lt): Redefined as define_insn with
pattern implemented as vec_merge instead of UNSPEC_BLENDV.
(*_blendv_lt): Ditto,
and extend mode to V48_AVX.
(*_pblendvb_not_lt): New.
(*_blendv_ltint): Deleted.
(*_pblendvb_lt): Ditto.
(*_pblendvb_not_lt): Ditto.

gcc/testsuite/ChangeLog:

* gcc.target/i386/funcspec-8.c: Replace
__builtin_ia32_blendvpd with  __builtin_ia32_roundps_az.
* gcc.target/i386/blendv-1.c: New test.
* gcc.target/i386/blendv-2.c: New test.


-- 
BR,
Hongtao
From f78d9f2595c315b6343adc4c3b79b6596c45c65b Mon Sep 17 00:00:00 2001
From: liuhongt 
Date: Fri, 21 May 2021 09:48:18 +0800
Subject: [PATCH 1/2] [i386] Fold blendv builtins into gimple.

Fold __builtin_ia32_pblendvb128 (a, b, c) as VEC_COND_EXPR (c < 0, b,
a), similar for float version but with mask operand VIEW_CONVERT_EXPR
to same sized integer vectype.

After folding, blendv related patterns can be redefined as
vec_merge since all elements of mask operand is either const0_rtx or
constm1_rtx now. It could potentially enable more rtl optimizations.

Besides, although there's no pblendv{d,q} instructions, backend can
still define their patterns and generate blendv{ps,pd} instead.

gcc/ChangeLog:

	* config/i386/i386-builtin.def (IX86_BUILTIN_BLENDVPD256,
	IX86_BUILTIN_BLENDVPS256, IX86_BUILTIN_PBLENDVB256,
	IX86_BUILTIN_BLENDVPD, IX86_BUILTIN_BLENDVPS,
	IX86_BUILTIN_PBLENDVB128): Replace icode with
	CODE_FOR_nothing.
	* config/i386/i386-expand.c (ix86_expand_sse_movcc): Use
	gen_avx_blendvd256/gen_avx_blendvq256/gen_sse4_1_blendvd/gen_sse4_1_blendvq
	for V8SI/V4DI/V4SI/V2DImode.
	* config/i386/i386.c (ix86_gimple_fold_builtin): Fold blendv
	builtins.
	* config/i386/mmx.md (mmx_blendvps): Change to define_expand.
	(*mmx_blendvps): New pattern implemented as vec_merge.
	* config/i386/sse.md
	(_blendv): Change to
	define_expand.
	(_pblendvb): Ditto.
	(*_blendv): New pattern
	implemented as vec_merge.
	(*_pblendvb): Ditto.
	(*_pblendvb_lt): Redefined as define_insn with
	pattern implemented as vec_merge instead of UNSPEC_BLENDV.
	(*_blendv_lt): Ditto,
	and extend mode to V48_AVX.
	(*_pblendvb_not_lt): New.
	(*_blendv_ltint): Deleted.
	(*_pblendvb_lt): Ditto.
	(*_pblendvb_not_lt): Ditto.

gcc/testsuite/ChangeLog:

	* gcc.target/i386/funcspec-8.c: Replace
	__builtin_ia32_blendvpd with  __builtin_ia32_roundps_az.
	* gcc.target/i386/blendv-1.c: New test.
	* gcc.target/i386/blendv-2.c: New test.
---
 gcc/config/i386/i386-builtin.def   |  12 +-
 gcc/config/i386/i386-expand.c  |  22 +-
 gcc/config/i386/i386.c |  37 
 gcc/config/i386/mmx.md |  38 +++-
 gcc/config/i386/sse.md | 227 +++--
 gcc/testsuite/gcc.target/i386/blendv-1.c   |  51 +
 gcc/testsuite/gcc.target/i386/blendv-2.c   |  41 
 gcc/testsuite/gcc.target/i386/funcspec-8.c |  16 +-
 8 files changed, 303 insertions(+), 141 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/i386/blendv-1.c
 create mode 100644 gcc/testsuite/gcc.target/i386/blendv-2.c

diff --git a/gcc/config/i386/i386-builtin.def b/gcc/config/i386/i386-builtin.def
index 80c2a2c0294..0c1507317ae 100644
--- a/gcc/config/i386/i386-builtin.def
+++ b/gcc/config/i386/i386-builtin.def
@@ -902,13 +902,13 @@ BDESC (OPTION_MASK_ISA_SSSE3 | OPTION_MASK_ISA_MMX, 0, CODE_FOR_ssse3_palignrdi,
 /* SSE4.1 */
 BDESC (OPTION_MASK_ISA_SSE4_1, 0, CODE_FOR_sse4_1_blendpd, 

[PATCH 2/2] [i386] For 128/256-bit vec_cond_expr, When mask operands is lt reg const0_rtx, blendv can be used instead of avx512 mask. [PR target/100648]

2021-05-23 Thread Hongtao Liu via Gcc-patches
Hi:
  This patch is about to add define_insn_and_split to convert avx512
mask mov back to pblendv instructions when mask operand is (lt: reg
const0_rtx).

  Bootstrapped and regtested on x86_64-linux-gnu{-m32,}.
  Ok for trunk?

gcc/ChangeLog:

PR target/100648
* config/i386/sse.md (*avx_cmp3_5): New
define_insn_and_split.
(*avx_cmp3_6): Ditto.
(*avx2_pcmp3_3): Ditto.
(*avx2_pcmp3_4): Ditto.
(*avx2_pcmp3_5): Ditto.

gcc/testsuite/ChangeLog:

PR target/100648
* g++.target/i386/avx2-pr54700-2.C: Adjust testcase.
* g++.target/i386/avx512vl-pr54700-1a.C: New test.
* g++.target/i386/avx512vl-pr54700-1b.C: New test.
* g++.target/i386/avx512vl-pr54700-2a.C: New test.
* g++.target/i386/avx512vl-pr54700-2b.C: New test.
* gcc.target/i386/avx512vl-pr100648.c: New test.


[C PATCH] qualifiers of pointers to arrays in C2X [PR 98397]

2021-05-23 Thread Uecker, Martin

Hi Joseph,

I found some time to update this patch. The only real change
of the patch is the qualifier in the conditional expression for
pointer to arrays in C2X. All the rest are the warnings,
which were wrong in the last version.

I hope I got this correct this time in combination with
-pedantic-errors and -Wc11-c2x-compat. 

Martin


2021-05-16  Martin Uecker  

gcc/c/
 PR c/98397
 * c-typeck.c (comp_target_types): Change pedwarn to pedwarn_c11
 for pointers to arrays with qualifiers.
 (build_conditional_expr): For C23 don't lose qualifiers for pointers
 to arrays when the other pointer is a void pointer. Update warnings.
 (convert_for_assignment): Update warnings for C2X when converting from
 void* with qualifiers to a pointer to array with the same qualifiers.

gcc/testsuite/
 PR c/98397
 * gcc.dg/c11-qual-1.c: New test.
 * gcc.dg/c2x-qual-1.c: New test.
 * gcc.dg/c2x-qual-2.c: New test.
 * gcc.dg/c2x-qual-3.c: New test.
 * gcc.dg/c2x-qual-4.c: New test.
 * gcc.dg/c2x-qual-5.c: New test.
 * gcc.dg/c2x-qual-6.c: New test.
 * gcc.dg/pointer-array-quals-1.c: Remove unnecessary flag.
 * gcc.dg/pointer-array-quals-2.c: Remove unnecessary flag.


diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index fc64ef96fb8..5b13656c090 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -1328,8 +1328,8 @@ comp_target_types (location_t location, tree ttl, tree 
ttr)
   val = comptypes_check_enum_int (mvl, mvr, &enum_and_int_p);
 
   if (val == 1 && val_ped != 1)
-pedwarn (location, OPT_Wpedantic, "pointers to arrays with different 
qualifiers "
-  "are incompatible in ISO C");
+pedwarn_c11 (location, OPT_Wpedantic, "invalid use of pointers to arrays 
with different qualifiers "
+ "in ISO C before C2X");
 
   if (val == 2)
 pedwarn (location, OPT_Wpedantic, "types are not quite compatible");
@@ -5396,39 +5396,40 @@ build_conditional_expr (location_t colon_loc, tree 
ifexp, bool ifexp_bcp,
"used in conditional expression");
  return error_mark_node;
}
-  else if (VOID_TYPE_P (TREE_TYPE (type1))
-  && !TYPE_ATOMIC (TREE_TYPE (type1)))
-   {
- if ((TREE_CODE (TREE_TYPE (type2)) == ARRAY_TYPE)
- && (TYPE_QUALS (strip_array_types (TREE_TYPE (type2)))
- & ~TYPE_QUALS (TREE_TYPE (type1
-   warning_at (colon_loc, OPT_Wdiscarded_array_qualifiers,
-   "pointer to array loses qualifier "
-   "in conditional expression");
-
- if (TREE_CODE (TREE_TYPE (type2)) == FUNCTION_TYPE)
+  else if ((VOID_TYPE_P (TREE_TYPE (type1))
+   && !TYPE_ATOMIC (TREE_TYPE (type1)))
+  || (VOID_TYPE_P (TREE_TYPE (type2))
+  && !TYPE_ATOMIC (TREE_TYPE (type2
+   {
+ tree t1 = TREE_TYPE (type1);
+ tree t2 = TREE_TYPE (type2);
+ if (!VOID_TYPE_P (t1))
+  {
+/* roles are swapped */
+t1 = t2;
+t2 = TREE_TYPE (type1);
+  }
+ tree t2_stripped = strip_array_types (t2);
+ if ((TREE_CODE (t2) == ARRAY_TYPE)
+ && (TYPE_QUALS (t2_stripped) & ~TYPE_QUALS (t1)))
+   {
+ if (!flag_isoc2x)
+   warning_at (colon_loc, OPT_Wdiscarded_array_qualifiers,
+   "pointer to array loses qualifier "
+   "in conditional expression");
+ else if (warn_c11_c2x_compat > 0)
+   warning_at (colon_loc, OPT_Wc11_c2x_compat,
+   "pointer to array loses qualifier "
+   "in conditional expression in ISO C before C2X");
+   }
+ if (TREE_CODE (t2) == FUNCTION_TYPE)
pedwarn (colon_loc, OPT_Wpedantic,
 "ISO C forbids conditional expr between "
 "% and function pointer");
- result_type = build_pointer_type (qualify_type (TREE_TYPE (type1),
- TREE_TYPE (type2)));
-   }
-  else if (VOID_TYPE_P (TREE_TYPE (type2))
-  && !TYPE_ATOMIC (TREE_TYPE (type2)))
-   {
- if ((TREE_CODE (TREE_TYPE (type1)) == ARRAY_TYPE)
- && (TYPE_QUALS (strip_array_types (TREE_TYPE (type1)))
- & ~TYPE_QUALS (TREE_TYPE (type2
-   warning_at (colon_loc, OPT_Wdiscarded_array_qualifiers,
-   "pointer to array loses qualifier "
-   "in conditional expression");
-
- if (TREE_CODE (TREE_TYPE (type1)) == FUNCTION_TYPE)
-   pedwarn (colon_loc, OPT_Wpedantic,
-"ISO C forbids conditional expr between "
-"% and function pointer");
- result_type = build_pointer_type (qualify_type (TREE_TYPE (type2),
-   

[PATCH][vect] Use main loop's thresholds and vectorization factor to narrow upper_bound of epilogue

2021-05-23 Thread Andre Vieira (lists) via Gcc-patches

Hi,

When vectorizing with --param vect-partial-vector-usage=1 the vectorizer 
uses an unpredicated (all-true predicate for SVE) main loop and a 
predicated tail loop. The way this was implemented seems to mean it 
re-uses the same vector-mode for both loops, which means the tail loop 
isn't an actual loop but only executes one iteration.


This patch uses the knowledge of the conditions to enter an epilogue 
loop to help come up with a potentially more restricive upper bound.


Regression tested on aarch64-linux-gnu and also ran the testsuite using 
'--param vect-partial-vector-usage=1' detecting no ICEs and no execution 
failures.


Would be good to have this tested for PPC too as I believe they are the 
main users of the --param vect-partial-vector-usage=1 option. Can 
someone help me test (and maybe even benchmark?) this on a PPC target?


Kind regards,
Andre

gcc/ChangeLog:

    * tree-vect-loop.c (vect_transform_loop): Use main loop's 
various' thresholds

    to narrow the upper bound on epilogue iterations.

gcc/testsuite/ChangeLog:

    * gcc.target/aarch64/sve/part_vect_single_iter_epilog.c: New test.

diff --git 
a/gcc/testsuite/gcc.target/aarch64/sve/part_vect_single_iter_epilog.c 
b/gcc/testsuite/gcc.target/aarch64/sve/part_vect_single_iter_epilog.c
new file mode 100644
index 
..a03229eb55585f637ebd5288fb4c00f8f921d44c
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/sve/part_vect_single_iter_epilog.c
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O3 --param vect-partial-vector-usage=1" } */
+
+void
+foo (short * __restrict__ a, short * __restrict__ b, short * __restrict__ c, 
int n)
+{
+  for (int i = 0; i < n; ++i)
+c[i] = a[i] + b[i];
+}
+
+/* { dg-final { scan-assembler-times {\twhilelo\tp[0-9]+.h, wzr, [xw][0-9]+} 1 
} } */
diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c
index 
3e973e774af8f9205be893e01ad9263281116885..81e9c5cc42415a0a92b765bc46640105670c4e6b
 100644
--- a/gcc/tree-vect-loop.c
+++ b/gcc/tree-vect-loop.c
@@ -9723,12 +9723,31 @@ vect_transform_loop (loop_vec_info loop_vinfo, gimple 
*loop_vectorized_call)
   /* In these calculations the "- 1" converts loop iteration counts
  back to latch counts.  */
   if (loop->any_upper_bound)
-loop->nb_iterations_upper_bound
-  = (final_iter_may_be_partial
-? wi::udiv_ceil (loop->nb_iterations_upper_bound + bias_for_lowest,
- lowest_vf) - 1
-: wi::udiv_floor (loop->nb_iterations_upper_bound + bias_for_lowest,
-  lowest_vf) - 1);
+{
+  loop_vec_info main_vinfo = LOOP_VINFO_ORIG_LOOP_INFO (loop_vinfo);
+  loop->nb_iterations_upper_bound
+   = (final_iter_may_be_partial
+  ? wi::udiv_ceil (loop->nb_iterations_upper_bound + bias_for_lowest,
+   lowest_vf) - 1
+  : wi::udiv_floor (loop->nb_iterations_upper_bound + bias_for_lowest,
+lowest_vf) - 1);
+  if (main_vinfo)
+   {
+ unsigned int bound;
+ poly_uint64 main_iters
+   = upper_bound (LOOP_VINFO_VECT_FACTOR (main_vinfo),
+  LOOP_VINFO_COST_MODEL_THRESHOLD (main_vinfo));
+ main_iters
+   = upper_bound (main_iters,
+  LOOP_VINFO_VERSIONING_THRESHOLD (main_vinfo));
+ if (can_div_away_from_zero_p (main_iters,
+   LOOP_VINFO_VECT_FACTOR (loop_vinfo),
+   &bound))
+   loop->nb_iterations_upper_bound
+ = wi::umin ((widest_int) (bound - 1),
+ loop->nb_iterations_upper_bound);
+  }
+  }
   if (loop->any_likely_upper_bound)
 loop->nb_iterations_likely_upper_bound
   = (final_iter_may_be_partial