@@ -933,15 +933,20 @@ void State::addInfoForInductions(BasicBlock &BB) {
933
933
}
934
934
935
935
DomTreeNode *DTN = DT.getNode (InLoopSucc);
936
- auto Inc = SE.getMonotonicPredicateType (AR, CmpInst::ICMP_UGT);
937
- bool MonotonicallyIncreasing =
938
- Inc && *Inc == ScalarEvolution::MonotonicallyIncreasing;
939
- if (MonotonicallyIncreasing) {
940
- // SCEV guarantees that AR does not wrap, so PN >= StartValue can be added
941
- // unconditionally.
936
+ auto IncUnsigned = SE.getMonotonicPredicateType (AR, CmpInst::ICMP_UGT);
937
+ auto IncSigned = SE.getMonotonicPredicateType (AR, CmpInst::ICMP_SGT);
938
+ bool MonotonicallyIncreasingUnsigned =
939
+ IncUnsigned && *IncUnsigned == ScalarEvolution::MonotonicallyIncreasing;
940
+ bool MonotonicallyIncreasingSigned =
941
+ IncSigned && *IncSigned == ScalarEvolution::MonotonicallyIncreasing;
942
+ // If SCEV guarantees that AR does not wrap, PN >= StartValue can be added
943
+ // unconditionally.
944
+ if (MonotonicallyIncreasingUnsigned)
942
945
WorkList.push_back (
943
946
FactOrCheck::getConditionFact (DTN, CmpInst::ICMP_UGE, PN, StartValue));
944
- }
947
+ if (MonotonicallyIncreasingSigned)
948
+ WorkList.push_back (
949
+ FactOrCheck::getConditionFact (DTN, CmpInst::ICMP_SGE, PN, StartValue));
945
950
946
951
APInt StepOffset;
947
952
if (auto *C = dyn_cast<SCEVConstant>(AR->getStepRecurrence (SE)))
@@ -965,11 +970,17 @@ void State::addInfoForInductions(BasicBlock &BB) {
965
970
WorkList.push_back (FactOrCheck::getConditionFact (
966
971
DTN, CmpInst::ICMP_UGE, StartValue, PN,
967
972
ConditionTy (CmpInst::ICMP_ULE, B, StartValue)));
973
+ WorkList.push_back (FactOrCheck::getConditionFact (
974
+ DTN, CmpInst::ICMP_SGE, StartValue, PN,
975
+ ConditionTy (CmpInst::ICMP_SLE, B, StartValue)));
968
976
// Add PN > B conditional on B <= StartValue which guarantees that the loop
969
977
// exits when reaching B with a step of -1.
970
978
WorkList.push_back (FactOrCheck::getConditionFact (
971
979
DTN, CmpInst::ICMP_UGT, PN, B,
972
980
ConditionTy (CmpInst::ICMP_ULE, B, StartValue)));
981
+ WorkList.push_back (FactOrCheck::getConditionFact (
982
+ DTN, CmpInst::ICMP_SGT, PN, B,
983
+ ConditionTy (CmpInst::ICMP_SLE, B, StartValue)));
973
984
return ;
974
985
}
975
986
@@ -990,14 +1001,21 @@ void State::addInfoForInductions(BasicBlock &BB) {
990
1001
// AR may wrap. Add PN >= StartValue conditional on StartValue <= B which
991
1002
// guarantees that the loop exits before wrapping in combination with the
992
1003
// restrictions on B and the step above.
993
- if (!MonotonicallyIncreasing) {
1004
+ if (!MonotonicallyIncreasingUnsigned)
994
1005
WorkList.push_back (FactOrCheck::getConditionFact (
995
1006
DTN, CmpInst::ICMP_UGE, PN, StartValue,
996
1007
ConditionTy (CmpInst::ICMP_ULE, StartValue, B)));
997
- }
1008
+ if (!MonotonicallyIncreasingSigned)
1009
+ WorkList.push_back (FactOrCheck::getConditionFact (
1010
+ DTN, CmpInst::ICMP_SGE, PN, StartValue,
1011
+ ConditionTy (CmpInst::ICMP_SLE, StartValue, B)));
1012
+
998
1013
WorkList.push_back (FactOrCheck::getConditionFact (
999
1014
DTN, CmpInst::ICMP_ULT, PN, B,
1000
1015
ConditionTy (CmpInst::ICMP_ULE, StartValue, B)));
1016
+ WorkList.push_back (FactOrCheck::getConditionFact (
1017
+ DTN, CmpInst::ICMP_SLT, PN, B,
1018
+ ConditionTy (CmpInst::ICMP_SLE, StartValue, B)));
1001
1019
}
1002
1020
1003
1021
void State::addInfoFor (BasicBlock &BB) {
0 commit comments