<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Hi Marcello,<div><br></div><div>This is awesome. I’ve been wanting improvements like this for a long time now, but have never gotten around to doing it myself. My procrastination^Wpatience is paying off!</div><div><br></div><div>When running on the LLVM test suite (including externals, preferably), how often does this optimization fire?</div><div><br></div><div>A few detail comments below. Nothing major.</div><div><br></div><div>General style nitpick: make sure comments are full sentences and end in a period.</div><div><br></div><div><br></div><div><blockquote type="cite">+// LowerBound and UpperBound are used to keep track of the bounds for Val <br>+// that have being already checked by a block emitted by one of the previous <br>+// calls to switchConvert in the call stack. </blockquote><br></div><div>s/have being already/have already been/</div><div><br></div><div><blockquote type="cite"><div>+ // Check if the Case Range is perfectly squeezed in between</div><div>+ // already checked Upper and Lower bounds. If it is then we can avoid</div><div>+ // emitting the code that checks if the value actually falls in the range</div><div>+ // because the bounds already tell us so</div><div>+ if (LowerBound != nullptr && UpperBound != nullptr &&</div><div>+ Begin->Low == LowerBound && Begin->High == UpperBound) {</div><div>+ return Begin->BB;</div><div>+ }</div></blockquote><div><br></div><div>Can Begin->Low or Begin->High ever be null? If not, the explicit nullptr checks can be removed as they’re implicit. If they can be null, that seems a bit odd for the algorithm.</div><div><br></div><div><blockquote type="cite">+ // NewLowerBound here should never be the integer value minimal.</blockquote><br></div><div>I don’t quite follow this comment.</div><div><br></div><div><blockquote type="cite">+ // Optimize the case where Default is an unreachable block <br>+ if (DefaultIsUnreachable) { <br>+ CaseItr LastCase = Cases.begin() + Cases.size() - 1; <br>+ UpperBound = cast<ConstantInt>(LastCase->High); <br>+ LowerBound = cast<ConstantInt>(Cases.begin()->Low); <br>+ }</blockquote></div><div><br></div><div>While accurate, the comment is a bit terse. It would be helpful to explain how we’re optimizing it, not just that we are. I.e., explain why the following code results in an optimization.</div><div><br></div><br><div><blockquote type="cite"><div>On Jun 11, 2014, at 4:22 PM, Marcello Maggioni <<a href="mailto:hayarms@gmail.com">hayarms@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div>I'm updating the patch to also remove the default basic block if it ends up being dead after switch lowering (no predecessors)<br></div><div class="gmail_extra"><br></div><div class="gmail_extra">Marcello<br><br><div class="gmail_quote">2014-06-11 20:34 GMT+01:00 Marcello Maggioni<span class="Apple-converted-space"> </span><span dir="ltr"><<a href="mailto:hayarms@gmail.com" target="_blank">hayarms@gmail.com</a>></span>:<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;"><div dir="ltr">Joerg,<div><br></div><div>I addressed your suggestion in this patch.</div><div>It was quite easy to add and can be useful in general, so thanks!</div><div><br></div><div>I also added a test that tests this kind of optimization being applied.</div><div><br></div><div>Marcello</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">2014-06-11 18:37 GMT+01:00 Joerg Sonnenberger<span class="Apple-converted-space"> </span><span dir="ltr"><<a href="mailto:joerg@britannica.bec.de" target="_blank">joerg@britannica.bec.de</a>></span>:<div><div class="h5"><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;"><div>On Wed, Jun 11, 2014 at 05:28:05PM +0100, Marcello Maggioni wrote:<br>> Yeah, it is suboptimal, it doesn't take into consideration the fact that<br>> the default is unreachable.<br>><br>> I'll a look at it later to see if it is easy to also take into<br>> consideration this case and add it to the patch + test for the condition.<br><br></div>Thanks. Please don't take this as hold up for pushing the original<br>patch, it can just as well be a follow-up commit.<br><div><br>Joerg<br>_______________________________________________<br>llvm-commits mailing list<br><a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">llvm-commits@cs.uiuc.edu</a><br><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br></div></blockquote></div></div></div><br></div></blockquote></div><br></div></div><span><optimized_lower_switch_v5.patch></span><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;">_______________________________________________</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;">llvm-commits mailing list</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><a href="mailto:llvm-commits@cs.uiuc.edu" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">llvm-commits@cs.uiuc.edu</a><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a></div></blockquote></div><br></div></body></html>