Bug 44284

Summary: vectorization does not work for short variable
Product: gcc Reporter: Roy Rosen <roy.1rosen>
Component: tree-optimizationAssignee: Richard Biener <rguenth>
Status: RESOLVED FIXED    
Severity: enhancement CC: gcc-bugs, roy.1rosen
Priority: P3 Keywords: missed-optimization
Version: 4.4.3   
Target Milestone: 4.5.1   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2010-05-26 15:40:22
Attachments: preprocessed file

Description Roy Rosen 2010-05-26 15:36:51 UTC
Hi,

I have tried vectorization and encountered a problem which I can see
is common to some ports (I tried ia64 and bfin).

For this function:

#define ts unsigned short
void f(ts* __restrict__ a, ts* __restrict__ b, ts* __restrict__ x)
{
   int i;
   for (i=0;i<1024;i++)
       x[i] = a[i] + b[i];
}

the loop is vectorized.
But if I define ts as follows: #define ts short
then the loop is not vectorized. The message I get is:

./a.c:21: note: no optab.
./a.c:21: note: not vectorized: relevant stmt not supported: D.1279_12
= (short unsigned int) D.1278_11;

I have tried to look a bit in the vectorizer code and it seems that
for this stmt I get to vectorizable_operation with code==NOP_EXPR
which is not handled.

Does anyone knows anything about this problem?

Thanks, Roy.

./xgcc -v -save-temps -O3 -S ./a.c -ftree-vectorizer-verbose=2
Using built-in specs.
Target: ia64-*-linux
Configured with: ../gcc-4.4.3/configure --target='ia64-*-linux' --enable-languages=c : (reconfigured)
Thread model: posix
gcc version 4.4.3 (GCC)
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-O3' '-S' '-ftree-vectorizer-verbose=2'
 cc1 -E -quiet -v -iprefix /home/swproj/sw/users/eyalhar/gcc-ia64/gcc/../lib/gcc/ia64-*-linux/4.4.3/ ./a.c -ftree-vectorizer-verbose=2 -O3 -fpch-preprocess -o a.i
ignoring nonexistent directory "/home/swproj/sw/users/eyalhar/gcc-ia64/gcc/../lib/gcc/ia64-*-linux/4.4.3/include"
ignoring nonexistent directory "/home/swproj/sw/users/eyalhar/gcc-ia64/gcc/../lib/gcc/ia64-*-linux/4.4.3/include-fixed"
ignoring nonexistent directory "/home/swproj/sw/users/eyalhar/gcc-ia64/gcc/../lib/gcc/ia64-*-linux/4.4.3/../../../../ia64-*-linux/sys-include"
ignoring nonexistent directory "/home/swproj/sw/users/eyalhar/gcc-ia64/gcc/../lib/gcc/ia64-*-linux/4.4.3/../../../../ia64-*-linux/include"
ignoring nonexistent directory "/home/swproj/sw/users/eyalhar/gcc-ia64/gcc/../lib/gcc/../../lib/gcc/ia64-*-linux/4.4.3/include"
ignoring nonexistent directory "/home/swproj/sw/users/eyalhar/gcc-ia64/gcc/../lib/gcc/../../lib/gcc/ia64-*-linux/4.4.3/include-fixed"
ignoring nonexistent directory "/home/swproj/sw/users/eyalhar/gcc-ia64/gcc/../lib/gcc/../../lib/gcc/ia64-*-linux/4.4.3/../../../../ia64-*-linux/sys-include"
ignoring nonexistent directory "/home/swproj/sw/users/eyalhar/gcc-ia64/gcc/../lib/gcc/../../lib/gcc/ia64-*-linux/4.4.3/../../../../ia64-*-linux/include"
#include "..." search starts here:
#include <...> search starts here:
End of search list.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-O3' '-S' '-ftree-vectorizer-verbose=2'
 cc1 -fpreprocessed a.i -quiet -dumpbase a.c -auxbase a -O3 -version -ftree-vectorizer-verbose=2 -o a.s
GNU C (GCC) version 4.4.3 (ia64-*-linux)
        compiled by GNU C version 4.1.2 20080704 (Red Hat 4.1.2-44), GMP version 4.3.2, MPFR version 2.4.2.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: cc15465375f06438c45a5c1ccdf35a17

./a.c:21: note: not vectorized: relevant stmt not supported: D.1236_12 = (short unsigned int) D.1235_11;

./a.c:18: note: vectorized 0 loops in function.
COMPILER_PATH=
LIBRARY_PATH=
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-O3' '-S' '-ftree-vectorizer-verbose=2'
Comment 1 Roy Rosen 2010-05-26 15:38:21 UTC
Created attachment 20752 [details]
preprocessed file
Comment 2 Richard Biener 2010-05-26 15:40:22 UTC
Confirmed.  Mine.
Comment 3 Richard Biener 2010-05-27 13:24:15 UTC
Subject: Bug 44284

Author: rguenth
Date: Thu May 27 13:23:45 2010
New Revision: 159920

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=159920
Log:
2010-05-27  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/44284
	* tree-vect-stmts.c (vectorizable_assignment): Handle
	sign-changing conversions as simple copy.

	* gcc.dg/vect/vect-118.c: New testcase.
	* gcc.dg/vect/bb-slp-20.c: Adjust.
	* gcc.dg/vect/no-section-anchors-vect-36.c: Likewise.
	* gcc.dg/vect/slp-9.c: Likewise.
	* gcc.dg/vect/slp-reduc-4.c: Likewise.
	* gcc.dg/vect/vect-10.c: Likewise.
	* gcc.dg/vect/vect-109.c: Likewise.
	* gcc.dg/vect/vect-12.c: Likewise.
	* gcc.dg/vect/vect-36.c: Likewise.
	* gcc.dg/vect/vect-7.c: Likewise.
	* gcc.dg/vect/vect-iv-8.c: Likewise.
	* gcc.dg/vect/vect-multitypes-10.c: Likewise.
	* gcc.dg/vect/vect-multitypes-13.c: Likewise.
	* gcc.dg/vect/vect-multitypes-14.c: Likewise.
	* gcc.dg/vect/vect-multitypes-15.c: Likewise.
	* gcc.dg/vect/vect-multitypes-7.c: Likewise.
	* gcc.dg/vect/vect-multitypes-8.c: Likewise.
	* gcc.dg/vect/vect-multitypes-9.c: Likewise.
	* gcc.dg/vect/vect-reduc-dot-s16b.c: Likewise.
	* gcc.dg/vect/vect-reduc-dot-s8a.c: Likewise.
	* gcc.dg/vect/vect-reduc-dot-s8b.c: Likewise.
	* gcc.dg/vect/vect-reduc-dot-u16b.c: Likewise.
	* gcc.dg/vect/vect-strided-a-u32-mult.c: Likewise.
	* gcc.dg/vect/vect-strided-u32-mult.c: Likewise.
	* gcc.dg/vect/vect-widen-mult-s16.c: Likewise.
	* gcc.dg/vect/vect-widen-mult-s8.c: Likewise.
	* gcc.dg/vect/vect-widen-mult-sum.c: Likewise.
	* gcc.dg/vect/vect-widen-mult-u16.c: Likewise.

Added:
    trunk/gcc/testsuite/gcc.dg/vect/vect-118.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gcc.dg/vect/bb-slp-20.c
    trunk/gcc/testsuite/gcc.dg/vect/no-section-anchors-vect-36.c
    trunk/gcc/testsuite/gcc.dg/vect/slp-9.c
    trunk/gcc/testsuite/gcc.dg/vect/slp-reduc-4.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-10.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-109.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-12.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-36.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-7.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-iv-8.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-multitypes-10.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-multitypes-13.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-multitypes-14.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-multitypes-15.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-multitypes-7.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-multitypes-8.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-multitypes-9.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-reduc-dot-s16a.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-reduc-dot-s16b.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-reduc-dot-s8a.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-reduc-dot-s8b.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-reduc-dot-s8c.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-reduc-dot-u16b.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-strided-a-u32-mult.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-strided-u32-mult.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-widen-mult-s16.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-widen-mult-s8.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-widen-mult-sum.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-widen-mult-u16.c
    trunk/gcc/tree-vect-stmts.c

Comment 4 Richard Biener 2010-05-27 13:24:28 UTC
Fixed.
Comment 5 Richard Biener 2010-07-08 11:56:42 UTC
Subject: Bug 44284

Author: rguenth
Date: Thu Jul  8 11:56:08 2010
New Revision: 161951

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=161951
Log:
2010-07-08  Richard Guenther  <rguenther@suse.de>

	Backport from mainline
	2010-05-27  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/44284
	* tree-vect-stmts.c (vectorizable_assignment): Handle
	sign-changing conversions as simple copy.

	* gcc.dg/vect/vect-118.c: New testcase.
	* gcc.dg/vect/bb-slp-20.c: Adjust.
	* gcc.dg/vect/no-section-anchors-vect-36.c: Likewise.
	* gcc.dg/vect/slp-9.c: Likewise.
	* gcc.dg/vect/slp-reduc-4.c: Likewise.
	* gcc.dg/vect/vect-10.c: Likewise.
	* gcc.dg/vect/vect-109.c: Likewise.
	* gcc.dg/vect/vect-12.c: Likewise.
	* gcc.dg/vect/vect-36.c: Likewise.
	* gcc.dg/vect/vect-7.c: Likewise.
	* gcc.dg/vect/vect-iv-8.c: Likewise.
	* gcc.dg/vect/vect-multitypes-10.c: Likewise.
	* gcc.dg/vect/vect-multitypes-13.c: Likewise.
	* gcc.dg/vect/vect-multitypes-14.c: Likewise.
	* gcc.dg/vect/vect-multitypes-15.c: Likewise.
	* gcc.dg/vect/vect-multitypes-7.c: Likewise.
	* gcc.dg/vect/vect-multitypes-8.c: Likewise.
	* gcc.dg/vect/vect-multitypes-9.c: Likewise.
	* gcc.dg/vect/vect-reduc-dot-s16b.c: Likewise.
	* gcc.dg/vect/vect-reduc-dot-s8a.c: Likewise.
	* gcc.dg/vect/vect-reduc-dot-s8b.c: Likewise.
	* gcc.dg/vect/vect-reduc-dot-u16b.c: Likewise.
	* gcc.dg/vect/vect-strided-a-u32-mult.c: Likewise.
	* gcc.dg/vect/vect-strided-u32-mult.c: Likewise.
	* gcc.dg/vect/vect-widen-mult-s16.c: Likewise.
	* gcc.dg/vect/vect-widen-mult-s8.c: Likewise.
	* gcc.dg/vect/vect-widen-mult-sum.c: Likewise.
	* gcc.dg/vect/vect-widen-mult-u16.c: Likewise.

	2010-07-06  Richard Guenther  <rguenther@suse.de>

	PR middle-end/44828
	* convert.c (convert_to_integer): Watch out for overflowing
	MULT_EXPR as well.

	* gcc.c-torture/execute/pr44828.c: New testcase.

Added:
    branches/gcc-4_5-branch/gcc/testsuite/gcc.c-torture/execute/pr44828.c
    branches/gcc-4_5-branch/gcc/testsuite/gcc.dg/vect/vect-118.c
Modified:
    branches/gcc-4_5-branch/gcc/ChangeLog
    branches/gcc-4_5-branch/gcc/convert.c
    branches/gcc-4_5-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_5-branch/gcc/testsuite/gcc.dg/vect/bb-slp-20.c
    branches/gcc-4_5-branch/gcc/testsuite/gcc.dg/vect/no-section-anchors-vect-36.c
    branches/gcc-4_5-branch/gcc/testsuite/gcc.dg/vect/slp-9.c
    branches/gcc-4_5-branch/gcc/testsuite/gcc.dg/vect/vect-10.c
    branches/gcc-4_5-branch/gcc/testsuite/gcc.dg/vect/vect-109.c
    branches/gcc-4_5-branch/gcc/testsuite/gcc.dg/vect/vect-12.c
    branches/gcc-4_5-branch/gcc/testsuite/gcc.dg/vect/vect-36.c
    branches/gcc-4_5-branch/gcc/testsuite/gcc.dg/vect/vect-7.c
    branches/gcc-4_5-branch/gcc/testsuite/gcc.dg/vect/vect-iv-8.c
    branches/gcc-4_5-branch/gcc/testsuite/gcc.dg/vect/vect-multitypes-10.c
    branches/gcc-4_5-branch/gcc/testsuite/gcc.dg/vect/vect-multitypes-13.c
    branches/gcc-4_5-branch/gcc/testsuite/gcc.dg/vect/vect-multitypes-14.c
    branches/gcc-4_5-branch/gcc/testsuite/gcc.dg/vect/vect-multitypes-15.c
    branches/gcc-4_5-branch/gcc/testsuite/gcc.dg/vect/vect-multitypes-7.c
    branches/gcc-4_5-branch/gcc/testsuite/gcc.dg/vect/vect-multitypes-8.c
    branches/gcc-4_5-branch/gcc/testsuite/gcc.dg/vect/vect-multitypes-9.c
    branches/gcc-4_5-branch/gcc/testsuite/gcc.dg/vect/vect-reduc-dot-s16a.c
    branches/gcc-4_5-branch/gcc/testsuite/gcc.dg/vect/vect-reduc-dot-s16b.c
    branches/gcc-4_5-branch/gcc/testsuite/gcc.dg/vect/vect-reduc-dot-s8a.c
    branches/gcc-4_5-branch/gcc/testsuite/gcc.dg/vect/vect-reduc-dot-s8b.c
    branches/gcc-4_5-branch/gcc/testsuite/gcc.dg/vect/vect-reduc-dot-s8c.c
    branches/gcc-4_5-branch/gcc/testsuite/gcc.dg/vect/vect-reduc-dot-u16b.c
    branches/gcc-4_5-branch/gcc/testsuite/gcc.dg/vect/vect-strided-a-u32-mult.c
    branches/gcc-4_5-branch/gcc/testsuite/gcc.dg/vect/vect-strided-u32-mult.c
    branches/gcc-4_5-branch/gcc/testsuite/gcc.dg/vect/vect-widen-mult-s16.c
    branches/gcc-4_5-branch/gcc/testsuite/gcc.dg/vect/vect-widen-mult-s8.c
    branches/gcc-4_5-branch/gcc/testsuite/gcc.dg/vect/vect-widen-mult-sum.c
    branches/gcc-4_5-branch/gcc/testsuite/gcc.dg/vect/vect-widen-mult-u16.c
    branches/gcc-4_5-branch/gcc/tree-vect-stmts.c