On Tue, Oct 23, 2012 at 12:56 PM, Eric Christopher <span dir="ltr"><<a href="mailto:echristo@gmail.com" target="_blank">echristo@gmail.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">> Thanks for replying so quickly. Would you elaborate on this further?<br>
><br>
> It seems costly to change the default stack alignment on the platform, since<br>
> that would require recompiling all of the system and user libraries to also<br>
> adhere to 32-byte stack alignment. Depending on an alignment not specified<br>
> by the ABI would also limit our compiler's interoperability with other<br>
> compilers installed on the system.<br>
><br>
> I suppose that the stack could be aligned dynamically at main(...) and other<br>
> visible entry points, but that too seems costly compared to the current<br>
> M.O..<br>
><br>
> Maybe I do not fully understand all the issues involved, but I suppose I<br>
> should be able to dynamically align the stack only when AVX registers are<br>
> spilled in a function, right? Seems reasonable with my limited knowledge. Do<br>
> you have any intuition built? It could be possible that the<br>
> prologue/epilogue emitters run prior to the spilling decisions. I am not so<br>
> sure of the ordering here.<br>
><br>
> Also, and this might be asking a lot, but do you have any insight into why<br>
> this behaviour changed sometime around the LLVM 3.0 release? I have not been<br>
> able to find much history.<br>
><br>
<br>
</div>It should only be happening if there is either a variable stored or<br>
saved on the stack. Functions without AVX shouldn't cause a 32-byte<br>
aligned stack or a realignment unless they are using callee saved<br>
registers that are clobbered, etc. Basically any stack traffic with an<br>
AVX register should cause a dynamic realignment and otherwise we<br>
should use the default abi alignment. Arguably a bug if anything else<br>
is happening.<br></blockquote><div><br></div><div>Yes, I believe that this is happening if any AVX register is used in a function; an AVX variable does not necessarily need to be placed on the stack.</div><div><br></div>
<div>Maybe I am misunderstanding this piece of code though...</div><div><br></div><div><div>>      // Be over-conservative: scan over all vreg defs and find whether vector</div><div>>      // registers are used. If yes, there is a possibility that vector register</div>
<div>>      // will be spilled and thus require dynamic stack realignment.</div><div>>      for (unsigned i = 0, e = RI.getNumVirtRegs(); i != e; ++i) {</div><div>>        unsigned Reg = TargetRegisterInfo::index2VirtReg(i);</div>
<div>>        if (RI.getRegClass(Reg)->getAlignment() > StackAlignment) {</div><div>>          FuncInfo->setForceFramePointer(true); // <= Forces Frame Pointer for any AVX reg use!!!</div><div>>          return true;</div>
<div>>        }</div><div>>      }</div></div><div><br></div><div>Just to be pedantic, at one time this did work properly for AVX without adding the unnecessary frame pointer. It is a proper regression.</div><div><br>
</div><div>-Cameron</div></div>