https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127086

Bohan Lei <garthlei at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |garthlei at gcc dot gnu.org

--- Comment #9 from Bohan Lei <garthlei at gcc dot gnu.org> ---
(In reply to Anton Blanchard from comment #8)
> Thanks Jeff, I tested trunk Bohan's fix against cpu2017 x264 but it didn't
> fix the problem. Claude came up with the following test where the function
> call is before the loop:
> 
> /* { dg-do compile } */
> /* { dg-options "-march=rv64gcv -mabi=lp64d -O3" } */
> 
> void tick (void);
> 
> void
> call_then_avg (unsigned char *dst, const unsigned char *s1,
>              const unsigned char *s2, int w, int h, int ds, int ss1, int ss2)
> {
>   tick ();
>   for (int y = 0; y < h; y++)
>     {
>       for (int x = 0; x < w; x++)
>       dst[x] = (s1[x] + s2[x] + 1) >> 1;
>       dst += ds;
>       s1 += ss1;
>       s2 += ss2;
>     }
> }
> 
> /* The write must come after the call and before the first loop label.  */
> /* { dg-final { scan-assembler
> {call_then_avg:\n(?:[^\n]*\n)*?\tcall\ttick(?:@plt)?\n(?:(?!\.L[0-9]+:
> )[^\n]*\n)*?\tcsrwi\tvxrm,0\n} } } */
> /* { dg-final { scan-assembler-times {\tcsrwi\tvxrm,} 1 } } */

I confirmed that in our x264 build.  Actually the testcase you provided here is
not exactly the same as the x264 scenario.  Here the call stands in every path
from entry to the VXRM use, and the entry write should be eliminated as per our
current strategy.  In x264 (refine_subpel), the entry write that we added in
the patch is preserved, but as there can still be calls before the VXRM use,
and the in-loop VXRM writes are inserted for correctness in spite of the entry
writes.

So this is indeed a problem.  I had thought it would behave as well in x264 and
didn't check the x264 build with the new patch carefully.  I was wondering if
we should implement something like my earlier patch to tackle this.

Reply via email to