[PATCH] D105271: [PowerPC][ELF]make sure local variable space does not overlap with parameter save area

ChenZheng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 8 01:05:45 PDT 2021


shchenz updated this revision to Diff 357154.
shchenz added a comment.

1: the unexpected size is caused by: there is a minimal parameter save area requirement which is 64 bytes. It is bigger than the needed 36 bytes.

2: Because the parameter size is 36 bytes, it can be passed by registers, so current `CalculateStackSlotUsed` return false. But because the byval parameter may be assumed in caller's parameter save area in the callee in other compiler, so we must also store the byval parameter in parameter save area of the caller function. Maybe we need a revisit for this case. For my understanding, there is no need to store byval parameter in the parameter save area in the caller site if the parameters can be passed in registers. Callee site should copy the byval parameter to its own stack memory, so any operation will not impact the caller site. Not sure which gcc version requires this and from the later comments, seems this is not implemented? But this should be another improvement issue from this functionality one.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105271/new/

https://reviews.llvm.org/D105271

Files:
  llvm/lib/Target/PowerPC/PPCISelLowering.cpp
  llvm/test/CodeGen/PowerPC/byval.ll


Index: llvm/test/CodeGen/PowerPC/byval.ll
===================================================================
--- llvm/test/CodeGen/PowerPC/byval.ll
+++ llvm/test/CodeGen/PowerPC/byval.ll
@@ -1,4 +1,3 @@
-; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
 ; RUN: llc -verify-machineinstrs < %s | FileCheck %s
 
 target datalayout = "e-m:e-i64:64-n32:64-S128-v256:256:256-v512:512:512"
@@ -9,15 +8,15 @@
 declare dso_local i32 @foo1(%struct* byval(%struct) %var)
 declare dso_local void @foo(%struct* %var)
 
-; FIXME: for the byval parameter %x, now the memory for local variable and
-; for parameter save area are overlap.
+; for the byval parameter %x, make sure the memory for local variable and
+; for parameter save area are not overlap.
 ; For the below case,
-; the local variable space is r1 + 40 ~ r1 + 76
+; the local variable space is r1 + 104 ~ r1 + 140
 ; the parameter save area is r1 + 32 ~ r1 + 68
 
 define dso_local i32 @bar() {
 ; CHECK-LABEL: bar:
-; CHECK:    addi 30, 1, 40
+; CHECK:    addi 30, 1, 104
 ; CHECK:    li 3, 16
 ; CHECK:    lxvd2x 0, 30, 3
 ; CHECK:    li 3, 48
@@ -25,7 +24,7 @@
 ; CHECK:    li 3, 32
 ; CHECK:    lxvd2x 0, 0, 30
 ; CHECK:    stxvd2x 0, 1, 3
-; CHECK:    lwz 3, 72(1)
+; CHECK:    lwz 3, 136(1)
 ; CHECK:    stw 3, 64(1)
 entry:
   %x = alloca %struct, align 4
Index: llvm/lib/Target/PowerPC/PPCISelLowering.cpp
===================================================================
--- llvm/lib/Target/PowerPC/PPCISelLowering.cpp
+++ llvm/lib/Target/PowerPC/PPCISelLowering.cpp
@@ -3912,7 +3912,10 @@
         --AvailableVRs;
         return false;
       }
-  }
+  } else if (Flags.getByValSize() >= 8)
+    // For 64-bit ELF v2, passing by value object whose size is no less than 8
+    // bytes will be copied to parameter save area.
+    return true;
 
   return UseMemory;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105271.357154.patch
Type: text/x-patch
Size: 1861 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210708/a9328a20/attachment.bin>


More information about the llvm-commits mailing list