public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/112742] New: missed vectorization with src[a*b+i] where a*b is not int rather than same percission as size_type
@ 2023-11-28  7:43 pinskia at gcc dot gnu.org
  2023-11-28 11:56 ` [Bug tree-optimization/112742] " rguenth at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-11-28  7:43 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 112742
           Summary: missed vectorization with src[a*b+i] where a*b is not
                    int rather than same percission as size_type
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
            Blocks: 53947
  Target Milestone: ---
            Target: x86_64-*-* aarch64-*-*

Take:
```
void f(unsigned char * __restrict src, 
      unsigned stride, int h, int row)
{
  unsigned char *src1 = src+row*stride;
  for(int col = 0; col < h; col++)
    {
        src1[col]=src1[col] + 1;
    }
}

void f1(unsigned char * __restrict src, unsigned rs,
      unsigned cs, unsigned stride, int h, int row)
{
  for(int col = 0; col < h; col++)
    {
        src[row*stride+col]=src[row*stride+col] + 1;
    }
}
```

These 2 function should be vectorized. But f1 does not. If we use -m32 (or
-mabi=ilp32 on aarch64) f1 does now get vectorized.
Note LLVM is able to vectorize f1 for both aarch64 and x86_64.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53947
[Bug 53947] [meta-bug] vectorizer missed-optimizations

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

* [Bug tree-optimization/112742] missed vectorization with src[a*b+i] where a*b is not int rather than same percission as size_type
  2023-11-28  7:43 [Bug tree-optimization/112742] New: missed vectorization with src[a*b+i] where a*b is not int rather than same percission as size_type pinskia at gcc dot gnu.org
@ 2023-11-28 11:56 ` rguenth at gcc dot gnu.org
  2023-11-28 12:02 ` rguenth at gcc dot gnu.org
  2023-12-15  5:58 ` [Bug tree-optimization/112742] missed vectorization with src[a*b+i] where a*b is not int rather than the same precision " pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-11-28 11:56 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2023-11-28
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
The issue is that row*stride + col doesn't evolve with an affine function as
far as SCEV is concerned.

t.c:6:32: missed:  failed: evolution of base is not affine.

The "issue" is that we are dealing with pointer arithmetic here and the
row*stride + col can overflow but SCEV doesn't have "assumptions" we
could verify at runtime.

Use a signed 'stride', otherwise all arithmetic is promoted unsigned.

Duplicate of other similar bugs.

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

* [Bug tree-optimization/112742] missed vectorization with src[a*b+i] where a*b is not int rather than same percission as size_type
  2023-11-28  7:43 [Bug tree-optimization/112742] New: missed vectorization with src[a*b+i] where a*b is not int rather than same percission as size_type pinskia at gcc dot gnu.org
  2023-11-28 11:56 ` [Bug tree-optimization/112742] " rguenth at gcc dot gnu.org
@ 2023-11-28 12:02 ` rguenth at gcc dot gnu.org
  2023-12-15  5:58 ` [Bug tree-optimization/112742] missed vectorization with src[a*b+i] where a*b is not int rather than the same precision " pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-11-28 12:02 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
Ah, row*stride is loop invariant and that saves us with -m32.  With -m64
we end up with

  <bb 3> [local count: 105119324]:
  row.0_1 = (unsigned int) row_13(D);
  _2 = row.0_1 * stride_14(D);

  <bb 4> [local count: 955630224]:
  # col_20 = PHI <col_17(6), 0(3)>
  col.1_3 = (unsigned int) col_20;
  _4 = _2 + col.1_3;
  _5 = (sizetype) _4;
  _6 = src_15(D) + _5;
  _7 = *_6;

which is "unfortuante" association of the (sizetype) conversion.  But
as the col addtition is unsigned it might overflow and we can't
associate the (sizetype) conversion but it makes the result non-affine.

A runtime versioning would be necessary, guaranteeing that _2 + col.1_3
never overflows.

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

* [Bug tree-optimization/112742] missed vectorization with src[a*b+i] where a*b is not int rather than the same precision as size_type
  2023-11-28  7:43 [Bug tree-optimization/112742] New: missed vectorization with src[a*b+i] where a*b is not int rather than same percission as size_type pinskia at gcc dot gnu.org
  2023-11-28 11:56 ` [Bug tree-optimization/112742] " rguenth at gcc dot gnu.org
  2023-11-28 12:02 ` rguenth at gcc dot gnu.org
@ 2023-12-15  5:58 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-12-15  5:58 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |pinskia at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I am going to take a stab at implementing this ...

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

end of thread, other threads:[~2023-12-15  5:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-28  7:43 [Bug tree-optimization/112742] New: missed vectorization with src[a*b+i] where a*b is not int rather than same percission as size_type pinskia at gcc dot gnu.org
2023-11-28 11:56 ` [Bug tree-optimization/112742] " rguenth at gcc dot gnu.org
2023-11-28 12:02 ` rguenth at gcc dot gnu.org
2023-12-15  5:58 ` [Bug tree-optimization/112742] missed vectorization with src[a*b+i] where a*b is not int rather than the same precision " pinskia at gcc dot gnu.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).