llvm.org GIT mirror
[Loop Predication] Teach LP about reverse loops with uge and sge latch conditions Add support of uge and sge latch condition to Loop Prediction for reverse loops. Reviewers: apilipenko, mkazantsev, sanjoy, anna Reviewed By: anna Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D42837 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@324589 91177308-0d34-0410-b5e6-96231b3b80d8 Serguei Katkov 1 year, 7 months ago
2 changed file(s) with 113 addition(s) and 5 deletion(s).
 154 154 // When S = -1 (i.e. reverse iterating loop), the transformation is supported 155 155 // when: 156 156 // * The loop has a single latch with the condition of the form: 157 // B(X) = X latchLimit, where is u> or s>.⏎ 157 // B(X) = X latchLimit, where is u>, u>=, s>, or s>=.⏎ 158 158 // * The guard condition is of the form 159 159 // G(X) = X - 1 u< guardLimit 160 160 // 170 170 // guardStart u< guardLimit && latchLimit u>= 1. 171 171 // Similarly for sgt condition the widened condition is: 172 172 // guardStart u< guardLimit && latchLimit s>= 1. 173 // For uge condition the widened condition is: 174 // guardStart u< guardLimit && latchLimit u> 1. 175 // For sge condition the widened condition is: 176 // guardStart u< guardLimit && latchLimit s> 1. 173 177 //===----------------------------------------------------------------------===// 174 178 175 179 #include "llvm/Transforms/Scalar/LoopPredication.h" 484 488 // latchLimit 1. 485 489 // See the header comment for reasoning of the checks. 486 490 Instruction *InsertAt = Preheader->getTerminator(); 487 auto LimitCheckPred = ICmpInst::isSigned(LatchCheck.Pred) 488 ? ICmpInst::ICMP_SGE 489 : ICmpInst::ICMP_UGE;⏎ 491 auto LimitCheckPred = getLatchPredicateForGuard(LatchCheck.Pred);⏎ 490 492 auto *FirstIterationCheck = expandCheck(Expander, Builder, ICmpInst::ICMP_ULT, 491 493 GuardStart, GuardLimit, InsertAt); 492 494 auto *LimitCheck = expandCheck(Expander, Builder, LimitCheckPred, LatchLimit, 670 672 Pred != ICmpInst::ICMP_ULE && Pred != ICmpInst::ICMP_SLE; 671 673 } else { 672 674 assert(Step->isAllOnesValue() && "Step should be -1!"); 673 return Pred != ICmpInst::ICMP_UGT && Pred != ICmpInst::ICMP_SGT;⏎ 675 return Pred != ICmpInst::ICMP_UGT && Pred != ICmpInst::ICMP_SGT &&⏎ 676 Pred != ICmpInst::ICMP_UGE && Pred != ICmpInst::ICMP_SGE; 674 677 } 675 678 }; 676 679