Skip to contentSkip to conversation

tcg problem running SPARC program on x86

Qemu-devel Vince Weaver 2 participants 3 messages Aug 18, 2008 – Aug 23, 2008

lore
Share & tools
lore
#0 lore raw

Hello

I'm continuing on my quest to get the SPEC2000 benchmarks running under sparc32-linux-user (so far 8 out of 48 work).

Many of the benchmarks die early on with the following error:

/fusion/research4/vince/qemu/svn/tcg/tcg.c:1455: tcg fatal error

This error is caused when tcg_reg_alloc_mov() is called but ts->val_type
is equal to 0 (which is TEMP_VAL_DEAD). So maybe the optimizer is optimizing away something that it shouldn't?

This happens in a block with multiple calls to the SPARC "mulscc"
instruction which is a complicated instruction, so maybe this is finding an obscure corner case.

I've attached a very small sample program that exhibits the bug when run with ./sparc32-linux-user/qemu-sparc32plus

Thanks for any help

Vince

! as -o mulscc.o mulscc.s ; ld -o mulscc mulscc.o

.equ SYSCALL_EXIT,1

.globl _start
_start:

        wr  	%g0, %o3, %y
        sra 	%o5, 0x1f, %g2
        and  	%o3, %g2, %g2
        andcc	%g1, 0, %g1

	mulscc  %g1, %o5, %g1
	mulscc  %g1, %o5, %g1
	mulscc  %g1, %o5, %g1
	mulscc  %g1, %o5, %g1
		
	!================================
	! Exit
	!================================
exit:		
        mov	0,%o0			! exit value
        mov	SYSCALL_EXIT,%g1        ! put the exit syscall number in g1
        ta      0x10			! and exit
#1 lore raw
Quoted 14 lines · Vince Weaver

Hello

I'm continuing on my quest to get the SPEC2000 benchmarks running under
sparc32-linux-user (so far 8 out of 48 work).

Many of the benchmarks die early on with the following error:

    /fusion/research4/vince/qemu/svn/tcg/tcg.c:1455: tcg

fatal error

This error is caused when tcg_reg_alloc_mov() is called but ts->val_type is equal to 0 (which is TEMP_VAL_DEAD). So maybe the optimizer is
optimizing away something that it shouldn't?

Quoted 6 lines

This happens in a block with multiple calls to the SPARC "mulscc" instruction which is a complicated instruction, so maybe this is finding an
obscure corner case.

I've attached a very small sample program that exhibits the bug when run
with ./sparc32-linux-user/qemu-sparc32plus

Okay, I can finally reproduce this. Strangely it does not occur if -d flag is used and "op" is one of the log items. I have to check if older reports where I could not reproduce the bug were suffering from the same problem.

But I haven't found any fix yet.

#2 lore raw
Quoted 23 lines · Blue Swirl
Quoted 14 lines · Vince Weaver

Hello

I'm continuing on my quest to get the SPEC2000 benchmarks running under
sparc32-linux-user (so far 8 out of 48 work).

Many of the benchmarks die early on with the following error:

    /fusion/research4/vince/qemu/svn/tcg/tcg.c:1455: tcg

fatal error

This error is caused when tcg_reg_alloc_mov() is called but ts->val_type is equal to 0 (which is TEMP_VAL_DEAD). So maybe the optimizer is
optimizing away something that it shouldn't?

Quoted 6 lines

This happens in a block with multiple calls to the SPARC "mulscc" instruction which is a complicated instruction, so maybe this is finding an
obscure corner case.

I've attached a very small sample program that exhibits the bug when run
with ./sparc32-linux-user/qemu-sparc32plus

Quoted 6 lines

Okay, I can finally reproduce this. Strangely it does not occur if -d
flag is used and "op" is one of the log items. I have to check if older reports where I could not reproduce the bug were suffering from the same problem.

But I haven't found any fix yet.

I have isolated the problem to andi op. The attached patch makes the bug go away by disabling the offending andi, but it's of course not a real fix. Why andi fails with op flag enabled, I have no idea.

target-sparc/translate.c +7 -7
Index: qemu/target-sparc/translate.c
===================================================================
@@ -280,7 +280,9 @@
 {
     tcg_gen_extu_i32_tl(reg, src);
     tcg_gen_shri_tl(reg, reg, PSR_OVF_SHIFT);
+#if 0
     tcg_gen_andi_tl(reg, reg, 0x1);
+#endif
 }
 
 static inline void gen_mov_reg_C(TCGv reg, TCGv src)
@@ -717,24 +719,22 @@
     int l1;
 
     l1 = gen_new_label();
-    r_temp = tcg_temp_new(TCG_TYPE_TL);
-    r_temp2 = tcg_temp_new(TCG_TYPE_I32);
 
     /* old op:
     if (!(env->y & 1))
         T1 = 0;
     */
     tcg_gen_mov_tl(cpu_cc_src, src1);
-    tcg_gen_ld32u_tl(r_temp, cpu_env, offsetof(CPUSPARCState, y));
-    tcg_gen_trunc_tl_i32(r_temp2, r_temp);
-    tcg_gen_andi_i32(r_temp2, r_temp2, 0x1);
+    tcg_gen_ld_i32(cpu_tmp32, cpu_env, offsetof(CPUSPARCState, y));
+    tcg_gen_andi_i32(cpu_tmp32, cpu_tmp32, 0x1);
     tcg_gen_mov_tl(cpu_cc_src2, src2);
-    tcg_gen_brcondi_i32(TCG_COND_NE, r_temp2, 0, l1);
+    tcg_gen_brcondi_i32(TCG_COND_NE, cpu_tmp32, 0, l1);
     tcg_gen_movi_tl(cpu_cc_src2, 0);
     gen_set_label(l1);
 
     // b2 = T0 & 1;
     // env->y = (b2 << 31) | (env->y >> 1);
+    r_temp2 = tcg_temp_new(TCG_TYPE_I32);
     tcg_gen_trunc_tl_i32(r_temp2, cpu_cc_src);
     tcg_gen_andi_i32(r_temp2, r_temp2, 0x1);
     tcg_gen_shli_i32(r_temp2, r_temp2, 31);
@@ -746,10 +746,10 @@
 
     // b1 = N ^ V;
     gen_mov_reg_N(cpu_tmp0, cpu_psr);
+    r_temp = tcg_temp_new(TCG_TYPE_TL);
     gen_mov_reg_V(r_temp, cpu_psr);
     tcg_gen_xor_tl(cpu_tmp0, cpu_tmp0, r_temp);
     tcg_temp_free(r_temp);
-
     // T0 = (b1 << 31) | (T0 >> 1);
     // src1 = T0;
     tcg_gen_shli_tl(cpu_tmp0, cpu_tmp0, 31);