<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;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jun 23, 2015, at 9:37 AM, <a href="mailto:silviu.baranga@arm.com" class="">silviu.baranga@arm.com</a> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">Hi Andy,<br class=""><br class="">Thanks for looking at this!<br class=""><br class="">In <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__reviews.llvm.org_D10161-23192391&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=dUqhfTOOeYeuKdviVl6_S4GyL4_BHeGhL4dtJvdElT0&s=_2Ytm1Ossu_H_grrS8ym000DqptC2SPB8Dvvi5kBuT0&e=" class="">http://reviews.llvm.org/D10161#192391</a>, @atrick wrote:<br class=""><br class=""><blockquote type="cite" class="">Overall, it's great to see something like this working in practice. In the past, several alternatives have been discussed. IIRC the main objection to this approach is that SCEV could make assumptions that are not necessary for the optimization leading to overhead for unnecessary checks.<br class=""></blockquote><br class=""><br class="">Would that be on the list? If so, it would be an interesting read.<br class="">Yes, in theory this can produce unnecessary checks. I think it works ok for the vectorizer (since any case where we wouldn't make this assumption would result in not vectorizing). It looks like a trade-off between not having all the users deal explicitly with this against the number of memchecks.<br class=""></div></div></blockquote><div><br class=""></div><div>I found a couple of old threads mentioning this, but there isn’t much substance and they don’t go into the unnecessary check issue:</div><div><br class=""></div><div><a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__thread.gmane.org_gmane.comp.compilers.llvm.devel_66092_focus-3D66176&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=dUqhfTOOeYeuKdviVl6_S4GyL4_BHeGhL4dtJvdElT0&s=1-drekQLq5aB-1xAGarboIOVVuCWyC0hrZXS9CXfuWQ&e=" class="">http://thread.gmane.org/gmane.comp.compilers.llvm.devel/66092/focus=66176</a></div><div><br class=""></div><a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__thread.gmane.org_gmane.comp.compilers.llvm.devel_67147_focus-3D67476&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=dUqhfTOOeYeuKdviVl6_S4GyL4_BHeGhL4dtJvdElT0&s=5Mgmxf-BYfsmOx-XpU8K9XU-wzyQwylK5Dica_hBFTA&e=" class="">http://thread.gmane.org/gmane.comp.compilers.llvm.devel/67147/focus=67476</a></div><div><br class=""></div><div>Arnold, MichaelZ, and I discussed alternative fixes off-list, but nothing materialized because we found sufficient workarounds.</div><div><br class=""></div><div>Andy</div><div><br class=""><blockquote type="cite" class=""><div class=""><div class=""><br class=""><blockquote type="cite" class="">On most targets, I think it's more efficient to check the high bits for overflow. e.g.<br class=""></blockquote><br class=""><blockquote type="cite" class=""><br class=""></blockquote><br class=""><blockquote type="cite" class="">  if ((a + 0x800000) & 0xffffff000000) overflow<br class=""></blockquote><br class=""><blockquote type="cite" class=""><br class=""></blockquote><br class=""><blockquote type="cite" class=""><br class=""></blockquote><br class=""><blockquote type="cite" class="">Instead of:<br class=""></blockquote><br class=""><blockquote type="cite" class=""><br class=""></blockquote><br class=""><blockquote type="cite" class="">+    if (Signed) {<br class=""></blockquote><br class=""><blockquote type="cite" class=""> +      APInt CmpMinValue = APInt::getSignedMinValue(DstBits).sext(SrcBits);<br class=""></blockquote><br class=""><blockquote type="cite" class=""> +      ConstantInt *CTMin = ConstantInt::get(M->getContext(), CmpMinValue);<br class=""></blockquote><br class=""><blockquote type="cite" class=""> +      Value *MinCheck = OFBuilder.CreateICmp(ICmpInst::ICMP_SLT,<br class=""></blockquote><br class=""><blockquote type="cite" class=""> +                                             TripCount,<br class=""></blockquote><br class=""><blockquote type="cite" class=""> +                                             CTMin);<br class=""></blockquote><br class=""><blockquote type="cite" class=""> +      TripCountCheck = OFBuilder.CreateOr(TripCountCheck, MinCheck);<br class=""></blockquote><br class=""><blockquote type="cite" class=""> +    }<br class=""></blockquote><br class=""><br class="">Nice. I wonder if the optimizers handle well the cases where we would test some consecutive values with this method, or if we don't end up generating something similar anyway.<br class=""><br class="">Thanks,<br class="">Silviu<br class=""><br class=""><br class=""><a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__reviews.llvm.org_D10161&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=dUqhfTOOeYeuKdviVl6_S4GyL4_BHeGhL4dtJvdElT0&s=5thZCZmI9YjdApIAXV9OY7GqWf2Q7YmIb6OwWC7V2Og&e=" class="">http://reviews.llvm.org/D10161</a><br class=""><br class="">EMAIL PREFERENCES<br class="">  http://reviews.llvm.org/settings/panel/emailpreferences/<br class=""><br class=""><br class=""></div></div></blockquote></div><br class=""></body></html>