<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">The stack temporaries are allocated to physical stack slots after register allocation, I believe, so yes they will be reused automatically when possible.<div><br><div><div><div>On 24 Nov 2012, at 17:27, Joseph Pusdesris wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">Yes, this is very helpful! Thank you!<div> </div><div>How does this work when exiting a variable's liveness range?  Will it automatically know to free the stack slot for reuse?</div><div>-Joe</div><div class="gmail_extra">

<br><br><div class="gmail_quote">On Sat, Nov 24, 2012 at 12:23 PM, Steve Montgomery <span dir="ltr"><<a href="mailto:stephen.montgomery3@btinternet.com" target="_blank">stephen.montgomery3@btinternet.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Sorry, forgot to Reply-All.<br><div><br><div>Begin forwarded message:</div><br><blockquote type="cite">

<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="font-family:'Helvetica';font-size:medium;color:rgba(0,0,0,1.0)"><b>From: </b></span><span style="font-family:'Helvetica';font-size:medium">Steve Montgomery <<a href="mailto:stephen.montgomery3@btinternet.com" target="_blank">stephen.montgomery3@btinternet.com</a>><br>

</span></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="font-family:'Helvetica';font-size:medium;color:rgba(0,0,0,1.0)"><b>Subject: </b></span><span style="font-family:'Helvetica';font-size:medium"><b>Re: [LLVMdev] Prevention register promotion at the isel codegen phase</b><br>

</span></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="font-family:'Helvetica';font-size:medium;color:rgba(0,0,0,1.0)"><b>Date: </b></span><span style="font-family:'Helvetica';font-size:medium">24 November 2012 17:09:58 GMT<br>

</span></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="font-family:'Helvetica';font-size:medium;color:rgba(0,0,0,1.0)"><b>To: </b></span><span style="font-family:'Helvetica';font-size:medium">Joseph Pusdesris <<a href="mailto:joe@pusdesris.com" target="_blank">joe@pusdesris.com</a>><br>

</span></div><div><div class="h5"><br><div>I had a similar problem trying to implement reg-mem operations. The solution I chose was to use PreprocessISelDAG() to decide which operands needed spilling to memory and then to store and load them from a new stack slot. This seems to work OK for me, though I'm no expert in such matters - perhaps someone more knowledgeable could comment?<br>

<br>Given that operand OpNo of Node needs to be a load, this is the code snippet I used:<br><br>  // Now we know which node to spill, perform the spill.<br>  SDValue SpillVal  = Node->getOperand(OpNo);<br>  SDValue SpillSlot = CurDAG->CreateStackTemporary(SpillVal.getValueType());<br>

  int FI            = cast<FrameIndexSDNode>(SpillSlot)->getIndex();<br>  SDValue Chain     = CurDAG->getStore(CurDAG->getEntryNode(),<br>                                       SpillVal.getDebugLoc(),<br>                                       SpillVal, SpillSlot,<br>

                                       MachinePointerInfo::getFixedStack(FI),<br>                                       false, false, 0);<br>  Chain = CurDAG->getLoad(SpillVal.getValueType(), SpillVal.getDebugLoc(),<br>

                          Chain, SpillSlot,<br>                          MachinePointerInfo::getFixedStack(FI),<br>                          false, false, false, 0);<br><br>  SmallVector<SDValue, 4> Ops;<br>  unsigned NumOps = Node->getNumOperands();<br>

<br>  for (unsigned i = 0; i < NumOps; ++i) {<br>    if (i == OpNo)<br>      Ops.push_back(Chain);<br>    else<br>      Ops.push_back(Node->getOperand(i));<br>  }<br><br>  CurDAG->UpdateNodeOperands(Node, &Ops[0], NumOps);<br>

<br>Note: you can't do this during ISelLowering because the combiner will just remove the store and load again unless you mark one or the other as volatile and that doesn't seem like the right thing to do.<br><br>

Hope that helps.<br><br>On 23 Nov 2012, at 18:02, Joseph Pusdesris wrote:<br><br><blockquote type="cite">I am trying to implement mem-mem operations, but I can't seem to figure out how to prevent register promotion for most cases.<br>

</blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">I can successfully compile:<br></blockquote><blockquote type="cite">int foo(int a, int b){<br></blockquote><blockquote type="cite">  return a + b;<br>

</blockquote><blockquote type="cite">}<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">because it gets matched to store(add(load)(load)), but when I attempt to compile:<br></blockquote><blockquote type="cite">

int foo(int a, int b, int c){<br></blockquote><blockquote type="cite">  return a + b + c;<br></blockquote><blockquote type="cite">}<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">I can't match the add anymore since it is of the form store(add(add(load)(load))(load)).  I think I need to figure out how to force a load/store between the two adds.  I am not sure where to load/store to though, I need to allocate a spill location or something I assume.<br>

</blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Any insight would be greatly appreciated. <br></blockquote><blockquote type="cite">_______________________________________________<br></blockquote>

<blockquote type="cite">LLVM Developers mailing list<br></blockquote><blockquote type="cite"><a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu/" target="_blank">http://llvm.cs.uiuc.edu</a><br>

</blockquote><blockquote type="cite"><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br></blockquote><br></div></div></div></blockquote></div>

<br></div><br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu/" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br></div></div></body></html>