[llvm] r247785 - [X86] Do not generate 64-bit pops of 32-bit GPRs.

Michael Kuperstein via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 16 04:27:21 PDT 2015


Author: mkuper
Date: Wed Sep 16 06:27:20 2015
New Revision: 247785

URL: http://llvm.org/viewvc/llvm-project?rev=247785&view=rev
Log:
[X86] Do not generate 64-bit pops of 32-bit GPRs.

When trying emit a stack adjustments using pops, frame lowering selects an
arbitrary free GPR. It should always select one from an appropriate class...
This fixes PR24649.

Patch by: amjad.aboud at intel.com
Differential Revision: http://reviews.llvm.org/D12609

Modified:
    llvm/trunk/lib/Target/X86/X86FrameLowering.cpp
    llvm/trunk/test/CodeGen/X86/pop-stack-cleanup.ll

Modified: llvm/trunk/lib/Target/X86/X86FrameLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86FrameLowering.cpp?rev=247785&r1=247784&r2=247785&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86FrameLowering.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86FrameLowering.cpp Wed Sep 16 06:27:20 2015
@@ -1935,6 +1935,9 @@ void X86FrameLowering::adjustForHiPEProl
 bool X86FrameLowering::adjustStackWithPops(MachineBasicBlock &MBB,
     MachineBasicBlock::iterator MBBI, DebugLoc DL, int Offset) const {
 
+  if (Offset <= 0)
+    return false;
+
   if (Offset % SlotSize)
     return false;
 
@@ -1955,9 +1958,11 @@ bool X86FrameLowering::adjustStackWithPo
   unsigned FoundRegs = 0;
 
   auto RegMask = Prev->getOperand(1);
-  
-  // Try to find up to NumPops free registers. 
-  for (auto Candidate : X86::GR32_NOREX_NOSPRegClass) {
+
+  auto &RegClass =
+      Is64Bit ? X86::GR64_NOREX_NOSPRegClass : X86::GR32_NOREX_NOSPRegClass;
+  // Try to find up to NumPops free registers.
+  for (auto Candidate : RegClass) {
 
     // Poor man's liveness:
     // Since we're immediately after a call, any register that is clobbered

Modified: llvm/trunk/test/CodeGen/X86/pop-stack-cleanup.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/pop-stack-cleanup.ll?rev=247785&r1=247784&r2=247785&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/pop-stack-cleanup.ll (original)
+++ llvm/trunk/test/CodeGen/X86/pop-stack-cleanup.ll Wed Sep 16 06:27:20 2015
@@ -1,10 +1,13 @@
-; RUN: llc < %s -mtriple=i686-windows | FileCheck %s -check-prefix=CHECK -check-prefix=NORMAL
+; RUN: llc < %s -mtriple=i686-windows | FileCheck %s -check-prefix=CHECK 
+; RUN: llc < %s -mtriple=x86_64-linux | FileCheck %s -check-prefix=LINUX64
 
 declare void @param1(i32 %a)
 declare i32 @param2_ret(i32 %a, i32 %b)
 declare i64 @param2_ret64(i32 %a, i32 %b)
 declare void @param2(i32 %a, i32 %b)
 declare void @param3(i32 %a, i32 %b, i32 %c)
+declare void @param8(i64, i64, i64, i64, i64, i64, i64, i64)
+
 
 define void @test() minsize {
 ; CHECK-LABEL: test:
@@ -59,3 +62,15 @@ define void @spill(i32 inreg %a, i32 inr
   call void @spill(i32 %a, i32 %b, i32 %c)
   ret void
 }
+
+define void @test_linux64(i32 %size) minsize {
+; LINUX64-LABEL: test_linux64:
+; LINUX64: pushq %rbp
+; LINUX64: callq param8
+; LINUX64-NEXT: popq %rax
+; LINUX64-NEXT: popq %rcx
+
+  %a = alloca i64, i32 %size, align 8
+  call void @param8(i64 1, i64 2, i64 3, i64 4, i64 5, i64 6, i64 7, i64 8)
+  ret void
+}




More information about the llvm-commits mailing list