[llvm] r262319 - Disallow generating vzeroupper before return instruction (iret) in interrupt handler function.
Amjad Aboud via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 1 03:32:04 PST 2016
Author: aaboud
Date: Tue Mar 1 05:32:03 2016
New Revision: 262319
URL: http://llvm.org/viewvc/llvm-project?rev=262319&view=rev
Log:
Disallow generating vzeroupper before return instruction (iret) in interrupt handler function.
This resolves https://llvm.org/bugs/show_bug.cgi?id=26412
Differential Revision: http://reviews.llvm.org/D17542
Added:
llvm/trunk/test/CodeGen/X86/x86-interrupt_vzeroupper.ll
Modified:
llvm/trunk/lib/Target/X86/X86VZeroUpper.cpp
Modified: llvm/trunk/lib/Target/X86/X86VZeroUpper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86VZeroUpper.cpp?rev=262319&r1=262318&r2=262319&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86VZeroUpper.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86VZeroUpper.cpp Tue Mar 1 05:32:03 2016
@@ -80,6 +80,7 @@ namespace {
BlockStateMap BlockStates;
DirtySuccessorsWorkList DirtySuccessors;
bool EverMadeChange;
+ bool IsX86INTR;
const TargetInstrInfo *TII;
static char ID;
@@ -181,10 +182,13 @@ void VZeroUpperInserter::processBasicBlo
for (MachineBasicBlock::iterator I = MBB.begin(); I != MBB.end(); ++I) {
MachineInstr *MI = I;
- bool isControlFlow = MI->isCall() || MI->isReturn();
+ // No need for vzeroupper before iret in interrupt handler function,
+ // epilogue will restore YMM registers if needed.
+ bool IsReturnFromX86INTR = IsX86INTR && MI->isReturn();
+ bool IsControlFlow = MI->isCall() || MI->isReturn();
// Shortcut: don't need to check regular instructions in dirty state.
- if (!isControlFlow && CurState == EXITS_DIRTY)
+ if ((!IsControlFlow || IsReturnFromX86INTR) && CurState == EXITS_DIRTY)
continue;
if (hasYmmReg(MI)) {
@@ -196,7 +200,7 @@ void VZeroUpperInserter::processBasicBlo
// Check for control-flow out of the current function (which might
// indirectly execute SSE instructions).
- if (!isControlFlow)
+ if (!IsControlFlow || IsReturnFromX86INTR)
continue;
// If the call won't clobber any YMM register, skip it as well. It usually
@@ -253,6 +257,7 @@ bool VZeroUpperInserter::runOnMachineFun
TII = ST.getInstrInfo();
MachineRegisterInfo &MRI = MF.getRegInfo();
EverMadeChange = false;
+ IsX86INTR = MF.getFunction()->getCallingConv() == CallingConv::X86_INTR;
bool FnHasLiveInYmm = checkFnHasLiveInYmm(MRI);
Added: llvm/trunk/test/CodeGen/X86/x86-interrupt_vzeroupper.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/x86-interrupt_vzeroupper.ll?rev=262319&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/x86-interrupt_vzeroupper.ll (added)
+++ llvm/trunk/test/CodeGen/X86/x86-interrupt_vzeroupper.ll Tue Mar 1 05:32:03 2016
@@ -0,0 +1,19 @@
+; RUN: llc -mtriple=x86_64-unknown-unknown -mattr=+avx < %s | FileCheck %s
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Checks that interrupt handler code does not call "vzeroupper" instruction
+;; before iret.
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+; CHECK: vzeroupper
+; CHECK-NEXT: call
+; CHECK-NOT: vzeroupper
+; CHECK: iret
+
+define x86_intrcc void @foo(i8* %frame) {
+ call void @bar()
+ ret void
+}
+
+declare void @bar()
+
More information about the llvm-commits
mailing list