Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GCC 9: miscompilation of saxpy_kernel_16 #1964

Closed
marxin opened this issue Jan 16, 2019 · 5 comments
Closed

GCC 9: miscompilation of saxpy_kernel_16 #1964

marxin opened this issue Jan 16, 2019 · 5 comments
Milestone

Comments

@marxin
Copy link
Contributor

marxin commented Jan 16, 2019

Using latest GCC one can see many test failures. I isolated a test-case for that:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88880#c0

and the problem is in:
../kernel/x86_64/saxpy_microk_haswell-2.c:

    31	static void saxpy_kernel_16( BLASLONG n, FLOAT *x, FLOAT *y, FLOAT *alpha)
    32	{
    33	
    34	
    35		BLASLONG register i = 0;
    36	
    37		__asm__  __volatile__
    38		(
    39		"vbroadcastss		(%4), %%ymm0		    \n\t"  // alpha	
    40	
    41		".p2align 4				            \n\t"
    42		"1:				            \n\t"
    43	
    44	        "vmovups                  (%3,%0,4), %%ymm12         \n\t"  // 8 * y
    45	        "vmovups                32(%3,%0,4), %%ymm13         \n\t"  // 8 * y
    46	        "vmovups                64(%3,%0,4), %%ymm14         \n\t"  // 8 * y
    47	        "vmovups                96(%3,%0,4), %%ymm15         \n\t"  // 8 * y
    48		"vfmadd231ps       (%2,%0,4), %%ymm0  , %%ymm12  	     \n\t"   // y += alpha * x
    49		"vfmadd231ps     32(%2,%0,4), %%ymm0  , %%ymm13  	     \n\t"   // y += alpha * x
    50		"vfmadd231ps     64(%2,%0,4), %%ymm0  , %%ymm14  	     \n\t"   // y += alpha * x
    51		"vfmadd231ps     96(%2,%0,4), %%ymm0  , %%ymm15  	     \n\t"   // y += alpha * x
    52		"vmovups	%%ymm12,   (%3,%0,4)		     \n\t"
    53		"vmovups	%%ymm13, 32(%3,%0,4)		     \n\t"
    54		"vmovups	%%ymm14, 64(%3,%0,4)		     \n\t"
    55		"vmovups	%%ymm15, 96(%3,%0,4)		     \n\t"
    56	
    57		"addq		$32, %0	  	 	             \n\t"
    58		"subq	        $32, %1			             \n\t"		
    59		"jnz		1b		             \n\t"
    60		"vzeroupper				     \n\t"
    61	
    62		:
    63	        : 
    64	          "r" (i),	// 0	
    65		  "r" (n),  	// 1
    66	          "r" (x),      // 2
    67	          "r" (y),      // 3
    68	          "r" (alpha)   // 4
    69		: "cc", 
    70		  "%xmm0", 
    71		  "%xmm8", "%xmm9", "%xmm10", "%xmm11", 
    72		  "%xmm12", "%xmm13", "%xmm14", "%xmm15",
    73		  "memory"
    74		);
    75	

Inputs 0 and 1 are marked as read-only, but are modified at lines 57 and 58.
Thus one needs something like:

diff --git a/kernel/x86_64/saxpy_microk_haswell-2.c b/kernel/x86_64/saxpy_microk_haswell-2.c
index 3a743d64..7994735b 100644
--- a/kernel/x86_64/saxpy_microk_haswell-2.c
+++ b/kernel/x86_64/saxpy_microk_haswell-2.c
@@ -60,9 +60,9 @@ static void saxpy_kernel_16( BLASLONG n, FLOAT *x, FLOAT *y, FLOAT *alpha)
        "vzeroupper                                  \n\t"
 
        :
+          "+r" (i),    // 0    
+         "+r" (n)      // 1
         : 
-          "r" (i),     // 0    
-         "r" (n),      // 1
           "r" (x),      // 2
           "r" (y),      // 3
           "r" (alpha)   // 4

Note that similar problem may be in other implementations (or asm statements).
Thanks

@martin-frbg
Copy link
Collaborator

Thanks. I vaguely remember fixing something very similar a year ago (ah yes, #1292) in response to more aggressive reuse of registers by gcc8, it seems I never got around to fixing more than the gemv kernels although I noticed that there were around 100 suspect files.

@peter-bergner
Copy link

FYI, GCC 9 will be even more aggressive at reusing registers than GCC 8.

@martin-frbg
Copy link
Collaborator

I guess so. I am about halfway through with fixing AXPY and DOT already, then to see what else has this defect.

@marxin
Copy link
Contributor Author

marxin commented Jan 18, 2019

Thanks for the fixes. When do you expect it will land in a release?

@martin-frbg martin-frbg added this to the 0.3.6 milestone Jan 18, 2019
@martin-frbg
Copy link
Collaborator

No release date set yet, probably end of February.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants