<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;"><br><div><div>On Sep 30, 2014, at 12:51 AM, Hal Finkel <<a href="mailto:hfinkel@anl.gov">hfinkel@anl.gov</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="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;">----- Original Message -----<br><blockquote type="cite">From: "Michael Liao" <<a href="mailto:michael.liao@intel.com">michael.liao@intel.com</a>><br>To: "Hal Finkel" <<a href="mailto:hfinkel@anl.gov">hfinkel@anl.gov</a>><br>Cc:<span class="Apple-converted-space"> </span><a href="mailto:reviews+D5444+public+de6f72cb2e4729d3@reviews.llvm.org">reviews+D5444+public+de6f72cb2e4729d3@reviews.llvm.org</a>,<span class="Apple-converted-space"> </span><a href="mailto:spatel@rotateright.com">spatel@rotateright.com</a>,<span class="Apple-converted-space"> </span><a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a>,<br><a href="mailto:nrotem@apple.com">nrotem@apple.com</a><br>Sent: Monday, September 29, 2014 11:10:38 PM<br>Subject: Re: [PATCH] Allow BB duplication threshold to be adjusted through JumpThreading's ctor<br><br><br><br>On Mon, 29 Sep, 2014 at 5:10 PM, Hal Finkel <<a href="mailto:hfinkel@anl.gov">hfinkel@anl.gov</a>> wrote:<br><blockquote type="cite">----- Original Message -----<br><blockquote type="cite">From: "Michael Liao" <<a href="mailto:michael.liao@intel.com">michael.liao@intel.com</a>><br>To: "michael liao" <<a href="mailto:michael.liao@intel.com">michael.liao@intel.com</a>>, <a href="mailto:nrotem@apple.com">nrotem@apple.com</a>,<br><a href="mailto:hfinkel@anl.gov">hfinkel@anl.gov</a><br>Cc: spatel@rotateright.com, llvm-commits@cs.uiuc.edu<br>Sent: Monday, September 29, 2014 6:34:36 PM<br>Subject: Re: [PATCH] Allow BB duplication threshold to be<br>adjusted<br>through JumpThreading's ctor<br><br>Hi Hal<br><br>Yeah, "noduplicate" could prevent duplicating of barrier calls<br>but<br>that<br>patch wants to address the potential issue on processors with<br>divergent<br>control flow, commonly found in GPUs, e.g. AMD/NVIDIA ones. The<br>scenario is that, if BB is duplicated to exploit more jump<br>threading,<br>targets with divergent CF may execute more instructions if the<br>condition is a divergent one.<br><br>For updating that threshold from TTI, yeah, if we are interested<br>in<br>that case. I could come another patch considering both TTI and<br>user-specified threshold.<br></blockquote><br>I suppose that I don't understand what you mean by "if we are<br>interested." Generally speaking, ctor parameters are useful only<br>for<br>clients who are not using the standard optimization pipeline, and<br>we'd like the standard optimization pipeline to generally work well<br>for a wide range of targets. Thus, a TTI interface is preferred.<br></blockquote><br>OK, I will add another patch with TTI support.<br><br><blockquote type="cite"><br><br>From a cost modeling perspective, how can you tell whether the<br>instruction duplication will be worthwhile. Can this be something<br>like 2*(instruction costs) <= (branch cost)?<br></blockquote><br>To be honest, I have no concrete answer as the instruction cost may<br>be<br>changed significantly after merging two BB, which is not fully<br>considered in the current cost model. E.g., if inst-fold kicks in<br>after<br>duplicating that BB and folds all instructions. Probably a better<br>place<br>to address that is to add a similar pass in backend with detailed<br>target model. So far, this patch only allows brief control of that<br>threshold.<br></blockquote><br>The problem of estimating what costs will be after instruction folding is faced by many mid-level passes, and while a machine-instruction-level pass could do a better job at cost modeling, those passes often run too late to enable other optimizations, interact with inlining, etc.<br><br>That having been said, currently, getJumpThreadDuplicationCost does not use any of the current TTI-based cost modeling infrastructure (it pre-dates TTI), and I agree that it will provide a poor estimate of the ultimate cost because it has no understand of what the target will be able to fold. I suspect it would be better to make the function work more like CodeMetrics::analyzeBasicBlock so that the target can inform the estimation of the cost of each instruction (even the base TTI implemented has some intelligence that can be applied). I suspect that proving getJumpThreadDuplicationCost with an actual target-informed method for estimating costs will ultimately yield better results for everyone<br></div></blockquote><br></div><div><div>If you want to go the code model route, you’re going to want to introduce some concept of duplication cost for an instruction.  This code would be marginal on most CPUs (the only cost is code size), but significant on GPUs (or CPUs programmed in a SPMD fashion) where duplicated instructions have significant cost, even if unexecuted, because they reduce the utilization of the machine’s vector width.</div><div><br></div><div>—Owen</div></div><br></body></html>