<html><head><style type='text/css'>p { margin: 0; }</style></head><body><div style='font-family: arial,helvetica,sans-serif; font-size: 10pt; color: #000000'><br><hr id="zwchr"><blockquote id="DWT7749" style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; color: rgb(0, 0, 0); font-weight: normal; font-style: normal; text-decoration: none; font-family: Helvetica,Arial,sans-serif; font-size: 12pt;"><b>From: </b>"Eli via llvm-dev Friedman" <llvm-dev@lists.llvm.org><br><b>To: </b>"Reid Kleckner" <rnk@google.com><br><b>Cc: </b>"llvm-dev" <llvm-dev@lists.llvm.org><br><b>Sent: </b>Friday, December 9, 2016 2:21:57 PM<br><b>Subject: </b>Re: [llvm-dev] RFC: Adding argument allocas<br><br>
<div class="moz-cite-prefix">On 12/9/2016 11:49 AM, Reid Kleckner
wrote:<br>
</div>
<blockquote cite="mid:CACs=tyLhNBrgO3d9WgBPLyxwt+RdkbhoiyWYwLXio4wnfWQSxw@mail.gmail.com">
<div dir="ltr">
<div class="gmail_extra">
<div class="gmail_quote">On Fri, Dec 9, 2016 at 10:30 AM,
Friedman, Eli <span dir="ltr"><<a href="mailto:efriedma@codeaurora.org" target="_blank">efriedma@codeaurora.org</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div><span class="gmail-m_8999134631902946825m_4643703738770916263gmail-">
<div class="gmail-m_8999134631902946825m_4643703738770916263gmail-m_-1365877156293351287moz-cite-prefix">Mmm...
maybe. The part I really don't like is the implied
store: there are a lot of transformations which
specifically reason about store instructions, and
they would all need to be fixed to specifically deal
with "alloca with an argument" so it doesn't block
optimizations. Every feature we add to the IR makes
it more difficult to write IR transformations, and
this really doesn't seem to carry its own weight.</div>
</span></div>
</blockquote>
<div><br>
</div>
<div>I don't feel like it complicates our model that much,
though. Passes already have to know that uninitialized
allocas contain undef, and with this change they can
contain a value. That doesn't seem very surprising. It is
a fair point that we'd have to add new cases to code
like llvm::FindAvailableLoadedValue, which looks for
StoreInst but not AllocaInst.</div>
</div>
</div>
</div>
</blockquote>
<br>
It's more that that... I mean, obviously you have to fix all the
places which assume allocas start off containing undef, but you're
also introducing the potential for missed optimizations by making
the store implicit. For example, consider:<br>
<br>
void g(int *x);<br>
__attribute((noinline)) void f(int y) {<br>
y = 10;<br>
g(&y);<br>
}<br>
void h() { f(134314); }<br>
<br>
The argument to f is dead; there are two stores to y, and
instcombine will eliminate the first one. With extended allocas, we
need a new form of dead store elimination which transforms "alloca
i32, argument %x" -> "alloca i32".<br></blockquote>This is a good point, but it does not seem complicated to implement.<br><br> -Hal<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px; color: rgb(0, 0, 0); font-weight: normal; font-style: normal; text-decoration: none; font-family: Helvetica,Arial,sans-serif; font-size: 12pt;">
<br>
<blockquote cite="mid:CACs=tyLhNBrgO3d9WgBPLyxwt+RdkbhoiyWYwLXio4wnfWQSxw@mail.gmail.com">
<div dir="ltr">
<div class="gmail_extra">
<div class="gmail_quote">
<blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div> 2. We could change the way clang
generates function definitions: instead of "define void
@f(i32 %x)", generate "define void @f(i32* byval %px)"
if the value is going to end up on the stack. This
should work without any changes to the IR. This is a
bad idea if we're trying to run optimizations because it
obscures data flow, but it seems reasonable at -O0.</div>
</blockquote>
<div><br>
</div>
<div>This is problematic because it would break out "bitcode
ABI" between optimized and debug builds. We've had
problems in the past when the caller and callee disagree
on whether an argument is a byval pointer or not, and
instcombine will come along and try to simplify the
casts: <a href="https://llvm.org/bugs/show_bug.cgi?id=21573" target="_blank">https://llvm.org/bugs/show_bug.cgi?id=21573</a></div>
</div>
</div>
</div>
</blockquote>
<br>
If instcombine is breaking this somehow, it's a bug; we're not
supposed to eliminate bitcasts unless we can prove the signatures
are equivalent. Granted, this is a complicated transform which has
had a lot of bugs in the past.<br>
<p>-Eli<br>
</p>
<pre class="moz-signature">--
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project</pre>
<br>_______________________________________________<br>LLVM Developers mailing list<br>llvm-dev@lists.llvm.org<br>http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev<br></blockquote><br><br><br>-- <br><div><span name="x"></span>Hal Finkel<br>Lead, Compiler Technology and Programming Languages<br>Leadership Computing Facility<br>Argonne National Laboratory<span name="x"></span><br></div></div></body></html>