On 9/25/20 1:51 AM, Frank Chang wrote: > trans_vsetvli() uses gen_goto_tb() to save the computation in the link to the > next TB. > I know there was a discussion about this back in RVV v0.7.1: > https://patchew.org/QEMU/20200103033347.20909-1-zhiwei_...@c-sky.com/20200103033347.20909-5-zhiwei_...@c-sky.com/ > > However, we had encountered an issue that looked like it was caused by the > linked TB. > The code snippet which cause the issue is: > > 00000000000104a8 <loop>: 104a8: 0122ffd7 vsetvli t6,t0,e32,m4,tu,mu,d1 104ac: > 02036407 vle32.v v8,(t1) 104b0: 028a0a57 vadd.vv v20,v8,v20 104b4: 41f282b3 > sub > t0,t0,t6 104b8: 002f9893 slli a7,t6,0x2 104bc: 9346 add t1,t1,a7 104be: > fe0295e3 bnez t0,104a8 <loop> 104c2: 012f7057 vsetvli zero,t5,e32,m4,tu,mu,d1 > ..... > > If $t0 is given with the value, e.g. 68. > <loop> is expected to process 32 elements in each iteration. > That's it, the env->vl after vsetvli at 0x104a8 in each iteration would be: > 1st iteration: 32 (remaining elements to be processed: 68 - 32 = 36) > 2nd iteration: 32 (remaining elements to be processed: 36 - 32 = 4) > 3rd iteration: 4 (remaining elements to be processed: 4 - 4 = 0, will leave > <loop> after 0x104be) > > vadd.vv at 0x104b0 is implemented with gvec for acceleration: > > if (a->vm && s->vl_eq_vlmax) { > gvec_fn(s->sew, vreg_ofs(s, a->rd), > vreg_ofs(s, a->rs2), vreg_ofs(s, a->rs1), > MAXSZ(s), MAXSZ(s)); > } else { > uint32_t data = 0; > > data = FIELD_DP32(data, VDATA, VM, a->vm); > data = FIELD_DP32(data, VDATA, LMUL, s->lmul); > tcg_gen_gvec_4_ptr(vreg_ofs(s, a->rd), vreg_ofs(s, 0), > vreg_ofs(s, a->rs1), vreg_ofs(s, a->rs2), > cpu_env, 0, s->vlen / 8, data, fn); > } > > gvec function is used when a->vm and s->vl_eq_vlmax are both true. > However, s->vl_eq_vlmax, for the above case, is only true in 1st and 2nd > iterations. > In third iteration, env->vl is 4 which is not equal to vlmax = 32. > But as the TB where vadd.vv resides are already linked with vsetvli's TB, > it won't be retranslated and still use the same gvec function in the third > iteration. > The total elemented being proceeded would be: 32 + 32 + 32 = 96, instead of > 68. > > I'm wondering under such conditions, is it still correct to use gen_goto_tb() > here? > Or we should use lookup_and_goto_ptr() as in trans_vsetvl() to not link the > TBs.
You're correct -- because of vl_eq_vlmax we can't use goto_tb when using a variable input. It would be possible when using xN,x0 for VLMAX, or x0,x0 for reuse of the current vl, but I doubt it's worth special-casing that. I wonder if the goto_tb conversation happened before we introduced vl_eq_vlmax and forgot to re-evaluate, or if I just missed that in the first place. Anyway, thanks for finding this. r~