[PATCH] D17542: Disallow generating vzeroupper before return instruction (iret) in interrupt handler function
Amjad Aboud via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 23 06:27:30 PST 2016
aaboud created this revision.
aaboud added reviewers: DavidKreitzer, hjl.tools, nadav.
aaboud added a subscriber: llvm-commits.
Resolved Bug 26412.
https://llvm.org/bugs/show_bug.cgi?id=26412
http://reviews.llvm.org/D17542
Files:
lib/Target/X86/X86VZeroUpper.cpp
test/CodeGen/X86/x86-interrupt_vzeroupper.ll
Index: lib/Target/X86/X86VZeroUpper.cpp
===================================================================
--- lib/Target/X86/X86VZeroUpper.cpp
+++ lib/Target/X86/X86VZeroUpper.cpp
@@ -80,6 +80,7 @@
BlockStateMap BlockStates;
DirtySuccessorsWorkList DirtySuccessors;
bool EverMadeChange;
+ bool IsX86INTR;
const TargetInstrInfo *TII;
static char ID;
@@ -181,7 +182,11 @@
for (MachineBasicBlock::iterator I = MBB.begin(); I != MBB.end(); ++I) {
MachineInstr *MI = I;
- bool isControlFlow = MI->isCall() || MI->isReturn();
+ bool isControlFlow = MI->isCall() ||
+ // No need for vzeroupper before iret in interrupt
+ // handler function, epilogue will restore YMM
+ // registers if needed.
+ (MI->isReturn() && !IsX86INTR);
// Shortcut: don't need to check regular instructions in dirty state.
if (!isControlFlow && CurState == EXITS_DIRTY)
@@ -253,6 +258,7 @@
TII = ST.getInstrInfo();
MachineRegisterInfo &MRI = MF.getRegInfo();
EverMadeChange = false;
+ IsX86INTR = MF.getFunction()->getCallingConv() == CallingConv::X86_INTR;
bool FnHasLiveInYmm = checkFnHasLiveInYmm(MRI);
Index: test/CodeGen/X86/x86-interrupt_vzeroupper.ll
===================================================================
--- test/CodeGen/X86/x86-interrupt_vzeroupper.ll
+++ test/CodeGen/X86/x86-interrupt_vzeroupper.ll
@@ -0,0 +1,41 @@
+; RUN: llc -mtriple=x86_64-unknown-unknown < %s | FileCheck %s
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Checks that interrupt handler code does not call "vzeroupper" instruction
+;; before iret.
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Command line: -Wall -march=nehalem -S -o - -emit-llvm -O2
+;; Source:
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;extern void foo (void *) __attribute__ ((interrupt));
+;;extern void bar (void);
+;;
+;;void foo (void *frame)
+;;{
+;; bar ();
+;;}
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+; CHECK: vzeroupper
+; CHECK-NEXT: call
+; CHECK-NOT: vzeroupper
+; CHECK: iret
+
+ at llvm.used = appending global [1 x i8*] [i8* bitcast (void (i8*)* @foo to i8*)], section "llvm.metadata"
+
+; Function Attrs: nounwind uwtable
+define x86_intrcc void @foo(i8* nocapture readnone %frame) #0 {
+entry:
+ tail call void @bar() #2
+ ret void
+}
+
+declare void @bar() #1
+
+attributes #0 = { nounwind uwtable "disable-tail-calls"="true" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "stackrealign" "target-cpu"="nehalem" "target-features"="+avx,+cx16,+fxsr,+popcnt,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+xsave,-3dnow,-3dnowa,-mmx" "unsafe-fp-math"="false" "use-soft-float"="true" }
+attributes #1 = { "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="nehalem" "target-features"="+avx,+cx16,+fxsr,+mmx,+popcnt,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+xsave" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #2 = { nounwind }
+
+!llvm.ident = !{!0}
+
+!0 = !{!"clang version 3.9.0 (trunk 259349) (llvm/trunk 259357)"}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D17542.48814.patch
Type: text/x-patch
Size: 3523 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160223/475b27d3/attachment.bin>
More information about the llvm-commits
mailing list