<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Nov 28, 2010, at 3:47 PM, John McCall wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; font-family: Optima; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><span class="Apple-style-span" style="font-family: monospace; ">So mem2reg would have to split %try and make a phi in %lp, like so:<br><br>try1: unwinds to %lp<br> %count = load i32* @count<br> br label %try2<br>try2: unwinds to %lp<br> call void foo()<br> br label %return<br>lp:<br> %t = phi i32 [ i32 0, label %try1 ], [ i32 %count, label %try2 ]<br> #etc.<br><br>That's a lot of added complexity for mem2reg (and other transformations that use it as a subroutine), but it's pretty much inherent in any design where edges don't always come from terminators.<br><br>Now, in this specific case, mem2reg could say "hey, %count can't throw, I don't need the phi at all".  But it would still need to split %lp to make the IR well-formed;  it's just that %lp1 wouldn't have an "unwinds" clause.  And in the general case, it needs a phi.<br></span></span></blockquote></div><br><div>This problem reappears during register allocation.</div><div><br></div><div>If a value is live-in to a landing pad, it must be kept in the same location before any instruction that may throw - a callee-saved register or a stack slot.</div><div><br></div><div>That means the register allocator is no longer free to move values between registers and the stack inside a basic block. It would at least have to ensure that a copy is kept in a stack slot or in a fixed callee-saved register. This would be particularly bad for register classes that have no callee-saved registers, such as vector registers.</div><div><br></div><div>This will be less of a problem if the code generator knows which instructions may throw.</div><div><br></div><div>/jakob</div><div><br></div></body></html>