Hi Anastasiya, If it fits you use case, you can consider walking the loop header and calling getSCEV() on all of the PHI nodes in the header. This will give you a SCEV* which should be easier to analyze than manually inspecting PHI cycles. Thanks! -- Sanjoy On Tue, Jul 25, 2017 at 11:42 AM, Michael Kruse via llvm-dev <llvm-dev at lists.llvm.org> wrote:> 2017-07-25 19:32 GMT+02:00 Anastasiya Ruzhanskaya > <anastasiya.ruzhanskaya at frtk.ru>: >> I call this function and it returns only "i" in my example. Are there any >> ways to return "j" also? > > That would contradict it being the /canonical/ induction variable, wouldn't it? > > If you look into the imlplementation of > getCanonicalInductionVariable(), it just walks the IR instructions and > checks some conditions. You can have your own implementation that, > instead of returning the first matching PHI, return all matching PHIs. > SimplifyIndVar won't try to canonicalize, though. > > Michael > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Anastasiya Ruzhanskaya via llvm-dev
2017-Jul-26 07:24 UTC
[llvm-dev] loop canonical variables
Great, thanks a lot! 2017-07-25 23:48 GMT+02:00 Sanjoy Das <sanjoy at google.com>:> Hi Anastasiya, > > If it fits you use case, you can consider walking the loop header and > calling getSCEV() on all of the PHI nodes in the header. This will > give you a SCEV* which should be easier to analyze than manually > inspecting PHI cycles. > > Thanks! > -- Sanjoy > > > On Tue, Jul 25, 2017 at 11:42 AM, Michael Kruse via llvm-dev > <llvm-dev at lists.llvm.org> wrote: > > 2017-07-25 19:32 GMT+02:00 Anastasiya Ruzhanskaya > > <anastasiya.ruzhanskaya at frtk.ru>: > >> I call this function and it returns only "i" in my example. Are there > any > >> ways to return "j" also? > > > > That would contradict it being the /canonical/ induction variable, > wouldn't it? > > > > If you look into the imlplementation of > > getCanonicalInductionVariable(), it just walks the IR instructions and > > checks some conditions. You can have your own implementation that, > > instead of returning the first matching PHI, return all matching PHIs. > > SimplifyIndVar won't try to canonicalize, though. > > > > Michael > > _______________________________________________ > > LLVM Developers mailing list > > llvm-dev at lists.llvm.org > > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170726/5539c1d9/attachment.html>
Anastasiya Ruzhanskaya via llvm-dev
2017-Jul-26 11:44 UTC
[llvm-dev] loop canonical variables
Still, there a question: 1) does loop analysis always find only outermost loop? I can't make it finding all innermost ones (LoopInfo &LI getAnalysis<LoopInfoWrapperPass>().getLoopInfo()). With other means it is possible,but not so convenient; 2) is the trip count value determined only when there is one exit block (I have seen such assert in code, but maybe there are other functions, that can overcome this difficulty)? In this example I have not fully optimized version but still I can't be sure that this will not happen even after full optimization pass: define i32 @main() #0 { br label %1 ; <label>:1 ; preds = %0, %4 %i.03 = phi i32 [ 0, %0 ], [ %5, %4 ] %a.02 = phi i32 [ 0, %0 ], [ %2, %4 ] %2 = add i32 %a.02, %i.03 %3 = icmp sgt i32 %i.03, 7 br i1 %3, label %.loopexit, label %4 ; <label>:4 ; preds = %1 %5 = add nsw i32 %i.03, 1 %6 = icmp ne i32 %5, 10 br i1 %6, label %1, label %.loopexit .loopexit: ; preds = %4, %1 %a.1 = phi i32 [ %2, %1 ], [ %2, %4 ] ret i32 %a.1 } the c code unsigned a = 0; for (int i = 0; i != 10; i++) { a+=i; if (i > 7) break; } return a; of course if I will apply instcombine with indvars passes, then it will look more logical, but anyway the loop trip count here is 7 , not 10, not 0 ( the max number we can enter the loop). But it can't be determined with the help of information from ScalarEvolution. 2017-07-26 9:24 GMT+02:00 Anastasiya Ruzhanskaya < anastasiya.ruzhanskaya at frtk.ru>:> Great, thanks a lot! > > 2017-07-25 23:48 GMT+02:00 Sanjoy Das <sanjoy at google.com>: > >> Hi Anastasiya, >> >> If it fits you use case, you can consider walking the loop header and >> calling getSCEV() on all of the PHI nodes in the header. This will >> give you a SCEV* which should be easier to analyze than manually >> inspecting PHI cycles. >> >> Thanks! >> -- Sanjoy >> >> >> On Tue, Jul 25, 2017 at 11:42 AM, Michael Kruse via llvm-dev >> <llvm-dev at lists.llvm.org> wrote: >> > 2017-07-25 19:32 GMT+02:00 Anastasiya Ruzhanskaya >> > <anastasiya.ruzhanskaya at frtk.ru>: >> >> I call this function and it returns only "i" in my example. Are there >> any >> >> ways to return "j" also? >> > >> > That would contradict it being the /canonical/ induction variable, >> wouldn't it? >> > >> > If you look into the imlplementation of >> > getCanonicalInductionVariable(), it just walks the IR instructions and >> > checks some conditions. You can have your own implementation that, >> > instead of returning the first matching PHI, return all matching PHIs. >> > SimplifyIndVar won't try to canonicalize, though. >> > >> > Michael >> > _______________________________________________ >> > LLVM Developers mailing list >> > llvm-dev at lists.llvm.org >> > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >> > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170726/b0d35ace/attachment.html>