Bug 39068 - signed short plus and signed char plus not vectorized
Summary: signed short plus and signed char plus not vectorized
Status: RESOLVED DUPLICATE of bug 26128
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.4.0
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization
: 39069 (view as bug list)
Depends on:
Blocks:
 
Reported: 2009-02-01 20:34 UTC by Dan Nicolaescu
Modified: 2009-02-06 01:51 UTC (History)
4 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dan Nicolaescu 2009-02-01 20:34:48 UTC
gcc -march=core2 -O3 -ftree-vectorizer-verbose=6 
for this code: 

#define SIZE 10000
signed short a[SIZE];
signed short b[SIZE];
signed short c[SIZE];

void add()
{
  int i;
  for (i = 0; i < SIZE; ++i)
    a[i] = b[i] + c[i];
}

cannot vectorize the loop:

add_sshort.c:9: note: vect_model_load_cost: aligned.
add_sshort.c:9: note: vect_model_load_cost: inside_cost = 1, outside_cost = 0 .
add_sshort.c:9: note: not vectorized: relevant stmt not supported: D.1580_6 = (short unsigned int) D.1579_5
add_sshort.c:7: note: vectorized 0 loops in function.

The same happens if the type for a,b and c is "signed char".

But if the type is "unsigned short" or "unsigned char" the loop is vectorized.
Comment 1 Richard Biener 2009-02-01 20:50:06 UTC
*** Bug 39069 has been marked as a duplicate of this bug. ***
Comment 2 dorit 2009-02-01 21:06:20 UTC
(reminds me of a couple missed-optimization PRs where vectorization is also failing due to casts - PR31873 , PR26128 - don't know if this is related)
Comment 3 Dan Nicolaescu 2009-02-02 16:42:44 UTC
(In reply to comment #2)
> (reminds me of a couple missed-optimization PRs where vectorization is also
> failing due to casts - PR31873 , PR26128 - don't know if this is related)

Are the casts actually needed in this case?  It seems the get introduced very early on, the .original dump already has:

  a[i] = (short int) ((short unsigned int) b[i] + (short unsigned int) c[i]);


Comment 4 Andrew Pinski 2009-02-06 01:45:13 UTC
(In reply to comment #3)
> Are the casts actually needed in this case?  It seems the get introduced very
> early on, the .original dump already has:

Yes because char = char + char is really char = (char)((int)char + (int)char);

So this is dup of bug 26128.

*** This bug has been marked as a duplicate of 26128 ***
Comment 5 Andrew Pinski 2009-02-06 01:51:45 UTC
(In reply to comment #4)
> Yes because char = char + char is really char = (char)((int)char + (int)char);

Let me expand on that.  ((char)CHAR_MAX) + 1 is well defined and there is no overflow that occurs.  Since GCC internally assumes signed integer overflow is undefined, it has to convert it to be the well defined unsigned integer version.