[backport from gcc-4.8/trunk r188733 ] gcc/ 2012-06-18 Richard Guenther PR tree-optimization/53693 * tree-vect-patterns.c (vect_operation_fits_smaller_type): Reject operands with more than one use. gcc/testsuite/ 2012-06-18 Richard Guenther PR tree-optimization/53693 * g++.dg/torture/pr53693.C: New testcase. --- gcc-4.7.1/gcc/testsuite/g++.dg/torture/pr53693.C.~1~ 1970-01-01 01:00:00.000000000 +0100 +++ gcc-4.7.1/gcc/testsuite/g++.dg/torture/pr53693.C 2012-06-24 11:48:40.000000000 +0200 @@ -0,0 +1,21 @@ +// { dg-do compile } + +void +filter_scanlines (void *src_buffer, void *dst_buffer, int dst_pitch, int width) +{ + int x; + unsigned short *src, *dst_a, *dst_b; + + src = (unsigned short *) src_buffer; + dst_a = (unsigned short *) dst_buffer; + dst_b = ((unsigned short *) dst_buffer) + (dst_pitch >> 1); + + for (x = 0; x < width; x++) + { + unsigned char gs, gh; + gs = src[x]; + gh = gs + (gs >> 1); + dst_a[x] = (gh << 5) | (gh); + dst_b[x] = ((gs - gh) << 5) | (gs - gh); + } +} --- gcc-4.7.1/gcc/tree-vect-patterns.c.~1~ 2012-05-04 22:59:13.000000000 +0200 +++ gcc-4.7.1/gcc/tree-vect-patterns.c 2012-06-24 11:48:40.000000000 +0200 @@ -937,6 +937,11 @@ vect_operation_fits_smaller_type (gimple || TREE_CODE (const_oprnd) != INTEGER_CST) return false; + /* If oprnd has other uses besides that in stmt we cannot mark it + as being part of a pattern only. */ + if (!has_single_use (oprnd)) + return false; + /* If we are in the middle of a sequence, we use DEF from a previous statement. Otherwise, OPRND has to be a result of type promotion. */ if (*new_type)