llvm.org GIT mirror llvm / 9870934
Revert "[SCEV] Clarify behavior around max backedge taken count" This reverts commit r303497 since it breaks the msan bootstrap bot: http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-bootstrap/builds/1379/ git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@303498 91177308-0d34-0410-b5e6-96231b3b80d8 Sanjoy Das 2 years ago
4 changed file(s) with 27 addition(s) and 58 deletion(s). Raw diff Collapse all Expand all
655655 /// Test whether this BackedgeTakenInfo contains complete information.
656656 bool hasFullInfo() const { return isComplete(); }
657657
658 /// Return an expression indicating the exact *backedge-taken*
659 /// count of the loop if it is known or SCEVCouldNotCompute
660 /// otherwise. If execution makes it to the backedge on every
661 /// iteration (i.e. there are no abnormal exists like exception
662 /// throws and thread exits) then this is the number of times the
663 /// loop header will execute minus one.
658 /// Return an expression indicating the exact backedge-taken count of the
659 /// loop if it is known or SCEVCouldNotCompute otherwise. This is the
660 /// number of times the loop header can be guaranteed to execute, minus
661 /// one.
664662 ///
665663 /// If the SCEV predicate associated with the answer can be different
666664 /// from AlwaysTrue, we must add a (non null) Predicates argument.
13991397 const SCEV *getExitCount(const Loop *L, BasicBlock *ExitingBlock);
14001398
14011399 /// If the specified loop has a predictable backedge-taken count, return it,
1402 /// otherwise return a SCEVCouldNotCompute object. The backedge-taken count is
1403 /// the number of times the loop header will be branched to from within the
1404 /// loop, assuming there are no abnormal exists like exception throws. This is
1405 /// one less than the trip count of the loop, since it doesn't count the first
1406 /// iteration, when the header is branched to from outside the loop.
1400 /// otherwise return a SCEVCouldNotCompute object. The backedge-taken count
1401 /// is the number of times the loop header will be branched to from within
1402 /// the loop. This is one less than the trip count of the loop, since it
1403 /// doesn't count the first iteration, when the header is branched to from
1404 /// outside the loop.
14071405 ///
14081406 /// Note that it is not valid to call this method on a loop without a
14091407 /// loop-invariant backedge-taken count (see
14181416 const SCEV *getPredicatedBackedgeTakenCount(const Loop *L,
14191417 SCEVUnionPredicate &Predicates);
14201418
1421 /// When successful, this returns a SCEVConstant that is greater than or equal
1422 /// to (i.e. a "conservative over-approximation") of the value returend by
1423 /// getBackedgeTakenCount. If such a value cannot be computed, it returns the
1424 /// SCEVCouldNotCompute object.
1419 /// Similar to getBackedgeTakenCount, except return the least SCEV value
1420 /// that is known never to be less than the actual backedge taken count.
14251421 const SCEV *getMaxBackedgeTakenCount(const Loop *L);
14261422
14271423 /// Return true if the backedge taken count is either the value returned by
59465946 if (any_of(ExitNotTaken, PredicateNotAlwaysTrue) || !getMax())
59475947 return SE->getCouldNotCompute();
59485948
5949 assert((isa(getMax()) || isa(getMax())) &&
5950 "No point in having a non-constant max backedge taken count!");
59515949 return getMax();
59525950 }
59535951
59735971 }
59745972
59755973 ScalarEvolution::ExitLimit::ExitLimit(const SCEV *E)
5976 : ExactNotTaken(E), MaxNotTaken(E), MaxOrZero(false) {
5977 assert((isa(MaxNotTaken) ||
5978 isa(MaxNotTaken)) &&
5979 "No point in having a non-constant max backedge taken count!");
5980 }
5974 : ExactNotTaken(E), MaxNotTaken(E), MaxOrZero(false) {}
59815975
59825976 ScalarEvolution::ExitLimit::ExitLimit(
59835977 const SCEV *E, const SCEV *M, bool MaxOrZero,
59865980 assert((isa(ExactNotTaken) ||
59875981 !isa(MaxNotTaken)) &&
59885982 "Exact is not allowed to be less precise than Max");
5989 assert((isa(MaxNotTaken) ||
5990 isa(MaxNotTaken)) &&
5991 "No point in having a non-constant max backedge taken count!");
59925983 for (auto *PredSet : PredSetList)
59935984 for (auto *P : *PredSet)
59945985 addPredicate(P);
59975988 ScalarEvolution::ExitLimit::ExitLimit(
59985989 const SCEV *E, const SCEV *M, bool MaxOrZero,
59995990 const SmallPtrSetImpl &PredSet)
6000 : ExitLimit(E, M, MaxOrZero, {&PredSet}) {
6001 assert((isa(MaxNotTaken) ||
6002 isa(MaxNotTaken)) &&
6003 "No point in having a non-constant max backedge taken count!");
6004 }
5991 : ExitLimit(E, M, MaxOrZero, {&PredSet}) {}
60055992
60065993 ScalarEvolution::ExitLimit::ExitLimit(const SCEV *E, const SCEV *M,
60075994 bool MaxOrZero)
6008 : ExitLimit(E, M, MaxOrZero, None) {
6009 assert((isa(MaxNotTaken) ||
6010 isa(MaxNotTaken)) &&
6011 "No point in having a non-constant max backedge taken count!");
6012 }
5995 : ExitLimit(E, M, MaxOrZero, None) {}
60135996
60145997 /// Allocate memory for BackedgeTakenInfo and copy the not-taken count of each
60155998 /// computable exit into a persistent ExitNotTakenInfo array.
60346017
60356018 return ExitNotTakenInfo(ExitBB, EL.ExactNotTaken, std::move(Predicate));
60366019 });
6037 assert((isa(MaxCount) || isa(MaxCount)) &&
6038 "No point in having a non-constant max backedge taken count!");
60396020 }
60406021
60416022 /// Invalidate this result and free the ExitNotTakenInfo array.
62976278 // to not.
62986279 if (isa(MaxBECount) &&
62996280 !isa(BECount))
6300 MaxBECount = getConstant(getUnsignedRange(BECount).getUnsignedMax());
6281 MaxBECount = BECount;
63016282
63026283 return ExitLimit(BECount, MaxBECount, false,
63036284 {&EL0.Predicates, &EL1.Predicates});
76017582 loopHasNoAbnormalExits(AddRec->getLoop())) {
76027583 const SCEV *Exact =
76037584 getUDivExpr(Distance, CountDown ? getNegativeSCEV(Step) : Step);
7604 const SCEV *Max =
7605 Exact == getCouldNotCompute()
7606 ? Exact
7607 : getConstant(getUnsignedRange(Exact).getUnsignedMax());
7608 return ExitLimit(Exact, Max, false, Predicates);
7585 return ExitLimit(Exact, Exact, false, Predicates);
76097586 }
76107587
76117588 // Solve the general equation.
7612 const SCEV *E = SolveLinEquationWithOverflow(StepC->getAPInt(),
7613 getNegativeSCEV(Start), *this);
7614 const SCEV *M = E == getCouldNotCompute()
7615 ? E
7616 : getConstant(getUnsignedRange(E).getUnsignedMax());
7617 return ExitLimit(E, M, false, Predicates);
7589 const SCEV *E = SolveLinEquationWithOverflow(
7590 StepC->getAPInt(), getNegativeSCEV(Start), *this);
7591 return ExitLimit(E, E, false, Predicates);
76187592 }
76197593
76207594 ScalarEvolution::ExitLimit
92439217 getConstant(StrideForMaxBECount), false);
92449218 }
92459219
9246 if (isa(MaxBECount) &&
9247 !isa(BECount))
9248 MaxBECount = getConstant(getUnsignedRange(BECount).getUnsignedMax());
9220 if (isa(MaxBECount))
9221 MaxBECount = BECount;
92499222
92509223 return ExitLimit(BECount, MaxBECount, MaxOrZero, Predicates);
92519224 }
101101 %cmp.i.i = icmp eq i32* %ptrincdec.i.i, %end
102102 br i1 %cmp.i.i, label %_ZSt4fillIPiiEvT_S1_RKT0_.exit, label %for.body.i.i
103103 ; CHECK: Loop %for.body.i.i: backedge-taken count is ((-4 + (-1 * %begin) + %end) /u 4)
104 ; CHECK: Loop %for.body.i.i: max backedge-taken count is 4611686018427387903
104 ; CHECK: Loop %for.body.i.i: max backedge-taken count is ((-4 + (-1 * %begin) + %end) /u 4)
105105 _ZSt4fillIPiiEvT_S1_RKT0_.exit: ; preds = %for.body.i.i, %entry
106106 ret void
107107 }
1313
1414 ; CHECK-LABEL: @test1
1515 ; CHECK: Loop %loop: backedge-taken count is ((-32 + (96 * %n)) /u 32)
16 ; CHECK: Loop %loop: max backedge-taken count is 134217727
16 ; CHECK: Loop %loop: max backedge-taken count is ((-32 + (96 * %n)) /u 32)
1717 }
1818
1919 ; PR19183
3131
3232 ; CHECK-LABEL: @test2
3333 ; CHECK: Loop %loop: backedge-taken count is ((-32 + (32 * (%n /u 32))) /u 32)
34 ; CHECK: Loop %loop: max backedge-taken count is 134217727
34 ; CHECK: Loop %loop: max backedge-taken count is ((-32 + (32 * (%n /u 32))) /u 32)
3535 }
3636
3737 define void @test3(i32 %n) {
4848
4949 ; CHECK-LABEL: @test3
5050 ; CHECK: Loop %loop: backedge-taken count is ((-32 + (32 * %n)) /u 32)
51 ; CHECK: Loop %loop: max backedge-taken count is 134217727
51 ; CHECK: Loop %loop: max backedge-taken count is ((-32 + (32 * %n)) /u 32)
5252 }
5353
5454 define void @test4(i32 %n) {
6565
6666 ; CHECK-LABEL: @test4
6767 ; CHECK: Loop %loop: backedge-taken count is ((-4 + (-1431655764 * %n)) /u 4)
68 ; CHECK: Loop %loop: max backedge-taken count is 1073741823
68 ; CHECK: Loop %loop: max backedge-taken count is ((-4 + (-1431655764 * %n)) /u 4)
6969 }
7070
7171 define void @test5(i32 %n) {
8282
8383 ; CHECK-LABEL: @test5
8484 ; CHECK: Loop %loop: backedge-taken count is ((-4 + (4 * %n)) /u 4)
85 ; CHECK: Loop %loop: max backedge-taken count is 1073741823
85 ; CHECK: Loop %loop: max backedge-taken count is ((-4 + (4 * %n)) /u 4)
8686 }