[PATCH] Fix PR58115

Richard Sandiford rdsandiford@googlemail.com
Thu Jan 9 09:02:00 GMT 2014

Bernd Edlinger <bernd.edlinger@hotmail.de> writes:
> I found another test case that still fails with today's trunk:
> #include <immintrin.h>
> __m256 a[10], b[10], c[10];
> void __attribute__((target ("sse2"), optimize (3)))
> foo (void)
> {
> }
> void __attribute__((target ("avx"), optimize (3)))
> bar (void)
> {
>   a[0] = _mm256_and_ps (b[0], c[0]);
> }
> compile with i686-pc-linux-gnu-gcc -O2 -msse2 -mno-avx -S  
> The attached patch seems to fix this test case for
> targets that do not have SWITCHABLE_TARGET.
> What do you think about it?

It looks like a correct fix, but the memcpy is going to be pretty
expensive, since in most cases there will be no difference.

Calling target_reinit is the rare case, and already very slow itself,
so maybe an easier option would be to have a target_reinit counter.
with a "number of target_reinit calls" field.

Not sure it's worth the effort though.  The other targets should
really move to SWITCHABLE_TARGET too.  One of the reasons why I made
SWITCHABLE_TARGET optional was that I was worried it might slow down
the compiler for targets that didn't need it.  Jakub's measurements
suggest that any compile-time effect is in the noise though.

> I think Jakub's patch will fix this case, but I did not try.
> However even if the i368 is now clean, there are
> still many targets that use target_reinit() in
> target_set_current_function.

FWIW I only see three others (nios, rs6000 and rx).  nios and rs6000
are direct cut-&-pastes of the i386 version so should be easy to switch.
rx looks more like MIPS in that it's switching between two specific


More information about the Gcc-patches mailing list