<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></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 Mar 27, 2015, at 9:17 AM, Philip Reames <<a href="mailto:listmail@philipreames.com" class="">listmail@philipreames.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 14px; 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;" class="">On 03/27/2015 12:00 AM, Andrew Trick wrote:</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 14px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 14px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" class="">On Mar 26, 2015, at 11:52 PM, Sanjoy Das <<a href="mailto:sanjoy@playingwithpointers.com" class="">sanjoy@playingwithpointers.com</a>> wrote:<br class=""><br class=""><blockquote type="cite" class="">If we don't care about trying to optimize out overflow checks in<br class="">InstCombine, I'd go with moving the complexity to CGP.<br class=""></blockquote>I think instcombine should optimize out overflow checks (as it does<br class="">today) without introducing _with_overflow calls.  Are there reasons<br class="">why such an approach would not work?<br class=""></blockquote>I agree. I think that approach would work in any case simple enough for InstCombine to otherwise convert the same compare/branch into a with_overflow intrinsic.<br class=""><br class="">I think the problem we run into is that we also want to optimize the _with_overflow cases that are generated by some frontends. We are stuck with some duplication of effort.<br class=""></blockquote><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 14px; 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;" class="">Possibly crazy idea, but could we lower incoming x.with.overflow to their IR equivalents and then rematch later? This would seem to get us the best of both worlds provided that there aren't key cases where we can optimize the intrinsics better than the IR patterns.</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 14px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""></div></blockquote><div><br class=""></div>Not a crazy idea at all, but it mostly defeats the purpose of the intrinsic and takes power away from the frontend. Frontends use the intrinsics when it’s important to effectively guarantee the best codegen knowing that the optimizer could otherwise obscure the overflow check. Getting that codegen right is often more important than whatever other optimizations may be inhibited by the intrinsic. If the frontend wants to give the optimizer free reign, then it simply shouldn’t use the instrinsics.</div><div><br class=""></div><div>Andy</div><div><br class=""><blockquote type="cite" class=""><div class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 14px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class="">Either way, I think the optimizer should handle compare-and-branch idioms first and foremost.<br class=""></blockquote><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 14px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 14px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class="">Andy<br class=""><br class=""><blockquote type="cite" class=""><blockquote type="cite" class="">However, I think<br class="">InstCombine is doing the right thing here by forming these.<br class=""></blockquote>I don't quite agree with you on this -- by materializing these<br class="">intrinsics InstCombine is making every pass that runs after it less<br class="">effective.  All of them have to know about the _with_overflow<br class="">intrinsics to optimize IR that it could have otherwise optimized.<br class=""><br class="">Another example is GVN -- `opt -gvn` optimizes away %to.optimize but<br class="">`opt -instcombine -gvn` does not.<br class=""><br class="">declare void @side_effect(i1)<br class=""><br class="">define void @foo(i8 %x, i8 %y) {<br class="">entry:<br class=""> %sum = add i8 %x, %y<br class=""> %e = icmp ugt i8 %x, %sum<br class=""> br i1 %e, label %yes, label %no<br class=""><br class="">yes:<br class=""> %to.optimize = icmp ugt i8 %x, %sum<br class=""> call void @side_effect(i1 %to.optimize)<br class=""> br label %no<br class=""><br class="">no:<br class=""> ret void<br class="">}<br class=""></blockquote><br class="">_______________________________________________<br class="">LLVM Developers mailing list<br class=""><a href="mailto:LLVMdev@cs.uiuc.edu" class="">LLVMdev@cs.uiuc.edu</a><span class="Apple-converted-space"> </span>        <a href="http://llvm.cs.uiuc.edu/" class="">http://llvm.cs.uiuc.edu</a><br class=""><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" class="">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a></blockquote></div></blockquote></div><br class=""></body></html>