Bug 26128 - Trivial operation not vectorized on char/short
Summary: Trivial operation not vectorized on char/short
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.2.0
: P3 enhancement
Target Milestone: 4.5.0
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization
: 29170 32309 39068 (view as bug list)
Depends on:
Blocks: vectorizer
  Show dependency treegraph
 
Reported: 2006-02-06 14:55 UTC by Isabelle Hurbain
Modified: 2012-07-13 14:05 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.5.4, 4.8.0
Known to fail: 4.4.6
Last reconfirmed: 2006-02-06 15:00:36


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Isabelle Hurbain 2006-02-06 14:55:22 UTC
char a[16] __attribute__((aligned)) = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
char b[16] __attribute__((aligned)) = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
char c[16] __attribute__((aligned));

int i;

for(i = 0; i<16; i++)
  {
    c[i] = a[i] + b[i];
  }

for(i = 0; i<16; i++)
  {
    printf("%i ", c[i]);
  }


This code is not vectorized anymore in GCC 4.2.0 (svn checkout on Feb, 06 2006). The vectorizer tells that :

paddb4bugreport.c:14: note: vect_is_simple_use: operand (unsigned char) D.1872_47
paddb4bugreport.c:14: note: not ssa-name.
paddb4bugreport.c:14: note: use not simple.
paddb4bugreport.c:14: note: not vectorized: relevant stmt not supported: D.1873_48 = (unsigned char) D.1872_47
paddb4bugreport.c:14: note: bad operation or unsupported loop bound.(get_loop_exit_condition
  if (ivtmp.52_2 != 0) goto <L13>; else goto <L5>;)

Seems to be a problem before the autovectorizer as the (unsigned char) cast should not happen IMHO.
Comment 1 Andrew Pinski 2006-02-06 15:00:36 UTC
Actually this is a known regression and a missed optimization regression caused by fixing up wrong code.

The work around is to use -fwrapv.
Comment 2 Andrew Pinski 2006-09-21 17:11:52 UTC
*** Bug 29170 has been marked as a duplicate of this bug. ***
Comment 3 Andrew Pinski 2007-06-12 17:36:49 UTC
*** Bug 32309 has been marked as a duplicate of this bug. ***
Comment 4 Andrew Pinski 2009-02-06 01:45:13 UTC
*** Bug 39068 has been marked as a duplicate of this bug. ***
Comment 5 Richard Biener 2012-07-13 08:57:17 UTC
Link to vectorizer missed-optimization meta-bug.
Comment 6 Richard Biener 2012-07-13 14:05:50 UTC
Making the testcase actually compile like

char a[16] __attribute__((aligned(16))) = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
    13, 14, 15, 16};
char b[16] __attribute__((aligned(16))) = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
    13, 14, 15, 16};
char c[16] __attribute__((aligned(16)));

int main()
{
  int i;

  for(i = 0; i<16; i++)
    {
      c[i] = a[i] + b[i];
    }

  for(i = 0; i<16; i++)
    {
      printf("%i ", c[i]);
    }
}

shows:

c> /space/rguenther/install/gcc-4.5.4/bin/gcc -O3 t.c -ftree-vectorizer-verbose=1
t.c: In function 'main':
t.c:18:7: warning: incompatible implicit declaration of built-in function 'printf'

t.c:11: note: LOOP VECTORIZED.
t.c:7: note: vectorized 1 loops in function.


Thus fixed, in GCC 4.5.