[PATCH] D104440: [X86] Fix bug when X86 stackify pass handle one ArgFPRW.

LuoYuanke via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 18 05:51:43 PDT 2021


LuoYuanke updated this revision to Diff 352986.
LuoYuanke added a comment.

Address Craig's comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104440

Files:
  llvm/lib/Target/X86/X86FloatingPoint.cpp
  llvm/test/CodeGen/X86/fpstack-call.mir


Index: llvm/test/CodeGen/X86/fpstack-call.mir
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/X86/fpstack-call.mir
@@ -0,0 +1,53 @@
+# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
+# RUN: llc -mtriple=x86_64-- -run-pass x86-codegen -verify-machineinstrs -mcpu=x86-64 -o - %s | FileCheck %s
+
+--- |
+   @x = dso_local global i32 0, align 4
+   define void @fpstack-empty() { ret void }
+   declare void @foo()
+...
+---
+
+name: fpstack-empty
+tracksRegLiveness: true
+registers:       []
+liveins:
+  - { reg: '$r14', virtual-reg: '' }
+stack:
+  - { id: 0, name: '', type: default, offset: 0, size: 8, alignment: 8,
+      stack-id: default, callee-saved-register: '', callee-saved-restored: true,
+      debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
+  - { id: 1, name: '', type: default, offset: 0, size: 8, alignment: 8,
+      stack-id: default, callee-saved-register: '', callee-saved-restored: true,
+      debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
+body: |
+  bb.0 (%ir-block.0):
+    liveins: $r14
+    ; CHECK-LABEL: name: fpstack-empty
+    ; CHECK: liveins: $r14
+    ; CHECK: ST_FPrr $st0, implicit-def $fpsw, implicit $fpcw
+    ; CHECK: renamable $rdi = MOV64ri @x
+    ; CHECK: renamable $rdx = LEA64r %stack.0, 1, $noreg, 0, $noreg
+    ; CHECK: ADJCALLSTACKDOWN64 0, 0, 0, implicit-def $rsp, implicit-def dead $eflags, implicit-def $ssp, implicit $rsp, implicit $ssp
+    ; CHECK: dead $esi = MOV32r0 implicit-def dead $eflags, implicit-def $rsi
+    ; CHECK: CALL64pcrel32 @foo, implicit $rsp, implicit $ssp, implicit $rdi, implicit $rsi, implicit $rdx
+    ; CHECK: ST_FPrr $st0, implicit-def $fpsw, implicit $fpcw
+    ; CHECK: renamable $xmm0 = MOVSDrm_alt %stack.1, 1, $noreg, 0, $noreg :: (load 8 from %stack.1)
+    ; CHECK: ADJCALLSTACKUP64 0, 0, implicit-def $rsp, implicit-def dead $eflags, implicit-def $ssp, implicit $rsp, implicit $ssp
+    ; CHECK: LD_F0 implicit-def $fpsw, implicit $fpcw
+    ; CHECK: CHS_F implicit-def $fpsw
+    ; CHECK: ST_FPrr $st0, implicit-def $fpsw, implicit $fpcw
+    ; CHECK: RETQ
+    ST_FPrr $st0, implicit-def $fpsw, implicit $fpcw
+    renamable $rdi = MOV64ri @x
+    renamable $rdx = LEA64r %stack.0, 1, $noreg, 0, $noreg
+    ADJCALLSTACKDOWN64 0, 0, 0, implicit-def $rsp, implicit-def dead $eflags, implicit-def $ssp, implicit $rsp, implicit $ssp
+    dead $esi = MOV32r0 implicit-def dead $eflags, implicit-def $rsi
+    CALL64pcrel32 @foo, implicit $rsp, implicit $ssp, implicit $rdi, implicit $rsi, implicit $rdx, implicit-def dead $fp0
+    renamable $xmm0 = MOVSDrm_alt %stack.1, 1, $noreg, 0, $noreg :: (load 8 from %stack.1)
+    ADJCALLSTACKUP64 0, 0, implicit-def $rsp, implicit-def dead $eflags, implicit-def $ssp, implicit $rsp, implicit $ssp
+    renamable $fp2 = CHS_Fp80 killed undef renamable $fp0, implicit-def $fpsw
+
+    RETQ
+...
+---
Index: llvm/lib/Target/X86/X86FloatingPoint.cpp
===================================================================
--- llvm/lib/Target/X86/X86FloatingPoint.cpp
+++ llvm/lib/Target/X86/X86FloatingPoint.cpp
@@ -1190,9 +1190,18 @@
   if (KillsSrc) {
     // If this is the last use of the source register, just make sure it's on
     // the top of the stack.
-    moveToTop(Reg, I);
-    if (StackTop == 0)
-      report_fatal_error("Stack cannot be empty!");
+    if (StackTop == 0) {
+      // If the stack is empty and the input is undefined fp register,
+      // insert fld0.
+      if (MI.getOperand(1).isUndef()) {
+        LLVM_DEBUG(dbgs() << "Emitting LD_F0 for undefined FP" << Reg << '\n');
+        BuildMI(*MBB, I, MI.getDebugLoc(), TII->get(X86::LD_F0));
+        pushReg(Reg);
+      } else
+        report_fatal_error("Stack cannot be empty!");
+    } else
+      moveToTop(Reg, I);
+
     --StackTop;
     pushReg(getFPReg(MI.getOperand(0)));
   } else {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104440.352986.patch
Type: text/x-patch
Size: 3952 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210618/c6681cce/attachment.bin>


More information about the llvm-commits mailing list