<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Sep 1, 2015 at 9:13 AM, Philip Reames <span dir="ltr"><<a href="mailto:listmail@philipreames.com" target="_blank">listmail@philipreames.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  
    
  
  <div bgcolor="#FFFFFF" text="#000000"><span class="">
    <br>
    <br>
    <div>On 09/01/2015 08:52 AM, Jacques Pienaar
      via llvm-dev wrote:<br>
    </div>
    <blockquote type="cite">
      <div dir="ltr">
        <div class="gmail_quote">
          <div dir="ltr">Hey,
            <div><br>
            </div>
            <div>I'm playing around with a backend with no callee saved
              registers and noticed more spilling than seems needed. I
              tried digging into the spilling code but with limited
              success. I also tried removing all the callee saved
              registers in the X86 backend and saw the same effect
              (basically making CSRs equal to CSR_NoRegs). So I seem to
              be misunderstanding something or missing something simple,
              and thought I'd ask.</div>
            <div><br>
            </div>
            <div>Consider this program as an example:</div>
            <div><br>
            </div>
            <div>
              <div>volatile int x;</div>
              <div><br>
              </div>
              <div>int __attribute__((noinline)) foo() { return x; }</div>
              <div><br>
              </div>
              <div>int main() {</div>
              <div>  for (int i = 0; i < 10; ++i) {</div>
              <div>    foo();</div>
              <div>  }</div>
              <div>}</div>
            </div>
            <div><br>
            </div>
            <div>The resultant output code spills 'i' within the loop (I
              have to compile with -fno-unroll-loops else the loop and
              'i' gets optimized
              away) while 'i' is assigned to a register that is used nowhere else
              in the generated program and I would consider 'foo' easy
              to analyse. At the call site of 'foo' the debugging output
              reports that the stack pointer and return value registers
              are "imp-use" and "imp-def" and no other registers are
              used.</div>
            <div><br>
            </div>
            <div>Should the spilling have occurred? Or this due to some
              feature in the backend that is missing?</div>
          </div>
        </div>
      </div>
    </blockquote></span>
    What are you expectating here?  Are you expecting the backend to
    recognize that foo doesn't actually clobber any registers?  I don't
    believe we do that today.  Without callee saved registers, if the
    value 'i' needs to be preserved across the call, it will need to be
    spilled.  There's no register we can put it in without it being
    clobbered.</div></blockquote><div><br></div><div>Yes that was what I was hoping for as it seems that all the information is there to do that. So at the moment if there is a case such as this then the backend should have some designated callee saved registers. That makes sense if that information isn't being used at the moment then we can't know if the register will be clobbered or not and have to assume it will.</div><div><br></div><div>Thanks</div><div> </div></div></div></div>