<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, May 2, 2016 at 6:27 PM, Matthias Braun <span dir="ltr"><<a href="mailto:matze@braunis.de">matze@braunis.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">My first intuition would be that we just need to provide the proper clobber mask for all personality functions to get your desired behavior. However currently this would not help because these extra clobber masks are not passed to MachineRegisterInfo::addPhysRegsUsedFromRegMask() in the VirtRegRewriter and thus are not considered for prologue epilogue insertion.<br></blockquote><div><br></div><div>This was no accident, I very carefully arranged to represent these masks as something other than MachineOperands specifically so that PEI *wouldn't* consider them clobbered. :)</div><div><br></div><div>On Win64, the unwinder arranges to restore all your registers to what they were at the point of the throwing call site, either after you rejoin normal control flow (via catchret in LLVM) or by unwinding out of the frame. They *don't* restore the registers on entry into a funclet cleanuppad or catchpad, which is why we have these register masks in in the first place. Win64 has *many* CSRs including XMM registers, so if things were not arranged this way, all functions using WinEH would have ridiculously large prologues.</div><div><br></div><div>On Win32, we still have this hack in X86ISelLowering:</div><div><div>  // If this is an invoke in a 32-bit function using a funclet-based</div><div>  // personality, assume the function clobbers all registers. If an exception</div><div>  // is thrown, the runtime will not restore CSRs.</div><div>  // FIXME: Model this more precisely so that we can register allocate across</div><div>  // the normal edge and spill and fill across the exceptional edge.</div><div>  if (!Is64Bit && CLI.CS && CLI.CS->isInvoke()) {</div><div>    const Function *CallerFn = MF.getFunction();</div><div>    EHPersonality Pers =</div><div>        CallerFn->hasPersonalityFn()</div><div>            ? classifyEHPersonality(CallerFn->getPersonalityFn())</div><div>            : EHPersonality::Unknown;</div><div>    if (isFuncletEHPersonality(Pers))</div><div>      Mask = RegInfo->getNoPreservedMask();</div><div>  }</div><div>The old 32-bit unwinder is not kind enough to restore registers for us, so we slapped a NoPreservedMask on the invoke, which makes PEI push all CSRs (all three of them!). We could get rid of this hack if we added something similar to what Marcin is proposing.</div></div></div></div></div>