<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On May 18, 2011, at 2:15 PM, Evan Cheng wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>Hi Chad,<br><br>Comments below.<br><br>On May 18, 2011, at 12:59 PM, Chad Rosier wrote:<br><br><blockquote type="cite">Author: mcrosier<br></blockquote><blockquote type="cite">Date: Wed May 18 14:59:50 2011<br></blockquote><blockquote type="cite">New Revision: 131560<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">URL: <a href="http://llvm.org/viewvc/llvm-project?rev=131560&view=rev">http://llvm.org/viewvc/llvm-project?rev=131560&view=rev</a><br></blockquote><blockquote type="cite">Log:<br></blockquote><blockquote type="cite">Enables vararg functions that pass all arguments via registers to be optimized into tail-calls when possible.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Added:<br></blockquote><blockquote type="cite">   llvm/trunk/test/CodeGen/X86/vararg_tailcall.ll<br></blockquote><blockquote type="cite">Modified:<br></blockquote><blockquote type="cite">   llvm/trunk/lib/Target/X86/X86ISelLowering.cpp<br></blockquote><blockquote type="cite">   llvm/trunk/test/CodeGen/X86/bool-zext.ll<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Modified: llvm/trunk/lib/Target/X86/X86ISelLowering.cpp<br></blockquote><blockquote type="cite">URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelLowering.cpp?rev=131560&r1=131559&r2=131560&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelLowering.cpp?rev=131560&r1=131559&r2=131560&view=diff</a><br></blockquote><blockquote type="cite">==============================================================================<br></blockquote><blockquote type="cite">--- llvm/trunk/lib/Target/X86/X86ISelLowering.cpp (original)<br></blockquote><blockquote type="cite">+++ llvm/trunk/lib/Target/X86/X86ISelLowering.cpp Wed May 18 14:59:50 2011<br></blockquote><blockquote type="cite">@@ -2525,16 +2525,29 @@<br></blockquote><blockquote type="cite">  if (RegInfo->needsStackRealignment(MF))<br></blockquote><blockquote type="cite">    return false;<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">-  // Do not sibcall optimize vararg calls unless the call site is not passing<br></blockquote><blockquote type="cite">-  // any arguments.<br></blockquote><blockquote type="cite">-  if (isVarArg && !Outs.empty())<br></blockquote><blockquote type="cite">-    return false;<br></blockquote><blockquote type="cite">-<br></blockquote><blockquote type="cite">  // Also avoid sibcall optimization if either caller or callee uses struct<br></blockquote><blockquote type="cite">  // return semantics.<br></blockquote><blockquote type="cite">  if (isCalleeStructRet || isCallerStructRet)<br></blockquote><blockquote type="cite">    return false;<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">+  // Do not sibcall optimize vararg calls unless all arguments are passed via<br></blockquote><blockquote type="cite">+  // registers<br></blockquote><blockquote type="cite">+  if (isVarArg && !Outs.empty()) {<br></blockquote><blockquote type="cite">+    SmallVector<CCValAssign, 16> ArgLocs;<br></blockquote><blockquote type="cite">+    CCState CCInfo(CalleeCC, isVarArg, getTargetMachine(),<br></blockquote><blockquote type="cite">+                   ArgLocs, *DAG.getContext());<br></blockquote><blockquote type="cite">+<br></blockquote><blockquote type="cite">+    // Allocate shadow area for Win64<br></blockquote><blockquote type="cite">+    if (Subtarget->isTargetWin64()) {<br></blockquote><blockquote type="cite">+      CCInfo.AllocateStack(32, 8);<br></blockquote><blockquote type="cite">+    }<br></blockquote><br>Stylistic nitpick. Please remove the '{ }' since the if part is a simple statement. Also, is this even safe to do sibcall here when stack space is being allocated?<br><br>You know this already. Please test this very carefully. Tailcall optimization can break stuff in very subtle ways.<font class="Apple-style-span" color="#000000"><font class="Apple-style-span" color="#144FAE"><br></font></font></div></blockquote><div><br></div>Since I don't have a Win64 machine for testing I'll play it safe.  We no longer attempt to tail-call optimize varargs on Win64 when arguments are being passed.  </div><div>Committed revision 131709.</div><div><br></div><div> Chad<br><br><blockquote type="cite"><div>Evan<br><br><blockquote type="cite">+<br></blockquote><blockquote type="cite">+    CCInfo.AnalyzeCallOperands(Outs, CC_X86);<br></blockquote><blockquote type="cite">+    for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i)<br></blockquote><blockquote type="cite">+      if (!ArgLocs[i].isRegLoc())<br></blockquote><blockquote type="cite">+        return false;<br></blockquote><blockquote type="cite">+  }<br></blockquote><blockquote type="cite">+<br></blockquote><blockquote type="cite">  // If the call result is in ST0 / ST1, it needs to be popped off the x87 stack.<br></blockquote><blockquote type="cite">  // Therefore if it's not used by the call it is not safe to optimize this into<br></blockquote><blockquote type="cite">  // a sibcall.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Modified: llvm/trunk/test/CodeGen/X86/bool-zext.ll<br></blockquote><blockquote type="cite">URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/bool-zext.ll?rev=131560&r1=131559&r2=131560&view=diff">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/bool-zext.ll?rev=131560&r1=131559&r2=131560&view=diff</a><br></blockquote><blockquote type="cite">==============================================================================<br></blockquote><blockquote type="cite">--- llvm/trunk/test/CodeGen/X86/bool-zext.ll (original)<br></blockquote><blockquote type="cite">+++ llvm/trunk/test/CodeGen/X86/bool-zext.ll Wed May 18 14:59:50 2011<br></blockquote><blockquote type="cite">@@ -2,7 +2,7 @@<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">; CHECK: @bar1<br></blockquote><blockquote type="cite">; CHECK: movzbl<br></blockquote><blockquote type="cite">-; CHECK: callq<br></blockquote><blockquote type="cite">+; CHECK: jmp<br></blockquote><blockquote type="cite">define void @bar1(i1 zeroext %v1) nounwind ssp {<br></blockquote><blockquote type="cite">entry:<br></blockquote><blockquote type="cite">  %conv = zext i1 %v1 to i32<br></blockquote><blockquote type="cite">@@ -12,7 +12,7 @@<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">; CHECK: @bar2<br></blockquote><blockquote type="cite">; CHECK-NOT: movzbl<br></blockquote><blockquote type="cite">-; CHECK: callq<br></blockquote><blockquote type="cite">+; CHECK: jmp<br></blockquote><blockquote type="cite">define void @bar2(i8 zeroext %v1) nounwind ssp {<br></blockquote><blockquote type="cite">entry:<br></blockquote><blockquote type="cite">  %conv = zext i8 %v1 to i32<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Added: llvm/trunk/test/CodeGen/X86/vararg_tailcall.ll<br></blockquote><blockquote type="cite">URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/vararg_tailcall.ll?rev=131560&view=auto">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/vararg_tailcall.ll?rev=131560&view=auto</a><br></blockquote><blockquote type="cite">==============================================================================<br></blockquote><blockquote type="cite">--- llvm/trunk/test/CodeGen/X86/vararg_tailcall.ll (added)<br></blockquote><blockquote type="cite">+++ llvm/trunk/test/CodeGen/X86/vararg_tailcall.ll Wed May 18 14:59:50 2011<br></blockquote><blockquote type="cite">@@ -0,0 +1,85 @@<br></blockquote><blockquote type="cite">+; RUN: llc < %s -march=x86-64 | FileCheck %s<br></blockquote><blockquote type="cite">+<br></blockquote><blockquote type="cite">+@.str = private unnamed_addr constant [5 x i8] c"%ld\0A\00"<br></blockquote><blockquote type="cite">+@sel = external global i8*<br></blockquote><blockquote type="cite">+@sel3 = external global i8*<br></blockquote><blockquote type="cite">+@sel4 = external global i8*<br></blockquote><blockquote type="cite">+@sel5 = external global i8*<br></blockquote><blockquote type="cite">+@sel6 = external global i8*<br></blockquote><blockquote type="cite">+@sel7 = external global i8*<br></blockquote><blockquote type="cite">+<br></blockquote><blockquote type="cite">+; CHECK: @foo<br></blockquote><blockquote type="cite">+; CHECK: jmp<br></blockquote><blockquote type="cite">+define void @foo(i64 %arg) nounwind optsize ssp noredzone {<br></blockquote><blockquote type="cite">+entry:<br></blockquote><blockquote type="cite">+  %call = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([5 x i8]* @.str, i64 0, i64 0), i64 %arg) nounwind optsize noredzone<br></blockquote><blockquote type="cite">+  ret void<br></blockquote><blockquote type="cite">+}<br></blockquote><blockquote type="cite">+<br></blockquote><blockquote type="cite">+declare i32 @printf(i8*, ...) optsize noredzone<br></blockquote><blockquote type="cite">+<br></blockquote><blockquote type="cite">+; CHECK: @bar<br></blockquote><blockquote type="cite">+; CHECK: jmp<br></blockquote><blockquote type="cite">+define void @bar(i64 %arg) nounwind optsize ssp noredzone {<br></blockquote><blockquote type="cite">+entry:<br></blockquote><blockquote type="cite">+  tail call void @bar2(i8* getelementptr inbounds ([5 x i8]* @.str, i64 0, i64 0), i64 %arg) nounwind optsize noredzone<br></blockquote><blockquote type="cite">+  ret void<br></blockquote><blockquote type="cite">+}<br></blockquote><blockquote type="cite">+<br></blockquote><blockquote type="cite">+declare void @bar2(i8*, i64) optsize noredzone<br></blockquote><blockquote type="cite">+<br></blockquote><blockquote type="cite">+; CHECK: @foo2<br></blockquote><blockquote type="cite">+; CHECK: jmp<br></blockquote><blockquote type="cite">+define i8* @foo2(i8* %arg) nounwind optsize ssp noredzone {<br></blockquote><blockquote type="cite">+entry:<br></blockquote><blockquote type="cite">+  %tmp1 = load i8** @sel, align 8, !tbaa !0<br></blockquote><blockquote type="cite">+  %call = tail call i8* (i8*, i8*, ...)* @x2(i8* %arg, i8* %tmp1) nounwind optsize noredzone<br></blockquote><blockquote type="cite">+  ret i8* %call<br></blockquote><blockquote type="cite">+}<br></blockquote><blockquote type="cite">+<br></blockquote><blockquote type="cite">+declare i8* @x2(i8*, i8*, ...) optsize noredzone<br></blockquote><blockquote type="cite">+<br></blockquote><blockquote type="cite">+; CHECK: @foo6<br></blockquote><blockquote type="cite">+; CHECK: jmp<br></blockquote><blockquote type="cite">+define i8* @foo6(i8* %arg1, i8* %arg2) nounwind optsize ssp noredzone {<br></blockquote><blockquote type="cite">+entry:<br></blockquote><blockquote type="cite">+  %tmp2 = load i8** @sel3, align 8, !tbaa !0<br></blockquote><blockquote type="cite">+  %tmp3 = load i8** @sel4, align 8, !tbaa !0<br></blockquote><blockquote type="cite">+  %tmp4 = load i8** @sel5, align 8, !tbaa !0<br></blockquote><blockquote type="cite">+  %tmp5 = load i8** @sel6, align 8, !tbaa !0<br></blockquote><blockquote type="cite">+  %call = tail call i8* (i8*, i8*, i8*, ...)* @x3(i8* %arg1, i8* %arg2, i8* %tmp2, i8* %tmp3, i8* %tmp4, i8* %tmp5) nounwind optsize noredzone<br></blockquote><blockquote type="cite">+  ret i8* %call<br></blockquote><blockquote type="cite">+}<br></blockquote><blockquote type="cite">+<br></blockquote><blockquote type="cite">+declare i8* @x3(i8*, i8*, i8*, ...) optsize noredzone<br></blockquote><blockquote type="cite">+<br></blockquote><blockquote type="cite">+; CHECK: @foo7<br></blockquote><blockquote type="cite">+; CHECK: callq<br></blockquote><blockquote type="cite">+define i8* @foo7(i8* %arg1, i8* %arg2) nounwind optsize ssp noredzone {<br></blockquote><blockquote type="cite">+entry:<br></blockquote><blockquote type="cite">+  %tmp2 = load i8** @sel3, align 8, !tbaa !0<br></blockquote><blockquote type="cite">+  %tmp3 = load i8** @sel4, align 8, !tbaa !0<br></blockquote><blockquote type="cite">+  %tmp4 = load i8** @sel5, align 8, !tbaa !0<br></blockquote><blockquote type="cite">+  %tmp5 = load i8** @sel6, align 8, !tbaa !0<br></blockquote><blockquote type="cite">+  %tmp6 = load i8** @sel7, align 8, !tbaa !0<br></blockquote><blockquote type="cite">+  %call = tail call i8* (i8*, i8*, i8*, i8*, i8*, i8*, i8*, ...)* @x7(i8* %arg1, i8* %arg2, i8* %tmp2, i8* %tmp3, i8* %tmp4, i8* %tmp5, i8* %tmp6) nounwind optsize noredzone<br></blockquote><blockquote type="cite">+  ret i8* %call<br></blockquote><blockquote type="cite">+}<br></blockquote><blockquote type="cite">+<br></blockquote><blockquote type="cite">+declare i8* @x7(i8*, i8*, i8*, i8*, i8*, i8*, i8*, ...) optsize noredzone<br></blockquote><blockquote type="cite">+<br></blockquote><blockquote type="cite">+; CHECK: @foo8<br></blockquote><blockquote type="cite">+; CHECK: callq<br></blockquote><blockquote type="cite">+define i8* @foo8(i8* %arg1, i8* %arg2) nounwind optsize ssp noredzone {<br></blockquote><blockquote type="cite">+entry:<br></blockquote><blockquote type="cite">+  %tmp2 = load i8** @sel3, align 8, !tbaa !0<br></blockquote><blockquote type="cite">+  %tmp3 = load i8** @sel4, align 8, !tbaa !0<br></blockquote><blockquote type="cite">+  %tmp4 = load i8** @sel5, align 8, !tbaa !0<br></blockquote><blockquote type="cite">+  %tmp5 = load i8** @sel6, align 8, !tbaa !0<br></blockquote><blockquote type="cite">+  %call = tail call i8* (i8*, i8*, i8*, ...)* @x3(i8* %arg1, i8* %arg2, i8* %tmp2, i8* %tmp3, i8* %tmp4, i8* %tmp5, i32 48879, i32 48879) nounwind optsize noredzone<br></blockquote><blockquote type="cite">+  ret i8* %call<br></blockquote><blockquote type="cite">+}<br></blockquote><blockquote type="cite">+<br></blockquote><blockquote type="cite">+!0 = metadata !{metadata !"any pointer", metadata !1}<br></blockquote><blockquote type="cite">+!1 = metadata !{metadata !"omnipotent char", metadata !2}<br></blockquote><blockquote type="cite">+!2 = metadata !{metadata !"Simple C/C++ TBAA", null}<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">_______________________________________________<br></blockquote><blockquote type="cite">llvm-commits mailing list<br></blockquote><blockquote type="cite"><a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br></blockquote><blockquote type="cite"><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br></blockquote><br></div></blockquote></div><br></body></html>