]> granicus.if.org Git - llvm/commitdiff
X86FrameLowering: Check subregs when deciding prolog kill flags
authorMatthias Braun <matze@braunis.de>
Tue, 28 Jun 2016 20:31:56 +0000 (20:31 +0000)
committerMatthias Braun <matze@braunis.de>
Tue, 28 Jun 2016 20:31:56 +0000 (20:31 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@274057 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/X86/X86FrameLowering.cpp
test/CodeGen/X86/no-prolog-kill.ll [new file with mode: 0644]

index ab219f680ba5494b9e22c75ed1aed1add25c29c5..10a15e1a3754eaeeba3dfdb7ac35775d754756e1 100644 (file)
@@ -1893,17 +1893,29 @@ bool X86FrameLowering::spillCalleeSavedRegisters(
     if (!X86::GR64RegClass.contains(Reg) && !X86::GR32RegClass.contains(Reg))
       continue;
 
-    bool isLiveIn = MF.getRegInfo().isLiveIn(Reg);
+    const MachineRegisterInfo &MRI = MF.getRegInfo();
+    bool isLiveIn = MRI.isLiveIn(Reg);
     if (!isLiveIn)
       MBB.addLiveIn(Reg);
 
+    // Decide whether we can add a kill flag to the use.
+    bool CanKill = !isLiveIn;
+    // Check if any subregister is live-in
+    if (CanKill) {
+      for (MCRegAliasIterator AReg(Reg, TRI, false); AReg.isValid(); ++AReg) {
+        if (MRI.isLiveIn(*AReg)) {
+          CanKill = false;
+          break;
+        }
+      }
+    }
+
     // Do not set a kill flag on values that are also marked as live-in. This
     // happens with the @llvm-returnaddress intrinsic and with arguments
     // passed in callee saved registers.
     // Omitting the kill flags is conservatively correct even if the live-in
     // is not used after all.
-    bool isKill = !isLiveIn;
-    BuildMI(MBB, MI, DL, TII.get(Opc)).addReg(Reg, getKillRegState(isKill))
+    BuildMI(MBB, MI, DL, TII.get(Opc)).addReg(Reg, getKillRegState(CanKill))
       .setMIFlag(MachineInstr::FrameSetup);
   }
 
diff --git a/test/CodeGen/X86/no-prolog-kill.ll b/test/CodeGen/X86/no-prolog-kill.ll
new file mode 100644 (file)
index 0000000..f625f31
--- /dev/null
@@ -0,0 +1,21 @@
+; RUN: llc -verify-machineinstrs -o - %s | FileCheck %s
+target triple = "x86_64--"
+
+; This function gets a AL live-in and at same time saves+restores RAX. We must
+; not add a kill flag to the "PUSHQ %rax" or the machine verifier will complain.
+; CHECK-LABEL: test:
+; CHECK: pushq %rax
+; CHECK: testb %al, %al
+; CHECK: je .LBB
+define void @test(i64 %a, i8* %b, ...)  {
+entry:
+  %bar = alloca i8
+  call void @llvm.va_start(i8* %bar)
+  call void @llvm.eh.unwind.init()
+  call void @llvm.eh.return.i64(i64 %a, i8* %b)
+  unreachable
+}
+
+declare void @llvm.eh.return.i64(i64, i8*)
+declare void @llvm.eh.unwind.init()
+declare void @llvm.va_start(i8*)