<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">
Hi,
<div class=""><br class="">
</div>
<div class="">After investigating, I still haven’t found the issue here. The code looks sensible, and there are only two places where the returned attribute affects codegen: setting the preserved mask and marking the zero’th parameter as used:</div>
<div class=""><br class="">
</div>
<div class="">
<div class="">    if (i == 0 && isThisReturn) {</div>
<div class="">      assert(!VA.needsCustom() && VA.getLocVT() == MVT::i64 &&</div>
<div class="">             "unexpected return calling convention register assignment");</div>
<div class="">      InVals.push_back(ThisVal);</div>
<div class="">      continue;</div>
<div class="">    }</div>
<div class=""><br class="">
</div>
<div class="">I’ve determined that the mask setting isn’t causing the issue, the above code is. But I’m not exactly sure why…</div>
<div class=""><br class="">
</div>
<div class="">Cheers,</div>
<div class=""><br class="">
</div>
<div class="">James</div>
<div>
<blockquote type="cite" class="">
<div class="">On 11 Jul 2016, at 13:06, Hal Finkel <<a href="mailto:hfinkel@anl.gov" class="">hfinkel@anl.gov</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">-----
 Original Message -----</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">
<blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">
From: "James Molloy" <<a href="mailto:James.Molloy@arm.com" class="">James.Molloy@arm.com</a>><br class="">
To: "Hal Finkel" <<a href="mailto:hfinkel@anl.gov" class="">hfinkel@anl.gov</a>><br class="">
Cc: "Tim Northover" <<a href="mailto:t.p.northover@gmail.com" class="">t.p.northover@gmail.com</a>>, "renato golin" <<a href="mailto:renato.golin@linaro.org" class="">renato.golin@linaro.org</a>>,<span class="Apple-converted-space"> </span><a href="mailto:llvm-commits@lists.llvm.org" class="">llvm-commits@lists.llvm.org</a><br class="">
Sent: Monday, July 11, 2016 2:57:33 AM<br class="">
Subject: Re: [llvm] r275042 - Revert r275027 - Let FuncAttrs infer the 'returned' argument attribute<br class="">
<br class="">
Hi Hal,<br class="">
<br class="">
I’ll try and attack this today. I don’t suppose you noticed if any<br class="">
stage1 builders went awry too? That would help with getting it<br class="">
debugged quicker.<br class="">
</blockquote>
<br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">
<span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Thanks!
 Unfortunately, no. Only the self-hosting builders were unhappy as far as I can tell.</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">
<br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">
<span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">-Hal</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">
<br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">
<blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">
<br class="">
Cheers,<br class="">
<br class="">
James<br class="">
<blockquote type="cite" class="">On 11 Jul 2016, at 06:11, Hal Finkel <<a href="mailto:hfinkel@anl.gov" class="">hfinkel@anl.gov</a>> wrote:<br class="">
<br class="">
Hi Tim, James, Renato,<br class="">
<br class="">
I'm not sure who is the best person to ask about this, but adding<br class="">
code to infer the 'returned' attribute on function arguments seems<br class="">
to cause the AArch64 backend to miscompile conspicuously:<br class="">
<br class="">
<a href="http://lab.llvm.org:8011/builders/clang-cmake-aarch64-full/builds/2564" class="">http://lab.llvm.org:8011/builders/clang-cmake-aarch64-full/builds/2564</a><br class="">
<br class="">
The other backends don't seem to have a problem, but then again,<br class="">
only ARM and AArch64 have special handling for 'returned'<br class="">
arguments. AArch64ISelLowering.cpp has, in part:<br class="">
<br class="">
  if (VA.isRegLoc()) {<br class="">
    if (realArgIdx == 0 && Flags.isReturned() && Outs[0].VT ==<br class="">
    MVT::i64) {<br class="">
      assert(VA.getLocVT() == MVT::i64 &&<br class="">
             "unexpected calling convention register assignment");<br class="">
      assert(!Ins.empty() && Ins[0].VT == MVT::i64 &&<br class="">
             "unexpected use of 'returned'");<br class="">
  ...<br class="">
<br class="">
and ARMISelLowering.cpp seems very similar.<br class="">
<br class="">
Any idea what's going on?<br class="">
<br class="">
To test, unrevert this commit (and r275043 for the few Clang test<br class="">
changes).<br class="">
<br class="">
Thanks again,<br class="">
Hal<br class="">
<br class="">
----- Original Message -----<br class="">
<blockquote type="cite" class="">From: "Hal Finkel via llvm-commits" <llvm-commits@lists.llvm.org><br class="">
To: llvm-commits@lists.llvm.org<br class="">
Sent: Sunday, July 10, 2016 11:51:24 PM<br class="">
Subject: [llvm] r275042 - Revert r275027 - Let FuncAttrs infer the<br class="">
'returned' argument attribute<br class="">
<br class="">
Author: hfinkel<br class="">
Date: Sun Jul 10 23:51:23 2016<br class="">
New Revision: 275042<br class="">
<br class="">
URL: http://llvm.org/viewvc/llvm-project?rev=275042&view=rev<br class="">
Log:<br class="">
Revert r275027 - Let FuncAttrs infer the 'returned' argument<br class="">
attribute<br class="">
<br class="">
Reverting r275027 and r275033. These seem to cause miscompiles on<br class="">
the<br class="">
AArch64 buildbot.<br class="">
<br class="">
Modified:<br class="">
  llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp<br class="">
  llvm/trunk/test/Transforms/FunctionAttrs/2009-01-02-LocalStores.ll<br class="">
  llvm/trunk/test/Transforms/FunctionAttrs/nocapture.ll<br class="">
  llvm/trunk/test/Transforms/FunctionAttrs/readattrs.ll<br class="">
<br class="">
Modified: llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp<br class="">
URL:<br class="">
http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp?rev=275042&r1=275041&r2=275042&view=diff<br class="">
==============================================================================<br class="">
--- llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp (original)<br class="">
+++ llvm/trunk/lib/Transforms/IPO/FunctionAttrs.cpp Sun Jul 10<br class="">
23:51:23 2016<br class="">
@@ -42,7 +42,6 @@ using namespace llvm;<br class="">
STATISTIC(NumReadNone, "Number of functions marked readnone");<br class="">
STATISTIC(NumReadOnly, "Number of functions marked readonly");<br class="">
STATISTIC(NumNoCapture, "Number of arguments marked nocapture");<br class="">
-STATISTIC(NumReturned, "Number of arguments marked returned");<br class="">
STATISTIC(NumReadNoneArg, "Number of arguments marked readnone");<br class="">
STATISTIC(NumReadOnlyArg, "Number of arguments marked readonly");<br class="">
STATISTIC(NumNoAlias, "Number of function returns marked<br class="">
noalias");<br class="">
@@ -484,53 +483,6 @@ determinePointerReadAttrs(Argument *A,<br class="">
 return IsRead ? Attribute::ReadOnly : Attribute::ReadNone;<br class="">
}<br class="">
<br class="">
-/// Deduce returned attributes for the SCC.<br class="">
-static bool addArgumentReturnedAttrs(const SCCNodeSet &SCCNodes)<br class="">
{<br class="">
-  bool Changed = false;<br class="">
-<br class="">
-  AttrBuilder B;<br class="">
-  B.addAttribute(Attribute::Returned);<br class="">
-<br class="">
-  // Check each function in turn, determining if an argument is<br class="">
always returned.<br class="">
-  for (Function *F : SCCNodes) {<br class="">
-    // We can infer and propagate function attributes only when<br class="">
we<br class="">
know that the<br class="">
-    // definition we'll get at link time is *exactly* the<br class="">
definition<br class="">
we see now.<br class="">
-    // For more details, see GlobalValue::mayBeDerefined.<br class="">
-    if (!F->hasExactDefinition())<br class="">
-      continue;<br class="">
-<br class="">
-    if (F->getReturnType()->isVoidTy())<br class="">
-      continue;<br class="">
-<br class="">
-    auto FindRetArg = [&]() -> Value * {<br class="">
-      Value *RetArg = nullptr;<br class="">
-      for (BasicBlock &BB : *F)<br class="">
-        if (auto *Ret = dyn_cast<ReturnInst>(BB.getTerminator()))<br class="">
{<br class="">
-          // Note that stripPointerCasts should look through<br class="">
functions with<br class="">
-          // returned arguments.<br class="">
-          Value *RetVal =<br class="">
Ret->getReturnValue()->stripPointerCasts();<br class="">
-          if (RetVal->getType() == F->getReturnType() &&<br class="">
isa<Argument>(RetVal)) {<br class="">
-            if (!RetArg)<br class="">
-              RetArg = RetVal;<br class="">
-            else if (RetArg != RetVal)<br class="">
-              return nullptr;<br class="">
-          }<br class="">
-        }<br class="">
-<br class="">
-      return RetArg;<br class="">
-    };<br class="">
-<br class="">
-    if (Value *RetArg = FindRetArg()) {<br class="">
-      auto *A = cast<Argument>(RetArg);<br class="">
-      A->addAttr(AttributeSet::get(F->getContext(), A->getArgNo()<br class="">
+<br class="">
1, B));<br class="">
-      ++NumReturned;<br class="">
-      Changed = true;<br class="">
-    }<br class="">
-  }<br class="">
-<br class="">
-  return Changed;<br class="">
-}<br class="">
-<br class="">
/// Deduce nocapture attributes for the SCC.<br class="">
static bool addArgumentAttrs(const SCCNodeSet &SCCNodes) {<br class="">
 bool Changed = false;<br class="">
@@ -1072,7 +1024,6 @@ PreservedAnalyses PostOrderFunctionAttrs<br class="">
 }<br class="">
<br class="">
 bool Changed = false;<br class="">
-  Changed |= addArgumentReturnedAttrs(SCCNodes);<br class="">
 Changed |= addReadAttrs(SCCNodes, AARGetter);<br class="">
 Changed |= addArgumentAttrs(SCCNodes);<br class="">
<br class="">
@@ -1138,7 +1089,6 @@ static bool runImpl(CallGraphSCC &SCC, A<br class="">
   SCCNodes.insert(F);<br class="">
 }<br class="">
<br class="">
-  Changed |= addArgumentReturnedAttrs(SCCNodes);<br class="">
 Changed |= addReadAttrs(SCCNodes, AARGetter);<br class="">
 Changed |= addArgumentAttrs(SCCNodes);<br class="">
<br class="">
<br class="">
Modified:<br class="">
llvm/trunk/test/Transforms/FunctionAttrs/2009-01-02-LocalStores.ll<br class="">
URL:<br class="">
http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/FunctionAttrs/2009-01-02-LocalStores.ll?rev=275042&r1=275041&r2=275042&view=diff<br class="">
==============================================================================<br class="">
---<br class="">
llvm/trunk/test/Transforms/FunctionAttrs/2009-01-02-LocalStores.ll<br class="">
(original)<br class="">
+++<br class="">
llvm/trunk/test/Transforms/FunctionAttrs/2009-01-02-LocalStores.ll<br class="">
Sun Jul 10 23:51:23 2016<br class="">
@@ -14,7 +14,7 @@ define i32* @b(i32 *%q) {<br class="">
ret i32* %tmp<br class="">
}<br class="">
<br class="">
-; CHECK: define i32* @c(i32* readnone returned %r)<br class="">
+; CHECK: define i32* @c(i32* readnone %r)<br class="">
@g = global i32 0<br class="">
define i32* @c(i32 *%r) {<br class="">
%a = icmp eq i32* %r, null<br class="">
<br class="">
Modified: llvm/trunk/test/Transforms/FunctionAttrs/nocapture.ll<br class="">
URL:<br class="">
http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/FunctionAttrs/nocapture.ll?rev=275042&r1=275041&r2=275042&view=diff<br class="">
==============================================================================<br class="">
--- llvm/trunk/test/Transforms/FunctionAttrs/nocapture.ll<br class="">
(original)<br class="">
+++ llvm/trunk/test/Transforms/FunctionAttrs/nocapture.ll Sun Jul<br class="">
10<br class="">
23:51:23 2016<br class="">
@@ -1,7 +1,7 @@<br class="">
; RUN: opt < %s -functionattrs -S | FileCheck %s<br class="">
@g = global i32* null; <i32**> [#uses=1]<br class="">
<br class="">
-; CHECK: define i32* @c1(i32* readnone returned %q)<br class="">
+; CHECK: define i32* @c1(i32* readnone %q)<br class="">
define i32* @c1(i32* %q) {<br class="">
ret i32* %q<br class="">
}<br class="">
@@ -140,7 +140,7 @@ define void @test1_1(i8* %x1_1, i8* %y1_<br class="">
 ret void<br class="">
}<br class="">
<br class="">
-; CHECK: define i8* @test1_2(i8* nocapture readnone %x1_2, i8*<br class="">
returned %y1_2)<br class="">
+; CHECK: define i8* @test1_2(i8* nocapture readnone %x1_2, i8*<br class="">
%y1_2)<br class="">
define i8* @test1_2(i8* %x1_2, i8* %y1_2) {<br class="">
 call void @test1_1(i8* %x1_2, i8* %y1_2)<br class="">
 store i32* null, i32** @g<br class="">
@@ -168,7 +168,7 @@ define void @test4_1(i8* %x4_1) {<br class="">
 ret void<br class="">
}<br class="">
<br class="">
-; CHECK: define i8* @test4_2(i8* nocapture readnone %x4_2, i8*<br class="">
readnone returned %y4_2, i8* nocapture readnone %z4_2)<br class="">
+; CHECK: define i8* @test4_2(i8* nocapture readnone %x4_2, i8*<br class="">
readnone %y4_2, i8* nocapture readnone %z4_2)<br class="">
define i8* @test4_2(i8* %x4_2, i8* %y4_2, i8* %z4_2) {<br class="">
 call void @test4_1(i8* null)<br class="">
 store i32* null, i32** @g<br class="">
<br class="">
Modified: llvm/trunk/test/Transforms/FunctionAttrs/readattrs.ll<br class="">
URL:<br class="">
http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/FunctionAttrs/readattrs.ll?rev=275042&r1=275041&r2=275042&view=diff<br class="">
==============================================================================<br class="">
--- llvm/trunk/test/Transforms/FunctionAttrs/readattrs.ll<br class="">
(original)<br class="">
+++ llvm/trunk/test/Transforms/FunctionAttrs/readattrs.ll Sun Jul<br class="">
10<br class="">
23:51:23 2016<br class="">
@@ -11,7 +11,7 @@ define void @test1_2(i8* %x1_2, i8* %y1_<br class="">
 ret void<br class="">
}<br class="">
<br class="">
-; CHECK: define i8* @test2(i8* readnone returned %p)<br class="">
+; CHECK: define i8* @test2(i8* readnone %p)<br class="">
define i8* @test2(i8* %p) {<br class="">
 store i32 0, i32* @x<br class="">
 ret i8* %p<br class="">
@@ -53,7 +53,7 @@ define void @test7_1(i32* inalloca %a) {<br class="">
 ret void<br class="">
}<br class="">
<br class="">
-; CHECK: define i32* @test8_1(i32* readnone returned %p)<br class="">
+; CHECK: define i32* @test8_1(i32* readnone %p)<br class="">
define i32* @test8_1(i32* %p) {<br class="">
entry:<br class="">
 ret i32* %p<br class="">
<br class="">
<br class="">
_______________________________________________<br class="">
llvm-commits mailing list<br class="">
llvm-commits@lists.llvm.org<br class="">
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits<br class="">
<br class="">
</blockquote>
<br class="">
--<br class="">
Hal Finkel<br class="">
Assistant Computational Scientist<br class="">
Leadership Computing Facility<br class="">
Argonne National Laboratory<br class="">
<br class="">
</blockquote>
<br class="">
IMPORTANT NOTICE: The contents of this email and any attachments are<br class="">
confidential and may also be privileged. If you are not the intended<br class="">
recipient, please notify the sender immediately and do not disclose<br class="">
the contents to any other person, use it for any purpose, or store<br class="">
or copy the information in any medium. Thank you.<br class="">
<br class="">
</blockquote>
<br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">
<span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">--<span class="Apple-converted-space"> </span></span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">
<span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Hal
 Finkel</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">
<span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Assistant
 Computational Scientist</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">
<span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Leadership
 Computing Facility</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">
<span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Argonne
 National Laboratory</span></div>
</blockquote>
</div>
<br class="">
</div>
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose,
 or store or copy the information in any medium. Thank you.
</body>
</html>