The testcase: --cut here-- #define N 256 int b[N]; void test() { int i; for (i = 0; i < N; i++) b[i] = 0; } --cut here-- compiles with '-O2 -msse2 -ftree-vectorize' into: test: movl $16, %eax pxor %xmm0, %xmm0 movdqa %xmm0, b .p2align 4,,7 .L2: pxor %xmm0, %xmm0 movdqa %xmm0, b(%eax) addl $16, %eax cmpl $1024, %eax jne .L2 rep ; ret Please note second pxor that is _not_ needed. Also, it should be moved out of loop as it is loop invariant. For slightly different testcase, where 'b[i] = 1' (or anything != 0) we get optimized code: test: movl $16, %eax movdqa .LC0, %xmm0 movdqa %xmm0, b .p2align 4,,7 .L2: movdqa %xmm0, b(%eax) addl $16, %eax cmpl $1024, %eax jne .L2 rep ; ret It looks like (g)cse doesn't know what 'xor N,N' means.
It is a target issue. Working on a fix.
Shouldn't rtl invariant motion catch this?
(In reply to comment #2) > Shouldn't rtl invariant motion catch this? It would be nice, but the problem is again in the fact that we lie to the compiler about supported instructions. This one is not a valid x86 insn: (insn 12 8 13 2 (set (mem:V4SI (symbol_ref:DI ("b") <var_decl 0x2aaaae15b000 b>) [3 S16 A128]) (const_vector:V4SI [ (const_int 0 [0x0]) (const_int 0 [0x0]) (const_int 0 [0x0]) (const_int 0 [0x0]) ])) 919 {*movv4si_internal} (nil) (nil)) This sequence is later split into pxor+store, unfortunatelly a bit late in the game, after RTL optimizers have already done their job.
Subject: Bug 30970 Author: uros Date: Tue Feb 27 21:27:27 2007 New Revision: 122387 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=122387 Log: PR target/30970 * config/i386/sse.md (*mov<mode>_internal, *movv4sf_internal, *movv2df_internal): Enable pattern only for valid operand combinations. * config/i386/i386.c (ix86_modes_tieable_p): For SSE registers, tie only 128bit modes. For MMX registers, tie only 64bit modes. testsuite/ChangeLog: PR target/30970 * gcc.target/i386/gfortran.dg/pr30970.c: New test. Added: trunk/gcc/testsuite/gcc.target/i386/pr30970.c Modified: trunk/gcc/ChangeLog trunk/gcc/config/i386/i386.c trunk/gcc/config/i386/sse.md trunk/gcc/testsuite/ChangeLog
Fixed in mainline.