Unwanted local variable stored in VFP register

Asked by jdobry on 2020-06-30


we are found that GCC >= 9 use VFP registers to store local function variables instead stack. It looks as smart idea, because access to VFP register is faster than access to stack, but there are one serious problem. We need to disable this optimization and we don't know, how to do it.
Problem is simple. We have MCU with VFP unit and real-time operating system. Problem is that save/restore complete VFP unit state on every context switch is very time expensive (33 DWORDs on stack). And most of processes don't need VFP operations. Therefore we are enable/disable VFP unit depending to proccess setting. In another word we need to have VFP operations only on functions where are float point operations.

And GCC9 produce code like this for ANY more complex function:

    stmdb sp!, {r4, r5, r6, r7, r8, r9, sl, fp, lr}
    vpush {d8}
    ... do something
   vmov s16, r3 ; store local varible to VFP register temporary
    ... do something
  vmov r1, s16 ; restore local varible from temporary VFP register
    ... do something
   vpop {d8}
   ldmia.w sp!, {r4, r5, r6, r7, r8, r9, sl, fp, pc}

Code like this must throw Undefined Instruction exception, because VFP unit is disabled.
We can compile some object files with VFP support and some without, but it is not solution because it is not compatible with LTO (linker must be VFP-enabled and linker do this optimization and function preamble/postamble)

How to manage(block) this optimization?

Jiri Dobry

Question information

English Edit question
GNU Arm Embedded Toolchain Edit question
No assignee Edit question
Solved by:
Last query:
Last reply:
Revision history for this message
jdobry (jdobry) said :