<html><head><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Okay.<div><br></div><div>-bw</div><div><br><div style=""><div>On Dec 4, 2013, at 12:39 PM, Dmitry Babokin <<a href="mailto:babokin@gmail.com">babokin@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr">Bill,<div><br></div><div>To be precise r196261+r196391 need to back ported.</div><div><br></div><div>Thanks in advance!</div><div><br></div><div>Dmitry.</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Wed, Dec 4, 2013 at 4:10 PM, Dmitry Babokin <span dir="ltr"><<a href="mailto:babokin@gmail.com" target="_blank">babokin@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">Bill,<div><br></div><div>Could you please consider merging this patch to 3.4? The patch seems to be save and at the same time it's quite important, as can cause a lot of pain for users on Window who are compiling for AVX target. If the bug triggers, half of AVX lane is occasionally zeroed, which is nightmare to debug in numerical code, for example.</div>
<span class="HOEnZb"><font color="#888888">
<div><br></div><div>Dmitry.</div></font></span></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Dec 3, 2013 at 1:17 PM, Michael Liao <span dir="ltr"><<a href="mailto:michael.liao@intel.com" target="_blank">michael.liao@intel.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: hliao<br>
Date: Tue Dec 3 03:17:32 2013<br>
New Revision: 196261<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=196261&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=196261&view=rev</a><br>
Log:<br>
Enhance the fix of PR17631<br>
<br>
- The fix to PR17631 fixes part of the cases where 'vzeroupper' should<br>
not be issued before 'call' insn. There're other cases where helper<br>
calls will be inserted not limited to epilog. These helper calls do<br>
not follow the standard calling convention and won't clobber any YMM<br>
registers. (So far, all call conventions will clobber any or part of<br>
YMM registers.)<br>
This patch enhances the previous fix to cover more cases 'vzerosupper' should<br>
not be inserted by checking if that function call won't clobber any YMM<br>
registers and skipping it if so.<br>
<br>
<br>
Modified:<br>
llvm/trunk/lib/Target/X86/X86VZeroUpper.cpp<br>
llvm/trunk/test/CodeGen/X86/pr17631.ll<br>
<br>
Modified: llvm/trunk/lib/Target/X86/X86VZeroUpper.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86VZeroUpper.cpp?rev=196261&r1=196260&r2=196261&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86VZeroUpper.cpp?rev=196261&r1=196260&r2=196261&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Target/X86/X86VZeroUpper.cpp (original)<br>
+++ llvm/trunk/lib/Target/X86/X86VZeroUpper.cpp Tue Dec 3 03:17:32 2013<br>
@@ -148,6 +148,25 @@ static bool hasYmmReg(MachineInstr *MI)<br>
return false;<br>
}<br>
<br>
+/// clobbersAnyYmmReg() - Check if any YMM register will be clobbered by this<br>
+/// instruction.<br>
+static bool clobbersAnyYmmReg(MachineInstr *MI) {<br>
+ for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {<br>
+ const MachineOperand &MO = MI->getOperand(i);<br>
+ if (!MO.isRegMask())<br>
+ continue;<br>
+ for (unsigned reg = X86::YMM0; reg < X86::YMM31; ++reg) {<br>
+ if (MO.clobbersPhysReg(reg))<br>
+ return true;<br>
+ }<br>
+ for (unsigned reg = X86::ZMM0; reg < X86::ZMM31; ++reg) {<br>
+ if (MO.clobbersPhysReg(reg))<br>
+ return true;<br>
+ }<br>
+ }<br>
+ return false;<br>
+}<br>
+<br>
/// runOnMachineFunction - Loop over all of the basic blocks, inserting<br>
/// vzero upper instructions before function calls.<br>
bool VZeroUpperInserter::runOnMachineFunction(MachineFunction &MF) {<br>
@@ -234,14 +253,6 @@ bool VZeroUpperInserter::processBasicBlo<br>
DebugLoc dl = I->getDebugLoc();<br>
MachineInstr *MI = I;<br>
<br>
- // Don't need to check instructions added in prolog.<br>
- // In prolog, special function calls may be added for specific targets<br>
- // (e.g. on Windows, a prolog helper '_chkstk' is called when the local<br>
- // variables exceed 4K bytes on stack.) These helpers won't use/def YMM/XMM<br>
- // registers.<br>
- if (MI->getFlag(MachineInstr::FrameSetup))<br>
- continue;<br>
-<br>
bool isControlFlow = MI->isCall() || MI->isReturn();<br>
<br>
// Shortcut: don't need to check regular instructions in dirty state.<br>
@@ -260,6 +271,14 @@ bool VZeroUpperInserter::processBasicBlo<br>
if (!isControlFlow)<br>
continue;<br>
<br>
+ // If the call won't clobber any YMM register, skip it as well. It usually<br>
+ // happens on helper function calls (such as '_chkstk', '_ftol2') where<br>
+ // standard calling convention is not used (RegMask is not used to mark<br>
+ // register clobbered and register usage (def/imp-def/use) is well-dfined<br>
+ // and explicitly specified.<br>
+ if (MI->isCall() && !clobbersAnyYmmReg(MI))<br>
+ continue;<br>
+<br>
BBHasCall = true;<br>
<br>
// The VZEROUPPER instruction resets the upper 128 bits of all Intel AVX<br>
<br>
Modified: llvm/trunk/test/CodeGen/X86/pr17631.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/pr17631.ll?rev=196261&r1=196260&r2=196261&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/pr17631.ll?rev=196261&r1=196260&r2=196261&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/test/CodeGen/X86/pr17631.ll (original)<br>
+++ llvm/trunk/test/CodeGen/X86/pr17631.ll Tue Dec 3 03:17:32 2013<br>
@@ -1,16 +1,16 @@<br>
; RUN: llc < %s -mcpu=core-avx-i -mtriple=i386-pc-win32 | FileCheck %s<br>
-<br>
+<br>
%struct_type = type { [64 x <8 x float>], <8 x float> }<br>
-<br>
+<br>
; Function Attrs: nounwind readnone<br>
declare i32 @llvm.x86.avx.movmsk.ps.256(<8 x float>)<br>
-<br>
+<br>
; Function Attrs: nounwind<br>
define i32 @equal(<8 x i32> %A) {<br>
allocas:<br>
%first_alloc = alloca [64 x <8 x i32>]<br>
%second_alloc = alloca %struct_type<br>
-<br>
+<br>
%A1 = bitcast <8 x i32> %A to <8 x float><br>
%A2 = call i32 @llvm.x86.avx.movmsk.ps.256(<8 x float> %A1)<br>
ret i32 %A2<br>
@@ -20,3 +20,15 @@ allocas:<br>
; CHECK-NOT: vzeroupper<br>
; CHECK: _chkstk<br>
; CHECK: ret<br>
+<br>
+define <8 x float> @foo(<8 x float> %y, i64* %p, double %x) {<br>
+ %i = fptoui double %x to i64<br>
+ store i64 %i, i64* %p<br>
+ %ret = fadd <8 x float> %y, %y<br>
+ ret <8 x float> %ret<br>
+}<br>
+<br>
+; CHECK: foo<br>
+; CHECK-NOT: vzeroupper<br>
+; CHECK: _ftol2<br>
+; CHECK: ret<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</blockquote></div><br></div></body></html>