From 67d80d414b5d1e9b8cad34ce56f984c6c51de00d Mon Sep 17 00:00:00 2001
From: florian <florian@freepascal.org>
Date: Thu, 10 Feb 2022 22:42:10 +0100
Subject: [PATCH]   * do not copy parameters onto the stack using FPU registers
 if the type is     actually handled by the MM unit, resolves #39567

---
 compiler/hlcg2ll.pas | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/compiler/hlcg2ll.pas b/compiler/hlcg2ll.pas
index dacd1e847d..d8b0eef8e6 100644
--- a/compiler/hlcg2ll.pas
+++ b/compiler/hlcg2ll.pas
@@ -1492,10 +1492,14 @@ implementation
             LOC_CMMREGISTER:
               cg.a_loadmm_ref_cgpara(list,locsize,l.reference,cgpara,mms_movescalar);
             { Some targets pass floats in normal registers }
+            LOC_REFERENCE,
+            LOC_CREFERENCE:
+              if use_vectorfpu(size) then
+                cg.a_loadmm_ref_cgpara(list,locsize,l.reference,cgpara,mms_movescalar)
+              else
+                cg.a_loadfpu_ref_cgpara(list,locsize,l.reference,cgpara);
             LOC_REGISTER,
             LOC_CREGISTER,
-            LOC_REFERENCE,
-            LOC_CREFERENCE,
             LOC_FPUREGISTER,
             LOC_CFPUREGISTER:
               cg.a_loadfpu_ref_cgpara(list,locsize,l.reference,cgpara);