================
@@ -1478,15 +1478,32 @@ void RISCVFrameLowering::emitZeroCallUsedRegs(BitVector
RegsToZero,
BitVector FinalRegsToZero(TRI.getNumRegs());
+ bool HasVRegister = false;
+
for (MCRegister Reg : RegsToZero.set_bits()) {
if (TRI.isGeneralPurposeRegister(MF, Reg)) {
FinalRegsToZero.set(Reg.id());
} else if (TRI.isFPRegister(Reg)) {
if (MCRegister MaybeReg = getLargestFPRegisterOrZero(STI, TRI, Reg))
FinalRegsToZero.set(MaybeReg.id());
+ } else if (RISCV::VRRegClass.contains(Reg)) {
+ if (!STI.hasStdExtV())
+ continue;
+ HasVRegister = true;
+ FinalRegsToZero.set(Reg.id());
}
}
+ if (HasVRegister) {
+ RISCVVType::VLMUL VLMUL = RISCVVType::encodeLMUL(1, /*Fractional=*/false);
+ unsigned VTypeImm = RISCVVType::encodeVTYPE(
+ VLMUL, /*SEW=*/32, /*TailAgnostic=*/false, /*MaskAgnostic=*/false);
+
+ BuildMI(MBB, MBBI, DL, TII.get(RISCV::VSETVLI), RISCV::X5)
+ .addReg(RISCV::X0)
+ .addImm(VTypeImm);
+ }
+
----------------
LucasChollet wrote:
I think that unconditionally emitting a `VSETVLI` here is the simplest way to
perform the cleaning. The added `VSETVLI` is potentially useless, but that's
probably rare enough that it shouldn't matter in practice.
Also, I always use `t0` as the output of `VSETVLI`, but I don't know exactly if
that's correct.
With `-fzero-call-used-regs`, GCC uses `t0` too. Otherwise, GCC reuses one
already dirty register (usually `a0` or `a1`), and as GCC don't use V registers
for arguments, it always has a dirty register handy. [1]
I'm still asking for your opinion on the subject, but I think I made my mind
while writing this comment.
Should we always use `t0`, and do we care if it's not cleared afterward?
If, as I think, the answer is yes, the strategy will be to:
1. find a GPR candidate in `FinalRegsToZero`
2. If found, use it
3. Otherwise, use `t0` and set `t0` to be cleared.
---
[1] While writing this, I found a way to get GCC to have used V registers
without having any used GPR, and it results in an ICE 😅
[gobolt
link](https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:14,fontUsePx:'0',j:1,lang:c%2B%2B,selection:(endColumn:1,endLineNumber:13,positionColumn:1,positionLineNumber:13,selectionStartColumn:1,selectionStartLineNumber:13,startColumn:1,startLineNumber:13),source:'%23include+%3Criscv_vector.h%3E%0A%0Astatic+float*+v1%3B%0Astatic+float*+v2%3B%0A%0A%0Afloat+sum_reduce()+%7B%0A++++size_t+vl+%3D+4%3B%0A++++vfloat32m1_t+a+%3D+__riscv_vle32_v_f32m1(v1,+vl)%3B%0A++++vfloat32m1_t+b+%3D+__riscv_vle32_v_f32m1(v2,+vl)%3B%0A++++vfloat32m1_t+sum1+%3D+__riscv_vfadd_vv_f32m1(a,+b,+vl)%3B%0A++++return+__riscv_vfmv_f_s_f32m1_f32(sum1)%3B%0A%7D%0A'),l:'5',n:'0',o:'C%2B%2B+source+%231',t:'0')),k:50,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((g:!((h:compiler,i:(compiler:rv64-gcctrunk,filters:(b:'0',binary:'1',binaryObject:'1',commentOnly:'0',debugCalls:'1',demangle:'0',directives:'0',execute:'1',intel:'0',libraryCode:'0',trim:'1',verboseDemangling:'0'),flagsViewOpen:'1',fontScale:14,fontUsePx:'0',j:1,lang:c%2B%2B,libs:!(),options:'-O2+-march%3D%22rv64gv%22',overrides:!(),selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:1),l:'5',n:'0',o:'+RISC-V+(64-bits)+gcc+(trunk)+(Editor+%231)',t:'0')),header:(),k:50,l:'4',m:29.30853485321027,n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:rv64-gcctrunk,filters:(b:'0',binary:'1',binaryObject:'1',commentOnly:'0',debugCalls:'1',demangle:'0',directives:'0',execute:'1',intel:'0',libraryCode:'0',trim:'1',verboseDemangling:'0'),flagsViewOpen:'1',fontScale:14,fontUsePx:'0',j:2,lang:c%2B%2B,libs:!(),options:'-O2+-march%3D%22rv64gv%22+-fzero-call-used-regs%3Dused',overrides:!(),selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:1),l:'5',n:'0',o:'+RISC-V+(64-bits)+gcc+(trunk)+(Editor+%231)',t:'0')),header:(),l:'4',m:28.57055016266181,n:'0',o:'',s:0,t:'0'),(g:!((h:output,i:(compilerName:'RISC-V+(64-bits)+gcc+(trunk)',editorid:1,fontScale:14,fontUsePx:'0',j:2,wrap:'1'),l:'5',n:'0',o:'Output+of+RISC-V+(64-bits)+gcc+(trunk)+(Compiler+%232)',t:'0')),l:'4',m:42.12091498412792,n:'0',o:'',s:0,t:'0')),k:50,l:'3',n:'0',o:'',t:'0')),l:'2',n:'0',o:'',t:'0')),version:4)
https://github.com/llvm/llvm-project/pull/206206
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits