[llvm] r224010 - [X86] When converting movs to pushes, don't assume MOVmi operand is an actual immediate

Michael Kuperstein michael.m.kuperstein at intel.com
Thu Dec 11 03:26:17 PST 2014


Author: mkuper
Date: Thu Dec 11 05:26:16 2014
New Revision: 224010

URL: http://llvm.org/viewvc/llvm-project?rev=224010&view=rev
Log:
[X86] When converting movs to pushes, don't assume MOVmi operand is an actual immediate

This should fix PR21878.

Modified:
    llvm/trunk/lib/Target/X86/X86FrameLowering.cpp
    llvm/trunk/test/CodeGen/X86/movtopush.ll

Modified: llvm/trunk/lib/Target/X86/X86FrameLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86FrameLowering.cpp?rev=224010&r1=224009&r2=224010&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86FrameLowering.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86FrameLowering.cpp Thu Dec 11 05:26:16 2014
@@ -93,13 +93,14 @@ static unsigned getANDriOpcode(bool IsLP
   return X86::AND32ri;
 }
 
-static unsigned getPUSHiOpcode(bool IsLP64, int64_t Imm) {
+static unsigned getPUSHiOpcode(bool IsLP64, MachineOperand MO) {
   // We don't support LP64 for now.
   assert(!IsLP64);
 
-  if (isInt<8>(Imm))
+  if (MO.isImm() && isInt<8>(MO.getImm()))
     return X86::PUSH32i8;
-  return X86::PUSHi32;
+
+  return X86::PUSHi32;;
 }
 
 static unsigned getLEArOpcode(unsigned IsLP64) {
@@ -1892,14 +1893,13 @@ convertArgMovsToPushes(MachineFunction &
   for (auto MMI = MovMap.rbegin(), MME = MovMap.rend(); MMI != MME; ++MMI) {
     MachineBasicBlock::iterator MOV = MMI->second;
     MachineOperand PushOp = MOV->getOperand(X86::AddrNumOperands);
-    if (MOV->getOpcode() == X86::MOV32mi) {
-      int64_t Val = PushOp.getImm();
-      BuildMI(MBB, Call, DL, TII.get(getPUSHiOpcode(false, Val)))
-        .addImm(Val);
-    } else {
-      BuildMI(MBB, Call, DL, TII.get(X86::PUSH32r))
-        .addReg(PushOp.getReg());
-    }
+
+    // Replace MOVmr with PUSH32r, and MOVmi with PUSHi of appropriate size
+    int PushOpcode = X86::PUSH32r;
+    if (MOV->getOpcode() == X86::MOV32mi)
+      PushOpcode = getPUSHiOpcode(false, PushOp);
+
+    BuildMI(MBB, Call, DL, TII.get(PushOpcode)).addOperand(PushOp);
     MBB.erase(MOV);
   }
 

Modified: llvm/trunk/test/CodeGen/X86/movtopush.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/movtopush.ll?rev=224010&r1=224009&r2=224010&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/movtopush.ll (original)
+++ llvm/trunk/test/CodeGen/X86/movtopush.ll Thu Dec 11 05:26:16 2014
@@ -94,4 +94,19 @@ entry:
   ret void
 }
 
+; Check that pushing the addresses of globals (Or generally, things that 
+; aren't exactly immediates) isn't broken.
+; Fixes PR21878.
+; NORMAL-LABEL: test6
+; NORMAL: pushl    $_ext
+; NORMAL-NEXT: call
+declare void @f(i8*)
+ at ext = external constant i8
 
+define void @test6() {
+  call void @f(i8* @ext)
+  br label %bb
+bb:
+  alloca i32
+  ret void
+}
\ No newline at end of file





More information about the llvm-commits mailing list