<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="">Hi Eric,<div class=""><br class=""></div><div class="">We indeed have a swarm of different options, and I’d be happy to simplify it. However, most of them (actually, all of them I think) are there for a reason, so trying to remove them would probably be painful.</div><div class=""><br class=""></div><div class="">Let’s look at what we had there:</div><div class="">* threshold for unrolling in presence of pragma</div><div class="">* threshold for unrolling under -Os</div><div class="">* threshold for unrolling in other cases</div><div class="">* flag 'is partial unrolling allowed’</div><div class=""><div class="">* flag 'is runtime unrolling allowed’</div></div><div class=""><br class=""></div><div class="">Now I've added two more options:</div><div class="">* ‘absolute’ threshold</div><div class="">* percent of optimized for complete unroll</div><div class=""><br class=""></div><div class="">I didn’t list an option 'unroll-max-iteration-count-to-analyze' here, because I don’t think anyone needs to tune it at all - it’s more for guarding the algorithm from doing too expensive analysis.</div><div class=""><br class=""></div><div class="">I do like an idea of simplifying this, but to me it looks that we’ll lose some cases if we just remove one of these thresholds - they cover very different areas. E.g. we can’t properly devise value for OptSize threshold from other thresholds. Similarly, it’s hard to get value for ‘absolute’ threshold from ‘usual’ threshold - the latter deals more with tiny loops, while the former is for unrolling big loops, where we can get a lot from consequent constant-folding. We can choose ‘one-fits-all’ value for e.g. the percent and remove the corresponding field from TTI, but I doubt that’ll help much here (we’ll still have the parameter in our model, it’ll just become hidden).</div><div class=""><br class=""></div><div class="">Having said that, I think that the names I chose for the new ones are not that good, and might be confusing (but I currently can’t come up with better ones). If you have a better idea for their names, or if you can suggest how can we simplify the overall scheme, I’d be happy to address it:)</div><div class=""><br class=""></div><div class="">Thanks,</div><div class="">Michael</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><div><blockquote type="cite" class=""><div class="">On Feb 9, 2015, at 1:02 PM, Eric Christopher <<a href="mailto:echristo@gmail.com" class="">echristo@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Drive by review questions:<br class=""><br class="">1) There are some uncomfortable tuning parameters here, can we figure out some better ideas using science?<div class="">2) There are also a huge number of tuning parameters for the pass and this is just adding more, what's up here?<div class=""><br class=""></div><div class="">In other words the pass is starting to look like a sea of options + TTI hell. :)</div><div class=""><br class=""></div><div class="">-eric</div><div class=""><br class=""></div><div class="gmail_quote">On Mon Feb 09 2015 at 12:53:59 PM Michael Zolotukhin <<a href="mailto:mzolotukhin@apple.com" target="_blank" class="">mzolotukhin@apple.com</a>> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Hal,<br class="">
<br class="">
Could you please take a look at the attached test? Does it cover the new features enough, or did I miss anything?<br class="">
<br class="">
<br class="">
<br class="">
<br class="">
Thanks,<br class="">
Michael<br class="">
<br class="">
> On Feb 6, 2015, at 12:31 PM, Hal Finkel <<a href="mailto:hfinkel@anl.gov" target="_blank" class="">hfinkel@anl.gov</a>> wrote:<br class="">
><br class="">
> As you stated in your follow-up e-mail ;) -- this needs a test case.<br class="">
><br class="">
> -Hal<br class="">
><br class="">
> ----- Original Message -----<br class="">
>> From: "Michael Zolotukhin" <<a href="mailto:mzolotukhin@apple.com" target="_blank" class="">mzolotukhin@apple.com</a>><br class="">
>> To: <a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank" class="">llvm-commits@cs.uiuc.edu</a><br class="">
>> Sent: Friday, February 6, 2015 2:20:40 PM<br class="">
>> Subject: [llvm] r228434 - Use estimated number of optimized insns in unroll-threshold computation.<br class="">
>><br class="">
>> Author: mzolotukhin<br class="">
>> Date: Fri Feb  6 14:20:40 2015<br class="">
>> New Revision: 228434<br class="">
>><br class="">
>> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=228434&view=rev" target="_blank" class="">http://llvm.org/viewvc/llvm-<u class=""></u>pr<u class=""></u>oject?rev=228434&view=rev</a><br class="">
>> Log:<br class="">
>> Use estimated number of optimized insns in unroll-threshold<br class="">
>> computation.<br class="">
>><br class="">
>> If complete-unroll could help us to optimize away N% of instructions,<br class="">
>> we<br class="">
>> might want to do this even if the final size would exceed loop-unroll<br class="">
>> threshold. However, we don't want to unroll huge loop, and we are add<br class="">
>> AbsoluteThreshold to avoid that - this threshold will never be<br class="">
>> crossed,<br class="">
>> even if we expect to optimize 99% instructions after that.<br class="">
>><br class="">
>> Modified:<br class="">
>>    llvm/trunk/include/llvm/<u class=""></u>Analys<u class=""></u>is/TargetTransformInfo.h<br class="">
>>    llvm/trunk/lib/Transforms/<u class=""></u>Scal<u class=""></u>ar/LoopUnrollPass.cpp<br class="">
>><br class="">
>> Modified: llvm/trunk/include/llvm/<u class=""></u>Analys<u class=""></u>is/TargetTransformInfo.h<br class="">
>> URL:<br class="">
>> <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/TargetTransformInfo.h?rev=228434&r1=228433&r2=228434&view=diff" target="_blank" class="">http://llvm.org/viewvc/llvm-<u class=""></u>pr<u class=""></u>oject/llvm/trunk/include/<u class=""></u>llvm/<u class=""></u>Analysis/<u class=""></u>TargetTransformInfo.<u class=""></u>h?rev=<u class=""></u>228434&r1=228433&r2=<u class=""></u>228434&<u class=""></u>view=diff</a><br class="">
>> ==============================<u class=""></u><u class=""></u>==============================<u class=""></u><u class=""></u>==================<br class="">
>> --- llvm/trunk/include/llvm/<u class=""></u>Analys<u class=""></u>is/TargetTransformInfo.h (original)<br class="">
>> +++ llvm/trunk/include/llvm/<u class=""></u>Analys<u class=""></u>is/TargetTransformInfo.h Fri Feb  6<br class="">
>> 14:20:40 2015<br class="">
>> @@ -217,6 +217,13 @@ public:<br class="">
>>     /// exceed this cost. Set this to UINT_MAX to disable the loop<br class="">
>>     body cost<br class="">
>>     /// restriction.<br class="">
>>     unsigned Threshold;<br class="">
>> +    /// If complete unrolling could help other optimizations (e.g.<br class="">
>> InstSimplify)<br class="">
>> +    /// to remove N% of instructions, then we can go beyond unroll<br class="">
>> threshold.<br class="">
>> +    /// This value set the minimal percent for allowing that.<br class="">
>> +    unsigned MinPercentOfOptimized;<br class="">
>> +    /// The absolute cost threshold. We won't go beyond this even if<br class="">
>> complete<br class="">
>> +    /// unrolling could result in optimizing out 90% of<br class="">
>> instructions.<br class="">
>> +    unsigned AbsoluteThreshold;<br class="">
>>     /// The cost threshold for the unrolled loop when optimizing for<br class="">
>>     size (set<br class="">
>>     /// to UINT_MAX to disable).<br class="">
>>     unsigned OptSizeThreshold;<br class="">
>><br class="">
>> Modified: llvm/trunk/lib/Transforms/<u class=""></u>Scal<u class=""></u>ar/LoopUnrollPass.cpp<br class="">
>> URL:<br class="">
>> <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopUnrollPass.cpp?rev=228434&r1=228433&r2=228434&view=diff" target="_blank" class="">http://llvm.org/viewvc/llvm-<u class=""></u>pr<u class=""></u>oject/llvm/trunk/lib/<u class=""></u>Transform<u class=""></u>s/Scalar/<u class=""></u>LoopUnrollPass.cpp?<u class=""></u>rev=228434&<u class=""></u>r1=228433&r2=<u class=""></u>228434&view=diff</a><br class="">
>> ==============================<u class=""></u><u class=""></u>==============================<u class=""></u><u class=""></u>==================<br class="">
>> --- llvm/trunk/lib/Transforms/<u class=""></u>Scal<u class=""></u>ar/LoopUnrollPass.cpp (original)<br class="">
>> +++ llvm/trunk/lib/Transforms/<u class=""></u>Scal<u class=""></u>ar/LoopUnrollPass.cpp Fri Feb  6<br class="">
>> 14:20:40 2015<br class="">
>> @@ -45,6 +45,17 @@ static cl::opt<unsigned> UnrollMaxIterat<br class="">
>>     cl::desc("Don't allow loop unrolling to simulate more than this<br class="">
>>     number of"<br class="">
>>              "iterations when checking full unroll profitability"));<br class="">
>><br class="">
>> +static cl::opt<unsigned> UnrollMinPercentOfOptimized(<br class="">
>> +    "unroll-percent-of-optimized-<u class=""></u>f<u class=""></u>or-complete-unroll", cl::init(20),<br class="">
>> cl::Hidden,<br class="">
>> +    cl::desc("If complete unrolling could trigger further<br class="">
>> optimizations, and, "<br class="">
>> +             "by that, remove the given percent of instructions,<br class="">
>> perform the "<br class="">
>> +             "complete unroll even if it's beyond the threshold"));<br class="">
>> +<br class="">
>> +static cl::opt<unsigned> UnrollAbsoluteThreshold(<br class="">
>> +    "unroll-absolute-threshold", cl::init(2000), cl::Hidden,<br class="">
>> +    cl::desc("Don't unroll if the unrolled size is bigger than this<br class="">
>> threshold,"<br class="">
>> +             " even if we can remove big portion of instructions<br class="">
>> later."));<br class="">
>> +<br class="">
>> static cl::opt<unsigned><br class="">
>> UnrollCount("unroll-count", cl::init(0), cl::Hidden,<br class="">
>>   cl::desc("Use this unroll count for all loops including those with<br class="">
>>   "<br class="">
>> @@ -70,11 +81,16 @@ namespace {<br class="">
>>     static char ID; // Pass ID, replacement for typeid<br class="">
>>     LoopUnroll(int T = -1, int C = -1, int P = -1, int R = -1) :<br class="">
>>     LoopPass(ID) {<br class="">
>>       CurrentThreshold = (T == -1) ? UnrollThreshold : unsigned(T);<br class="">
>> +      CurrentAbsoluteThreshold = UnrollAbsoluteThreshold;<br class="">
>> +      CurrentMinPercentOfOptimized = UnrollMinPercentOfOptimized;<br class="">
>>       CurrentCount = (C == -1) ? UnrollCount : unsigned(C);<br class="">
>>       CurrentAllowPartial = (P == -1) ? UnrollAllowPartial :<br class="">
>>       (bool)P;<br class="">
>>       CurrentRuntime = (R == -1) ? UnrollRuntime : (bool)R;<br class="">
>><br class="">
>>       UserThreshold = (T != -1) ||<br class="">
>>       (UnrollThreshold.<u class=""></u>getNumOccurr<u class=""></u>ences() > 0);<br class="">
>> +      UserAbsoluteThreshold =<br class="">
>> (UnrollAbsoluteThreshold.<u class=""></u>getNu<u class=""></u>mOccurrences() > 0);<br class="">
>> +      UserPercentOfOptimized =<br class="">
>> +          (UnrollMinPercentOfOptimized.<u class=""></u>g<u class=""></u>etNumOccurrences() > 0);<br class="">
>>       UserAllowPartial = (P != -1) ||<br class="">
>>                          (UnrollAllowPartial.<u class=""></u>getNumOccu<u class=""></u>rrences() ><br class="">
>>                          0);<br class="">
>>       UserRuntime = (R != -1) || (UnrollRuntime.<u class=""></u>getNumOccurrenc<u class=""></u>es()<br class="">
>>> 0);<br class="">
>> @@ -98,10 +114,16 @@ namespace {<br class="">
>><br class="">
>>     unsigned CurrentCount;<br class="">
>>     unsigned CurrentThreshold;<br class="">
>> +    unsigned CurrentAbsoluteThreshold;<br class="">
>> +    unsigned CurrentMinPercentOfOptimized;<br class="">
>>     bool     CurrentAllowPartial;<br class="">
>>     bool     CurrentRuntime;<br class="">
>>     bool     UserCount;            // CurrentCount is<br class="">
>>     user-specified.<br class="">
>>     bool     UserThreshold;        // CurrentThreshold is<br class="">
>>     user-specified.<br class="">
>> +    bool UserAbsoluteThreshold;    // CurrentAbsoluteThreshold is<br class="">
>> +                                   // user-specified.<br class="">
>> +    bool UserPercentOfOptimized;   // CurrentMinPercentOfOptimized<br class="">
>> is<br class="">
>> +                                   // user-specified.<br class="">
>>     bool     UserAllowPartial;     // CurrentAllowPartial is<br class="">
>>     user-specified.<br class="">
>>     bool     UserRuntime;          // CurrentRuntime is<br class="">
>>     user-specified.<br class="">
>><br class="">
>> @@ -133,6 +155,8 @@ namespace {<br class="">
>>     void getUnrollingPreferences(Loop *L, const TargetTransformInfo<br class="">
>>     &TTI,<br class="">
>>                                  TargetTransformInfo::<u class=""></u>Unrolling<u class=""></u>Preferences<br class="">
>>                                  &UP) {<br class="">
>>       UP.Threshold = CurrentThreshold;<br class="">
>> +      UP.AbsoluteThreshold = CurrentAbsoluteThreshold;<br class="">
>> +      UP.MinPercentOfOptimized = CurrentMinPercentOfOptimized;<br class="">
>>       UP.OptSizeThreshold = OptSizeUnrollThreshold;<br class="">
>>       UP.PartialThreshold = CurrentThreshold;<br class="">
>>       UP.PartialOptSizeThreshold = OptSizeUnrollThreshold;<br class="">
>> @@ -160,13 +184,32 @@ namespace {<br class="">
>>     void selectThresholds(const Loop *L, bool HasPragma,<br class="">
>>                           const<br class="">
>>                           TargetTransformInfo::<u class=""></u>Unrollin<u class=""></u>gPreferences<br class="">
>>                           &UP,<br class="">
>>                           unsigned &Threshold, unsigned<br class="">
>>                           &PartialThreshold,<br class="">
>> -                          unsigned NumberOfSimplifiedInstructions<u class=""></u><u class=""></u>) {<br class="">
>> +                          unsigned NumberOfOptimizedInstructions) {<br class="">
>>       // Determine the current unrolling threshold.  While this is<br class="">
>>       // normally set from UnrollThreshold, it is overridden to a<br class="">
>>       // smaller value if the current function is marked as<br class="">
>>       // optimize-for-size, and the unroll threshold was not user<br class="">
>>       // specified.<br class="">
>>       Threshold = UserThreshold ? CurrentThreshold : UP.Threshold;<br class="">
>> +<br class="">
>> +      // If we are allowed to completely unroll if we can remove M%<br class="">
>> of<br class="">
>> +      // instructions, and we know that with complete unrolling<br class="">
>> we'll be able<br class="">
>> +      // to kill N instructions, then we can afford to completely<br class="">
>> unroll loops<br class="">
>> +      // with unrolled size up to N*100/M.<br class="">
>> +      // Adjust the threshold according to that:<br class="">
>> +      unsigned PercentOfOptimizedForCompleteU<u class=""></u><u class=""></u>nroll =<br class="">
>> +          UserPercentOfOptimized ? CurrentMinPercentOfOptimized<br class="">
>> +                                 : UP.MinPercentOfOptimized;<br class="">
>> +      unsigned AbsoluteThreshold = UserAbsoluteThreshold<br class="">
>> +                                       ? CurrentAbsoluteThreshold<br class="">
>> +                                       : UP.AbsoluteThreshold;<br class="">
>> +      if (<u class=""></u>PercentOfOptimizedForComplete<u class=""></u>U<u class=""></u>nroll)<br class="">
>> +        Threshold = std::max<unsigned>(Threshold,<br class="">
>> +                                       NumberOfOptimizedInstructions<br class="">
>> * 100 /<br class="">
>> +<br class="">
>>                                          PercentOfOptimizedForCompleteU<u class=""></u><u class=""></u>nroll);<br class="">
>> +      // But don't allow unrolling loops bigger than absolute<br class="">
>> threshold.<br class="">
>> +      Threshold = std::min<unsigned>(Threshold, AbsoluteThreshold);<br class="">
>> +<br class="">
>>       PartialThreshold = UserThreshold ? CurrentThreshold :<br class="">
>>       UP.PartialThreshold;<br class="">
>>       if (!UserThreshold &&<br class="">
>>           L->getHeader()->getParent()-><u class=""></u><u class=""></u>getAttributes().<br class="">
>> @@ -186,7 +229,6 @@ namespace {<br class="">
>>           PartialThreshold =<br class="">
>>               std::max<unsigned>(<u class=""></u>PartialThr<u class=""></u>eshold,<br class="">
>>               PragmaUnrollThreshold);<br class="">
>>       }<br class="">
>> -      Threshold += NumberOfSimplifiedInstructions<u class=""></u><u class=""></u>;<br class="">
>>     }<br class="">
>>   };<br class="">
>> }<br class="">
>><br class="">
>><br class="">
>> ______________________________<u class=""></u><u class=""></u>_________________<br class="">
>> llvm-commits mailing list<br class="">
>> <a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank" class="">llvm-commits@cs.uiuc.edu</a><br class="">
>> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank" class="">http://lists.cs.uiuc.edu/<u class=""></u>mailm<u class=""></u>an/listinfo/llvm-commits</a><br class="">
>><br class="">
><br class="">
> --<br class="">
> Hal Finkel<br class="">
> Assistant Computational Scientist<br class="">
> Leadership Computing Facility<br class="">
> Argonne National Laboratory<br class="">
<br class="">
______________________________<u class=""></u><u class=""></u>_________________<br class="">
llvm-commits mailing list<br class="">
<a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank" class="">llvm-commits@cs.uiuc.edu</a><br class="">
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank" class="">http://lists.cs.uiuc.edu/<u class=""></u>mailm<u class=""></u>an/listinfo/llvm-commits</a><br class="">
</blockquote></div></div></div>
</div></blockquote></div><br class=""></div></body></html>