public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/26731] Jump threading gets in the way of loops
       [not found] <bug-26731-4@http.gcc.gnu.org/bugzilla/>
@ 2014-12-06 19:52 ` Joost.VandeVondele at mat dot ethz.ch
  2014-12-09 14:40 ` rguenth at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Joost.VandeVondele at mat dot ethz.ch @ 2014-12-06 19:52 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=26731

Joost VandeVondele <Joost.VandeVondele at mat dot ethz.ch> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |Joost.VandeVondele at mat dot ethz
                   |                            |.ch

--- Comment #3 from Joost VandeVondele <Joost.VandeVondele at mat dot ethz.ch> ---
(In reply to Andrew Pinski from comment #0)
> Jump threading causes bad interactions with loops:
> int f(int t, int a, int x)
> {
>   int n, g;
>   if (t)
>    n = a;
>   else
>    n = 4;
>   for (g=0; g<n; g++)
>     x++;
>   return x;
> }
> 
> This should be optimized to:
> int f(int t, int a, int x)
> {
>   int n, g;
>   if (t)
>    n = a;
>   else
>    n = 4;
>   x+=n;
>   return x;
> }
> But is not because of jump threading getting in the way to dect that the
> loop is finite.

actually, it should not, for a<0 and t=1.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug tree-optimization/26731] Jump threading gets in the way of loops
       [not found] <bug-26731-4@http.gcc.gnu.org/bugzilla/>
  2014-12-06 19:52 ` [Bug tree-optimization/26731] Jump threading gets in the way of loops Joost.VandeVondele at mat dot ethz.ch
@ 2014-12-09 14:40 ` rguenth at gcc dot gnu.org
  2021-12-13 14:06 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2014-12-09 14:40 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=26731

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
Indeed x += n needs to be guarded with n > 0 - and we analyze that correctly:

Analyzing # of iterations of loop 1
  exit condition [1, + , 1](no_overflow) < a_10
  bounds on difference of bases: -2147483649 ... 2147483646
  result:
    zero if a_10 <= 0
    # of iterations (unsigned int) a_10 + 4294967295, bounded by 2147483646

but SCEV cprop doesn't handle this as it thinks that

  (x_6(D) + 1) + (a_10 > 0 ? (int) ((unsigned int) a_10 + 4294967295) : 0)

is expensive.

Of course it should have used number_of_iterations_exit instead to be able
to insert the may_be_zero condition properly which its simplistic code
doesn't handle.

Without jump threading the analysis is able to simplify the may_be_zero
condition against the dominating header copy checks.

Thus re-confirmed.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug tree-optimization/26731] Jump threading gets in the way of loops
       [not found] <bug-26731-4@http.gcc.gnu.org/bugzilla/>
  2014-12-06 19:52 ` [Bug tree-optimization/26731] Jump threading gets in the way of loops Joost.VandeVondele at mat dot ethz.ch
  2014-12-09 14:40 ` rguenth at gcc dot gnu.org
@ 2021-12-13 14:06 ` pinskia at gcc dot gnu.org
  2023-06-10  2:32 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-13 14:06 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=26731

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
In GCC 9 and above we get:
  _2 = x_6(D) + 1;
  _7 = (unsigned int) n_1;
  _11 = _7 + 4294967295;
  _15 = (int) _11;
  _16 = n_1 > 0 ? _15 : 0;
  x_3 = _2 + _16;

Which is okish, the loop has been removed but the above should be able to
reduce further:
  # RANGE [1, 2147483647] NONZERO 2147483647
  # n_1 = PHI <a_5(D)(3), 4(2)>
  # RANGE [-2147483647, 2147483647]
  _2 = x_6(D) + 1;
  # RANGE [1, 2147483647] NONZERO 2147483647
  _7 = (unsigned int) n_1;
  # RANGE [0, 2147483646] NONZERO 2147483647
  _11 = _7 + 4294967295;
  # RANGE [0, 2147483646] NONZERO 2147483647
  _15 = (intD.9) _11;
  # RANGE [0, 2147483646] NONZERO 2147483647
  _16 = n_1 > 0 ? _15 : 0;
  x_3 = _2 + _16;

The COND_EXPR should just converted into _15 but we don't ...
VRP should have done that ....

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug tree-optimization/26731] Jump threading gets in the way of loops
       [not found] <bug-26731-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2021-12-13 14:06 ` pinskia at gcc dot gnu.org
@ 2023-06-10  2:32 ` pinskia at gcc dot gnu.org
  2023-08-07  7:55 ` pinskia at gcc dot gnu.org
  2023-08-07  8:23 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-10  2:32 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=26731

--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #5)
> In GCC 9 and above we get:
>   _2 = x_6(D) + 1;
>   _7 = (unsigned int) n_1;
>   _11 = _7 + 4294967295;
>   _15 = (int) _11;
>   _16 = n_1 > 0 ? _15 : 0;
>   x_3 = _2 + _16;
> 
> Which is okish, the loop has been removed but the above should be able to
> reduce further:
>   # RANGE [1, 2147483647] NONZERO 2147483647
>   # n_1 = PHI <a_5(D)(3), 4(2)>
>   # RANGE [-2147483647, 2147483647]
>   _2 = x_6(D) + 1;
>   # RANGE [1, 2147483647] NONZERO 2147483647
>   _7 = (unsigned int) n_1;
>   # RANGE [0, 2147483646] NONZERO 2147483647
>   _11 = _7 + 4294967295;
>   # RANGE [0, 2147483646] NONZERO 2147483647
>   _15 = (intD.9) _11;
>   # RANGE [0, 2147483646] NONZERO 2147483647
>   _16 = n_1 > 0 ? _15 : 0;
>   x_3 = _2 + _16;
> 
> The COND_EXPR should just converted into _15 but we don't ...
> VRP should have done that ....

That was fixed in GCC 13 by not have the COND_EXPR have the comparison in the
first operand (I don't have the revision offhand).

We now get at optimization:
  <bb 2> [local count: 118111600]:
  if (t_4(D) != 0)
    goto <bb 3>; [50.00%]
  else
    goto <bb 4>; [50.00%]

  <bb 3> [local count: 59055800]:
  if (a_5(D) > 0)
    goto <bb 4>; [66.92%]
  else
    goto <bb 5>; [33.08%]

  <bb 4> [local count: 105119324]:
  # n_1 = PHI <a_5(D)(3), 4(2)>
  _2 = x_6(D) + 1;
  _11 = (unsigned int) n_1;
  _15 = _11 + 4294967295;
  _16 = (int) _15;
  x_3 = _2 + _16;

  <bb 5> [local count: 118111600]:
  # x_13 = PHI <x_3(4), x_6(D)(3)>
  return x_13;

}

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug tree-optimization/26731] Jump threading gets in the way of loops
       [not found] <bug-26731-4@http.gcc.gnu.org/bugzilla/>
                   ` (3 preceding siblings ...)
  2023-06-10  2:32 ` pinskia at gcc dot gnu.org
@ 2023-08-07  7:55 ` pinskia at gcc dot gnu.org
  2023-08-07  8:23 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-07  7:55 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=26731
Bug 26731 depends on bug 18940, which changed state.

Bug 18940 Summary: Loop is not vectorized when it should be (VRP)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=18940

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug tree-optimization/26731] Jump threading gets in the way of loops
       [not found] <bug-26731-4@http.gcc.gnu.org/bugzilla/>
                   ` (4 preceding siblings ...)
  2023-08-07  7:55 ` pinskia at gcc dot gnu.org
@ 2023-08-07  8:23 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-07  8:23 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=26731

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|2007-07-01 00:14:40         |2023-8-7

--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The last part of the issue here is take:
```
int f1(int i, int n)
{
        int t1 = i + 1;
        unsigned t = n;
        t -= 1;
        t1 = t1 + (int)t;
        return t1;
}
```

This should just be optimized to:
```
int f(int i, int n)
{
  return i + n;
}
```

Note the original f should really transform into:
int f0_(int t, int a, int x)
{
  int n, g;
  if (t)
  {
   n = a;
   if (a <= 0) return x;
  }
  else
   n = 4;
  x+=n;
  return x;
}

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug tree-optimization/26731] Jump threading gets in the way of loops
  2006-03-17 17:31 [Bug tree-optimization/26731] New: " pinskia at gcc dot gnu dot org
  2006-03-17 17:32 ` [Bug tree-optimization/26731] " pinskia at gcc dot gnu dot org
@ 2006-03-17 20:02 ` rguenth at gcc dot gnu dot org
  1 sibling, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2006-03-17 20:02 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from rguenth at gcc dot gnu dot org  2006-03-17 20:02 -------
Confirmed.  Though SCEV should be taught to handle this.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rguenth at gcc dot gnu dot
                   |                            |org
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2006-03-17 20:02:18
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26731


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug tree-optimization/26731] Jump threading gets in the way of loops
  2006-03-17 17:31 [Bug tree-optimization/26731] New: " pinskia at gcc dot gnu dot org
@ 2006-03-17 17:32 ` pinskia at gcc dot gnu dot org
  2006-03-17 20:02 ` rguenth at gcc dot gnu dot org
  1 sibling, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-03-17 17:32 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2006-03-17 17:32 -------
I almost think this is also the cause for PR 26727.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
OtherBugsDependingO|                            |26727
              nThis|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26731


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-08-07  8:23 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-26731-4@http.gcc.gnu.org/bugzilla/>
2014-12-06 19:52 ` [Bug tree-optimization/26731] Jump threading gets in the way of loops Joost.VandeVondele at mat dot ethz.ch
2014-12-09 14:40 ` rguenth at gcc dot gnu.org
2021-12-13 14:06 ` pinskia at gcc dot gnu.org
2023-06-10  2:32 ` pinskia at gcc dot gnu.org
2023-08-07  7:55 ` pinskia at gcc dot gnu.org
2023-08-07  8:23 ` pinskia at gcc dot gnu.org
2006-03-17 17:31 [Bug tree-optimization/26731] New: " pinskia at gcc dot gnu dot org
2006-03-17 17:32 ` [Bug tree-optimization/26731] " pinskia at gcc dot gnu dot org
2006-03-17 20:02 ` rguenth at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).