68TEST(ScalarEvolutionTests, InductionVariable)
76 const auto & graph = rvsdgModule.
Rvsdg();
78 const auto & c0 = IntegerConstantOperation::Create(graph.GetRootRegion(), 32, 0);
79 const auto &
c2 = IntegerConstantOperation::Create(graph.GetRootRegion(), 32, 2);
82 const auto lv1 = theta->AddLoopVar(c0.output(0));
83 const auto lv2 = theta->AddLoopVar(
c2.output(0));
85 const auto &
c1 = IntegerConstantOperation::Create(*theta->subregion(), 32, 1);
87 const auto result = addNode.output(0);
89 const auto & c5 = IntegerConstantOperation::Create(*theta->subregion(), 32, 5);
91 const auto matchResult =
94 theta->set_predicate(matchResult);
95 lv1.post->divert_to(result);
103 EXPECT_NE(chrecMap.find(lv1.pre), chrecMap.end());
104 EXPECT_NE(chrecMap.find(lv2.pre), chrecMap.end());
108 lv1TestChrec.AddOperand(SCEVConstant::Create(0));
109 lv1TestChrec.AddOperand(SCEVConstant::Create(1));
110 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv1TestChrec, *chrecMap.at(lv1.pre)));
114 lv2TestChrec.AddOperand(SCEVConstant::Create(2));
115 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv2TestChrec, *chrecMap.at(lv2.pre)));
118TEST(ScalarEvolutionTests, RecursiveInductionVariable)
126 const auto & graph = rvsdgModule.
Rvsdg();
128 const auto & c0 = IntegerConstantOperation::Create(graph.GetRootRegion(), 32, 0);
129 const auto & c4 = IntegerConstantOperation::Create(graph.GetRootRegion(), 32, 4);
132 const auto lv1 = theta->AddLoopVar(c0.output(0));
133 const auto lv2 = theta->AddLoopVar(c4.output(0));
135 const auto &
c1 = IntegerConstantOperation::Create(*theta->subregion(), 32, 1);
137 const auto res1 = addNode.output(0);
139 const auto & c5 = IntegerConstantOperation::Create(*theta->subregion(), 32, 5);
141 const auto matchResult =
144 const auto &
c2 = IntegerConstantOperation::Create(*theta->subregion(), 32, 2);
146 const auto res2 = addNode2.output(0);
148 const auto & c3 = IntegerConstantOperation::Create(*theta->subregion(), 32, 3);
150 const auto res3 = addNode3.output(0);
152 theta->set_predicate(matchResult);
153 lv1.post->divert_to(res1);
154 lv2.post->divert_to(res3);
162 EXPECT_NE(chrecMap.find(lv1.pre), chrecMap.end());
163 EXPECT_NE(chrecMap.find(lv2.pre), chrecMap.end());
167 lv1TestChrec.AddOperand(SCEVConstant::Create(0));
168 lv1TestChrec.AddOperand(SCEVConstant::Create(1));
169 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv1TestChrec, *chrecMap.at(lv1.pre)));
173 lv2TestChrec.AddOperand(SCEVConstant::Create(4));
174 lv2TestChrec.AddOperand(SCEVConstant::Create(5));
175 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv2TestChrec, *chrecMap.at(lv2.pre)));
178TEST(ScalarEvolutionTests, PolynomialInductionVariable)
186 const auto & graph = rvsdgModule.
Rvsdg();
188 const auto & c0 = IntegerConstantOperation::Create(graph.GetRootRegion(), 32, 0);
189 const auto &
c2 = IntegerConstantOperation::Create(graph.GetRootRegion(), 32, 2);
192 const auto lv1 = theta->AddLoopVar(c0.output(0));
193 const auto lv2 = theta->AddLoopVar(
c2.output(0));
195 const auto &
c1 = IntegerConstantOperation::Create(*theta->subregion(), 32, 1);
197 const auto res1 = addNode.output(0);
199 const auto & c5 = IntegerConstantOperation::Create(*theta->subregion(), 32, 5);
201 const auto matchResult =
205 const auto res2 = addNode2.output(0);
207 theta->set_predicate(matchResult);
208 lv1.post->divert_to(res1);
209 lv2.post->divert_to(res2);
217 EXPECT_NE(chrecMap.find(lv1.pre), chrecMap.end());
218 EXPECT_NE(chrecMap.find(lv2.pre), chrecMap.end());
222 lv1TestChrec.AddOperand(SCEVConstant::Create(0));
223 lv1TestChrec.AddOperand(SCEVConstant::Create(1));
224 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv1TestChrec, *chrecMap.at(lv1.pre)));
229 lv2TestChrec.AddOperand(SCEVConstant::Create(2));
230 lv2TestChrec.AddOperand(SCEVConstant::Create(1));
231 lv2TestChrec.AddOperand(SCEVConstant::Create(1));
232 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv2TestChrec, *chrecMap.at(lv2.pre)));
235TEST(ScalarEvolutionTests, ThirdDegreePolynomialInductionVariable)
243 const auto & graph = rvsdgModule.
Rvsdg();
245 const auto &
c2 = IntegerConstantOperation::Create(graph.GetRootRegion(), 32, 2);
246 const auto & c3 = IntegerConstantOperation::Create(graph.GetRootRegion(), 32, 3);
247 const auto & c4 = IntegerConstantOperation::Create(graph.GetRootRegion(), 32, 4);
250 const auto lv1 = theta->AddLoopVar(
c2.output(0));
251 const auto lv2 = theta->AddLoopVar(c3.output(0));
252 const auto lv3 = theta->AddLoopVar(c4.output(0));
254 const auto &
c1 = IntegerConstantOperation::Create(*theta->subregion(), 32, 1);
257 const auto result_1 = addNode_1.output(0);
260 const auto result_2 = addNode_2.output(0);
263 const auto result_3 = addNode_3.output(0);
265 const auto & c5 = IntegerConstantOperation::Create(*theta->subregion(), 32, 5);
267 const auto matchResult =
270 theta->set_predicate(matchResult);
271 lv1.post->divert_to(result_1);
272 lv2.post->divert_to(result_2);
273 lv3.post->divert_to(result_3);
281 EXPECT_NE(chrecMap.find(lv1.pre), chrecMap.end());
282 EXPECT_NE(chrecMap.find(lv2.pre), chrecMap.end());
283 EXPECT_NE(chrecMap.find(lv3.pre), chrecMap.end());
287 lv1TestChrec.AddOperand(SCEVConstant::Create(2));
288 lv1TestChrec.AddOperand(SCEVConstant::Create(1));
289 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv1TestChrec, *chrecMap.at(lv1.pre)));
293 lv2TestChrec.AddOperand(SCEVConstant::Create(3));
294 lv2TestChrec.AddOperand(SCEVConstant::Create(2));
295 lv2TestChrec.AddOperand(SCEVConstant::Create(1));
296 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv2TestChrec, *chrecMap.at(lv2.pre)));
301 lv3TestChrec.AddOperand(SCEVConstant::Create(4));
302 lv3TestChrec.AddOperand(SCEVConstant::Create(3));
303 lv3TestChrec.AddOperand(SCEVConstant::Create(2));
304 lv3TestChrec.AddOperand(SCEVConstant::Create(1));
305 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv3TestChrec, *chrecMap.at(lv3.pre)));
308TEST(ScalarEvolutionTests, InductionVariableWithMultiplication)
316 const auto & graph = rvsdgModule.
Rvsdg();
318 const auto & c0 = IntegerConstantOperation::Create(graph.GetRootRegion(), 32, 0);
319 const auto &
c2 = IntegerConstantOperation::Create(graph.GetRootRegion(), 32, 2);
322 const auto lv1 = theta->AddLoopVar(c0.output(0));
323 const auto lv2 = theta->AddLoopVar(
c2.output(0));
325 const auto &
c1 = IntegerConstantOperation::Create(*theta->subregion(), 32, 1);
327 auto res1 = addNode1.output(0);
329 const auto & c3 = IntegerConstantOperation::Create(*theta->subregion(), 32, 3);
334 auto res2 = addNode2.output(0);
336 const auto & c5 = IntegerConstantOperation::Create(*theta->subregion(), 32, 5);
338 const auto matchResult =
341 theta->set_predicate(matchResult);
342 lv1.post->divert_to(res1);
343 lv2.post->divert_to(res2);
351 EXPECT_NE(chrecMap.find(lv1.pre), chrecMap.end());
352 EXPECT_NE(chrecMap.find(lv2.pre), chrecMap.end());
356 lv1TestChrec.AddOperand(SCEVConstant::Create(0));
357 lv1TestChrec.AddOperand(SCEVConstant::Create(1));
358 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv1TestChrec, *chrecMap.at(lv1.pre)));
363 lv2TestChrec.AddOperand(SCEVConstant::Create(2));
364 lv2TestChrec.AddOperand(SCEVConstant::Create(3));
365 lv2TestChrec.AddOperand(SCEVConstant::Create(3));
366 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv2TestChrec, *chrecMap.at(lv2.pre)));
411TEST(ScalarEvolutionTests, MultiplicationOfTwoAffineChrecs)
419 const auto & graph = rvsdgModule.
Rvsdg();
421 const auto & c0 = IntegerConstantOperation::Create(graph.GetRootRegion(), 32, 0);
422 const auto & c3 = IntegerConstantOperation::Create(graph.GetRootRegion(), 32, 3);
425 const auto lv1 = theta->AddLoopVar(c0.output(0));
426 const auto lv2 = theta->AddLoopVar(c3.output(0));
428 const auto &
c1 = IntegerConstantOperation::Create(*theta->subregion(), 32, 1);
430 auto res1 = addNode1.output(0);
436 auto res2 = addNode2.output(0);
438 const auto & c5 = IntegerConstantOperation::Create(*theta->subregion(), 32, 5);
440 const auto matchResult =
443 theta->set_predicate(matchResult);
444 lv1.post->divert_to(res1);
445 lv2.post->divert_to(res2);
453 EXPECT_NE(chrecMap.find(lv1.pre), chrecMap.end());
454 EXPECT_NE(chrecMap.find(lv2.pre), chrecMap.end());
458 lv1TestChrec.AddOperand(SCEVConstant::Create(0));
459 lv1TestChrec.AddOperand(SCEVConstant::Create(1));
460 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv1TestChrec, *chrecMap.at(lv1.pre)));
465 lv2TestChrec.AddOperand(SCEVConstant::Create(3));
466 lv2TestChrec.AddOperand(SCEVConstant::Create(0));
467 lv2TestChrec.AddOperand(SCEVConstant::Create(1));
468 lv2TestChrec.AddOperand(SCEVConstant::Create(2));
469 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv2TestChrec, *chrecMap.at(lv2.pre)));
472TEST(ScalarEvolutionTests, MultiplicationOfTwoQuadraticChrecs)
480 const auto & graph = rvsdgModule.
Rvsdg();
482 const auto & c0 = IntegerConstantOperation::Create(graph.GetRootRegion(), 32, 0);
483 const auto & c1_1 = IntegerConstantOperation::Create(graph.GetRootRegion(), 32, 1);
484 const auto &
c2 = IntegerConstantOperation::Create(graph.GetRootRegion(), 32, 2);
487 const auto lv1 = theta->AddLoopVar(c0.output(0));
488 const auto lv2 = theta->AddLoopVar(c1_1.output(0));
489 const auto lv3 = theta->AddLoopVar(
c2.output(0));
491 const auto & c1_2 = IntegerConstantOperation::Create(*theta->subregion(), 32, 1);
493 auto res1 = addNode1.output(0);
496 auto res2 = addNode2.output(0);
501 auto res3 = addNode3.output(0);
503 const auto & c5 = IntegerConstantOperation::Create(*theta->subregion(), 32, 5);
505 const auto matchResult =
508 theta->set_predicate(matchResult);
509 lv1.post->divert_to(res1);
510 lv2.post->divert_to(res2);
511 lv3.post->divert_to(res3);
519 EXPECT_NE(chrecMap.find(lv1.pre), chrecMap.end());
520 EXPECT_NE(chrecMap.find(lv2.pre), chrecMap.end());
521 EXPECT_NE(chrecMap.find(lv3.pre), chrecMap.end());
525 lv1TestChrec.AddOperand(SCEVConstant::Create(0));
526 lv1TestChrec.AddOperand(SCEVConstant::Create(1));
527 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv1TestChrec, *chrecMap.at(lv1.pre)));
531 lv2TestChrec.AddOperand(SCEVConstant::Create(1));
532 lv2TestChrec.AddOperand(SCEVConstant::Create(0));
533 lv2TestChrec.AddOperand(SCEVConstant::Create(1));
534 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv2TestChrec, *chrecMap.at(lv2.pre)));
539 lv3TestChrec.AddOperand(SCEVConstant::Create(2));
540 lv3TestChrec.AddOperand(SCEVConstant::Create(1));
541 lv3TestChrec.AddOperand(SCEVConstant::Create(0));
542 lv3TestChrec.AddOperand(SCEVConstant::Create(3));
543 lv3TestChrec.AddOperand(SCEVConstant::Create(6));
544 lv3TestChrec.AddOperand(SCEVConstant::Create(6));
545 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv3TestChrec, *chrecMap.at(lv3.pre)));
548TEST(ScalarEvolutionTests, InvalidPolynomialInductionVariableWithMultiplication)
556 const auto & graph = rvsdgModule.
Rvsdg();
558 const auto & c0 = IntegerConstantOperation::Create(graph.GetRootRegion(), 32, 0);
559 const auto & c3 = IntegerConstantOperation::Create(graph.GetRootRegion(), 32, 3);
562 const auto lv1 = theta->AddLoopVar(c0.output(0));
563 const auto lv2 = theta->AddLoopVar(c3.output(0));
565 const auto &
c1 = IntegerConstantOperation::Create(*theta->subregion(), 32, 1);
567 auto res1 = addNode1.output(0);
569 const auto &
c2 = IntegerConstantOperation::Create(*theta->subregion(), 32, 1);
573 const auto res2 = mulNode.output(0);
575 const auto & c5 = IntegerConstantOperation::Create(*theta->subregion(), 32, 5);
577 const auto matchResult =
580 theta->set_predicate(matchResult);
581 lv1.post->divert_to(res1);
582 lv2.post->divert_to(res2);
590 EXPECT_NE(chrecMap.find(lv1.pre), chrecMap.end());
591 EXPECT_NE(chrecMap.find(lv2.pre), chrecMap.end());
595 lv1TestChrec.AddOperand(SCEVConstant::Create(0));
596 lv1TestChrec.AddOperand(SCEVConstant::Create(1));
597 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv1TestChrec, *chrecMap.at(lv1.pre)));
602 lv2TestChrec.AddOperand(SCEVUnknown::Create());
603 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv2TestChrec, *chrecMap.at(lv2.pre)));
649TEST(ScalarEvolutionTests, PolynomialInductionVariableWithSubtraction)
657 const auto & graph = rvsdgModule.
Rvsdg();
659 const auto & c0 = IntegerConstantOperation::Create(graph.GetRootRegion(), 32, 0);
660 const auto & c3 = IntegerConstantOperation::Create(graph.GetRootRegion(), 32, 3);
663 const auto lv1 = theta->AddLoopVar(c0.output(0));
664 const auto lv2 = theta->AddLoopVar(c3.output(0));
666 const auto &
c1 = IntegerConstantOperation::Create(*theta->subregion(), 32, 1);
668 const auto res1 = addNode.output(0);
671 const auto res2 = subNode.output(0);
673 const auto & c5 = IntegerConstantOperation::Create(*theta->subregion(), 32, 5);
675 const auto matchResult =
678 theta->set_predicate(matchResult);
679 lv1.post->divert_to(res1);
680 lv2.post->divert_to(res2);
688 EXPECT_NE(chrecMap.find(lv1.pre), chrecMap.end());
689 EXPECT_NE(chrecMap.find(lv2.pre), chrecMap.end());
693 lv1TestChrec.AddOperand(SCEVConstant::Create(0));
694 lv1TestChrec.AddOperand(SCEVConstant::Create(1));
695 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv1TestChrec, *chrecMap.at(lv1.pre)));
700 lv2TestChrec.AddOperand(SCEVConstant::Create(3));
701 lv2TestChrec.AddOperand(SCEVConstant::Create(-1));
702 lv2TestChrec.AddOperand(SCEVConstant::Create(-1));
703 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv2TestChrec, *chrecMap.at(lv2.pre)));
706TEST(ScalarEvolutionTests, InductionVariablesWithNonConstantInitialValues)
725 LlvmLambdaOperation::Create(
728 Linkage::externalLinkage));
732 auto cv1 = lambda->AddContextVar(*x).inner;
733 auto cv2 = lambda->AddContextVar(*y).inner;
734 auto cv3 = lambda->AddContextVar(*z).inner;
735 auto cv4 = lambda->AddContextVar(*w).inner;
738 auto lv1 = theta->AddLoopVar(cv1);
739 auto lv2 = theta->AddLoopVar(cv2);
740 auto lv3 = theta->AddLoopVar(cv3);
741 auto lv4 = theta->AddLoopVar(cv4);
744 const auto res1 = addNode1.output(0);
747 const auto res2 = addNode2.output(0);
750 const auto res3 = addNode3.output(0);
753 const auto res4 = addNode4.output(0);
755 const auto & c5 = IntegerConstantOperation::Create(*theta->subregion(), 32, 5);
757 const auto matchResult =
760 theta->set_predicate(matchResult);
761 lv2.post->divert_to(res1);
762 lv3.post->divert_to(res2);
763 lv4.post->divert_to(res4);
771 EXPECT_NE(chrecMap.find(lv1.pre), chrecMap.end());
772 EXPECT_NE(chrecMap.find(lv2.pre), chrecMap.end());
773 EXPECT_NE(chrecMap.find(lv3.pre), chrecMap.end());
774 EXPECT_NE(chrecMap.find(lv4.pre), chrecMap.end());
779 lv1TestChrec.AddOperand(SCEVInit::Create(*lv1.pre));
780 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv1TestChrec, *chrecMap.at(lv1.pre)));
786 lv2TestChrec.AddOperand(SCEVInit::Create(*lv2.pre));
787 lv2TestChrec.AddOperand(SCEVInit::Create(*lv1.pre));
788 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv2TestChrec, *chrecMap.at(lv2.pre)));
793 lv3TestChrec.AddOperand(SCEVInit::Create(*lv3.pre));
794 lv3TestChrec.AddOperand(
795 SCEVNAryAddExpr::Create(SCEVInit::Create(*lv2.pre), SCEVInit::Create(*lv1.pre)));
796 lv3TestChrec.AddOperand(SCEVInit::Create(*lv1.pre));
797 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv3TestChrec, *chrecMap.at(lv3.pre)));
804 lv4TestChrec.AddOperand(SCEVInit::Create(*lv4.pre));
805 lv4TestChrec.AddOperand(SCEVNAryAddExpr::Create(
806 SCEVInit::Create(*lv2.pre),
807 SCEVInit::Create(*lv1.pre),
808 SCEVInit::Create(*lv3.pre),
809 SCEVInit::Create(*lv2.pre),
810 SCEVInit::Create(*lv1.pre)));
811 lv4TestChrec.AddOperand(SCEVNAryAddExpr::Create(
812 SCEVInit::Create(*lv2.pre),
813 SCEVInit::Create(*lv1.pre),
814 SCEVInit::Create(*lv1.pre),
815 SCEVInit::Create(*lv1.pre)));
816 lv4TestChrec.AddOperand(SCEVInit::Create(*lv1.pre));
817 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv4TestChrec, *chrecMap.at(lv4.pre)));
820TEST(ScalarEvolutionTests, InductionVariablesWithNonConstantInitialValuesAndMultiplication)
836 LlvmLambdaOperation::Create(
839 Linkage::externalLinkage));
841 auto cv1 = lambda->AddContextVar(*x).inner;
842 auto cv2 = lambda->AddContextVar(*y).inner;
843 auto cv3 = lambda->AddContextVar(*z).inner;
844 auto cv4 = lambda->AddContextVar(*w).inner;
847 auto lv1 = theta->AddLoopVar(cv1);
848 auto lv2 = theta->AddLoopVar(cv2);
849 auto lv3 = theta->AddLoopVar(cv3);
850 auto lv4 = theta->AddLoopVar(cv4);
852 const auto &
c1 = IntegerConstantOperation::Create(*theta->subregion(), 32, 1);
854 const auto res1 = addNode1.output(0);
857 const auto res2 = mulNode1.output(0);
860 const auto res3 = addNode2.output(0);
866 const auto res4 = addNode3.output(0);
868 const auto & c5 = IntegerConstantOperation::Create(*theta->subregion(), 32, 5);
870 const auto matchResult =
873 theta->set_predicate(matchResult);
874 lv2.post->divert_to(res1);
875 lv3.post->divert_to(res3);
876 lv4.post->divert_to(res4);
884 EXPECT_NE(chrecMap.find(lv1.pre), chrecMap.end());
885 EXPECT_NE(chrecMap.find(lv2.pre), chrecMap.end());
886 EXPECT_NE(chrecMap.find(lv3.pre), chrecMap.end());
887 EXPECT_NE(chrecMap.find(lv4.pre), chrecMap.end());
892 lv1TestChrec.AddOperand(SCEVInit::Create(*lv1.pre));
893 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv1TestChrec, *chrecMap.at(lv1.pre)));
898 lv2TestChrec.AddOperand(SCEVInit::Create(*lv2.pre));
899 lv2TestChrec.AddOperand(SCEVConstant::Create(1));
900 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv2TestChrec, *chrecMap.at(lv2.pre)));
905 lv3TestChrec.AddOperand(SCEVInit::Create(*lv3.pre));
906 lv3TestChrec.AddOperand(
907 SCEVNAryMulExpr::Create(SCEVInit::Create(*lv1.pre), SCEVInit::Create(*lv2.pre)));
908 lv3TestChrec.AddOperand(SCEVInit::Create(*lv1.pre));
910 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv3TestChrec, *chrecMap.at(lv3.pre)));
919 lv4TestChrec.AddOperand(SCEVInit::Create(*lv4.pre));
920 lv4TestChrec.AddOperand(SCEVNAryMulExpr::Create(
921 SCEVInit::Create(*lv1.pre),
922 SCEVInit::Create(*lv2.pre),
923 SCEVInit::Create(*lv1.pre),
924 SCEVInit::Create(*lv2.pre)));
925 lv4TestChrec.AddOperand(SCEVNAryAddExpr::Create(
926 SCEVNAryMulExpr::Create(
927 SCEVInit::Create(*lv1.pre),
928 SCEVInit::Create(*lv2.pre),
929 SCEVInit::Create(*lv1.pre)),
930 SCEVNAryMulExpr::Create(SCEVInit::Create(*lv1.pre), SCEVInit::Create(*lv1.pre)),
931 SCEVNAryMulExpr::Create(
932 SCEVInit::Create(*lv1.pre),
933 SCEVInit::Create(*lv2.pre),
934 SCEVInit::Create(*lv1.pre))));
935 lv4TestChrec.AddOperand(SCEVNAryAddExpr::Create(
936 SCEVNAryMulExpr::Create(SCEVInit::Create(*lv1.pre), SCEVInit::Create(*lv1.pre)),
937 SCEVNAryMulExpr::Create(SCEVInit::Create(*lv1.pre), SCEVInit::Create(*lv1.pre))));
939 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv4TestChrec, *chrecMap.at(lv4.pre)));
982TEST(ScalarEvolutionTests, DependentOnInvalidInductionVariable)
990 const auto & graph = rvsdgModule.
Rvsdg();
992 const auto & c0 = IntegerConstantOperation::Create(graph.GetRootRegion(), 32, 0);
993 const auto &
c1 = IntegerConstantOperation::Create(graph.GetRootRegion(), 32, 0);
996 const auto lv1 = theta->AddLoopVar(c0.output(0));
997 const auto lv2 = theta->AddLoopVar(
c1.output(0));
1000 const auto result_1 = addNode_1.output(0);
1003 const auto result_2 = addNode_2.output(0);
1005 const auto & c5 = IntegerConstantOperation::Create(*theta->subregion(), 32, 5);
1007 const auto matchResult =
1010 theta->set_predicate(matchResult);
1011 lv1.post->divert_to(result_1);
1012 lv2.post->divert_to(result_2);
1020 EXPECT_NE(chrecMap.find(lv1.pre), chrecMap.end());
1021 EXPECT_NE(chrecMap.find(lv2.pre), chrecMap.end());
1025 lv1TestChrec.AddOperand(SCEVUnknown::Create());
1026 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv1TestChrec, *chrecMap.at(lv1.pre)));
1030 lv2TestChrec.AddOperand(SCEVConstant::Create(0));
1031 lv2TestChrec.AddOperand(SCEVUnknown::Create());
1032 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv2TestChrec, *chrecMap.at(lv2.pre)));
1035TEST(ScalarEvolutionTests, MutuallyDependentInductionVariables)
1044 const auto & graph = rvsdgModule.
Rvsdg();
1046 const auto & c0 = IntegerConstantOperation::Create(graph.GetRootRegion(), 32, 0);
1047 const auto &
c1 = IntegerConstantOperation::Create(graph.GetRootRegion(), 32, 1);
1050 const auto lv1 = theta->AddLoopVar(c0.output(0));
1051 const auto lv2 = theta->AddLoopVar(
c1.output(0));
1054 const auto result_1 = addNode_1.output(0);
1057 const auto result_2 = addNode_2.output(0);
1059 const auto & c5 = IntegerConstantOperation::Create(*theta->subregion(), 32, 5);
1061 const auto matchResult =
1064 theta->set_predicate(matchResult);
1065 lv1.post->divert_to(result_1);
1066 lv2.post->divert_to(result_2);
1074 EXPECT_NE(chrecMap.find(lv1.pre), chrecMap.end());
1075 EXPECT_NE(chrecMap.find(lv2.pre), chrecMap.end());
1079 lv1TestChrec.AddOperand(SCEVUnknown::Create());
1081 lv2TestChrec.AddOperand(SCEVUnknown::Create());
1082 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv1TestChrec, *chrecMap.at(lv1.pre)));
1083 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv2TestChrec, *chrecMap.at(lv2.pre)));
1086TEST(ScalarEvolutionTests, MultiLayeredMutuallyDependentInductionVariables)
1095 const auto & graph = rvsdgModule.
Rvsdg();
1097 const auto & c0 = IntegerConstantOperation::Create(graph.GetRootRegion(), 32, 0);
1098 const auto &
c1 = IntegerConstantOperation::Create(graph.GetRootRegion(), 32, 1);
1099 const auto &
c2 = IntegerConstantOperation::Create(graph.GetRootRegion(), 32, 2);
1100 const auto & c3 = IntegerConstantOperation::Create(graph.GetRootRegion(), 32, 3);
1103 const auto lv1 = theta->AddLoopVar(c0.output(0));
1104 const auto lv2 = theta->AddLoopVar(
c1.output(0));
1105 const auto lv3 = theta->AddLoopVar(
c2.output(0));
1106 const auto lv4 = theta->AddLoopVar(c3.output(0));
1109 const auto result_1 = addNode_1.output(0);
1111 const auto result_2 = addNode_2.output(0);
1113 const auto result_3 = addNode_3.output(0);
1115 const auto result_4 = addNode_4.output(0);
1117 const auto & c5 = IntegerConstantOperation::Create(*theta->subregion(), 32, 5);
1119 const auto matchResult =
1122 theta->set_predicate(matchResult);
1123 lv1.post->divert_to(result_1);
1124 lv2.post->divert_to(result_2);
1125 lv3.post->divert_to(result_3);
1126 lv4.post->divert_to(result_4);
1134 EXPECT_NE(chrecMap.find(lv1.pre), chrecMap.end());
1135 EXPECT_NE(chrecMap.find(lv2.pre), chrecMap.end());
1136 EXPECT_NE(chrecMap.find(lv3.pre), chrecMap.end());
1137 EXPECT_NE(chrecMap.find(lv4.pre), chrecMap.end());
1141 lv1TestChrec.AddOperand(SCEVUnknown::Create());
1143 lv2TestChrec.AddOperand(SCEVUnknown::Create());
1145 lv3TestChrec.AddOperand(SCEVUnknown::Create());
1147 lv4TestChrec.AddOperand(SCEVUnknown::Create());
1149 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv1TestChrec, *chrecMap.at(lv1.pre)));
1150 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv2TestChrec, *chrecMap.at(lv2.pre)));
1151 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv3TestChrec, *chrecMap.at(lv3.pre)));
1152 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv4TestChrec, *chrecMap.at(lv4.pre)));
1155TEST(ScalarEvolutionTests, InductionVariablesInNestedLoops)
1164 const auto & graph = rvsdgModule.
Rvsdg();
1166 const auto & c0 = IntegerConstantOperation::Create(graph.GetRootRegion(), 32, 0);
1168 const auto lv1 = theta1->AddLoopVar(c0.output(0));
1170 const auto &
c1 = IntegerConstantOperation::Create(*theta1->subregion(), 32, 1);
1172 const auto res1 = addNode1.output(0);
1174 const auto & c5 = IntegerConstantOperation::Create(*theta1->subregion(), 32, 5);
1176 const auto matchResult1 =
1180 const auto lv2 = theta2->AddLoopVar(
c1.output(0));
1181 const auto lv3 = theta2->AddLoopVar(lv1.pre);
1184 const auto & res2 = addNode2.output(0);
1186 const auto & c10 = IntegerConstantOperation::Create(*theta2->subregion(), 32, 10);
1189 const auto matchResult2 =
1192 theta1->set_predicate(matchResult1);
1193 lv1.post->divert_to(res1);
1195 theta2->set_predicate(matchResult2);
1196 lv2.post->divert_to(res2);
1204 EXPECT_NE(chrecMap.find(lv1.pre), chrecMap.end());
1206 EXPECT_NE(chrecMap.find(lv2.pre), chrecMap.end());
1207 EXPECT_NE(chrecMap.find(lv3.pre), chrecMap.end());
1211 lv1TestChrec.AddOperand(SCEVConstant::Create(0));
1212 lv1TestChrec.AddOperand(SCEVConstant::Create(1));
1213 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv1TestChrec, *chrecMap.at(lv1.pre)));
1218 lv2TestChrec.AddOperand(SCEVConstant::Create(1));
1219 lv2TestChrec.AddOperand(lv1TestChrec.Clone());
1220 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv2TestChrec, *chrecMap.at(lv2.pre)));
1224 lv3TestChrec.AddOperand(lv1TestChrec.Clone());
1225 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv3TestChrec, *chrecMap.at(lv3.pre)));
1228TEST(ScalarEvolutionTests, InductionVariablesInNestedLoopsWithFolding)
1236 const auto & graph = rvsdgModule.
Rvsdg();
1238 const auto & c0_1 = IntegerConstantOperation::Create(graph.GetRootRegion(), 32, 0);
1239 const auto & c2_1 = IntegerConstantOperation::Create(graph.GetRootRegion(), 32, 2);
1240 const auto & c3_1 = IntegerConstantOperation::Create(graph.GetRootRegion(), 32, 3);
1243 const auto lv1_1 = theta1->AddLoopVar(c0_1.output(0));
1244 const auto lv2_1 = theta1->AddLoopVar(c2_1.output(0));
1245 const auto lv3_1 = theta1->AddLoopVar(c3_1.output(0));
1247 const auto & c1_2 = IntegerConstantOperation::Create(*theta1->subregion(), 32, 1);
1248 const auto & c2_2 = IntegerConstantOperation::Create(*theta1->subregion(), 32, 2);
1249 const auto & c3_2 = IntegerConstantOperation::Create(*theta1->subregion(), 32, 3);
1257 const auto res1 = addNode1.output(0);
1258 const auto res2 = addNode2.output(0);
1259 const auto res3 = addNode3.output(0);
1261 const auto & c5 = IntegerConstantOperation::Create(*theta1->subregion(), 32, 5);
1263 const auto matchResult1 =
1267 const auto lv1_2 = theta2->AddLoopVar(res1);
1268 const auto lv2_2 = theta2->AddLoopVar(res2);
1269 const auto lv3_2 = theta2->AddLoopVar(res3);
1270 const auto lv4 = theta2->AddLoopVar(c1_2.output(0));
1271 const auto lv5 = theta2->AddLoopVar(c1_2.output(0));
1278 const auto & res4 = addNode6.output(0);
1283 const auto & res5 = addNode7.output(0);
1285 const auto & c10 = IntegerConstantOperation::Create(*theta2->subregion(), 32, 10);
1288 const auto matchResult2 =
1292 theta1->set_predicate(matchResult1);
1293 lv1_1.post->divert_to(res1);
1294 lv2_1.post->divert_to(res2);
1295 lv3_1.post->divert_to(res3);
1298 theta2->set_predicate(matchResult2);
1299 lv4.post->divert_to(res4);
1300 lv5.post->divert_to(res5);
1308 EXPECT_NE(chrecMap.find(lv1_1.pre), chrecMap.end());
1309 EXPECT_NE(chrecMap.find(lv2_1.pre), chrecMap.end());
1310 EXPECT_NE(chrecMap.find(lv3_1.pre), chrecMap.end());
1312 EXPECT_NE(chrecMap.find(lv1_2.pre), chrecMap.end());
1313 EXPECT_NE(chrecMap.find(lv2_2.pre), chrecMap.end());
1314 EXPECT_NE(chrecMap.find(lv3_2.pre), chrecMap.end());
1315 EXPECT_NE(chrecMap.find(lv4.pre), chrecMap.end());
1316 EXPECT_NE(chrecMap.find(lv5.pre), chrecMap.end());
1320 lv1TestChrec.AddOperand(SCEVConstant::Create(0));
1321 lv1TestChrec.AddOperand(SCEVConstant::Create(1));
1322 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv1TestChrec, *chrecMap.at(lv1_1.pre)));
1326 lv2TestChrec.AddOperand(SCEVConstant::Create(2));
1327 lv2TestChrec.AddOperand(SCEVConstant::Create(2));
1328 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv2TestChrec, *chrecMap.at(lv2_1.pre)));
1332 lv3TestChrec.AddOperand(SCEVConstant::Create(3));
1333 lv3TestChrec.AddOperand(SCEVConstant::Create(3));
1334 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv3TestChrec, *chrecMap.at(lv3_1.pre)));
1338 const auto lv1_2InnerChrec = SCEVChainRecurrence::Create(*theta1, *lv1_1.post->origin());
1339 lv1_2InnerChrec->AddOperand(SCEVConstant::Create(1));
1340 lv1_2InnerChrec->AddOperand(SCEVConstant::Create(1));
1341 lv1_2TestChrec.AddOperand(lv1_2InnerChrec->Clone());
1342 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv1_2TestChrec, *chrecMap.at(lv1_2.pre)));
1346 const auto lv2_2InnerChrec = SCEVChainRecurrence::Create(*theta1, *lv2_1.post->origin());
1347 lv2_2InnerChrec->AddOperand(SCEVConstant::Create(4));
1348 lv2_2InnerChrec->AddOperand(SCEVConstant::Create(2));
1349 lv2_2TestChrec.AddOperand(lv2_2InnerChrec->Clone());
1350 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv2_2TestChrec, *chrecMap.at(lv2_2.pre)));
1354 const auto lv3_2InnerChrec = SCEVChainRecurrence::Create(*theta1, *lv3_1.post->origin());
1355 lv3_2InnerChrec->AddOperand(SCEVConstant::Create(6));
1356 lv3_2InnerChrec->AddOperand(SCEVConstant::Create(3));
1357 lv3_2TestChrec.AddOperand(lv3_2InnerChrec->Clone());
1358 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv3_2TestChrec, *chrecMap.at(lv3_2.pre)));
1364 lv4TestChrec.AddOperand(SCEVConstant::Create(1));
1365 const auto lv4InnerChrec = SCEVChainRecurrence::Create(*theta1, *lv4.pre);
1366 lv4InnerChrec->AddOperand(SCEVConstant::Create(11));
1367 lv4InnerChrec->AddOperand(SCEVConstant::Create(6));
1368 lv4TestChrec.AddOperand(lv4InnerChrec->Clone());
1369 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv4TestChrec, *chrecMap.at(lv4.pre)));
1374 lv5TestChrec.AddOperand(SCEVConstant::Create(1));
1375 const auto lv5InnerChrec = SCEVChainRecurrence::Create(*theta1, *lv5.pre);
1376 lv5InnerChrec->AddOperand(SCEVConstant::Create(4));
1377 lv5InnerChrec->AddOperand(SCEVConstant::Create(8));
1378 lv5InnerChrec->AddOperand(SCEVConstant::Create(4));
1379 lv5TestChrec.AddOperand(lv5InnerChrec->Clone());
1380 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv5TestChrec, *chrecMap.at(lv5.pre)));
1383TEST(ScalarEvolutionTests, InductionVariablesInSisterLoops)
1393 const auto & graph = rvsdgModule.
Rvsdg();
1395 const auto & c0 = IntegerConstantOperation::Create(graph.GetRootRegion(), 32, 0);
1397 const auto lv1 = theta1->AddLoopVar(c0.output(0));
1399 const auto &
c1 = IntegerConstantOperation::Create(*theta1->subregion(), 32, 1);
1401 const auto res1 = addNode1.output(0);
1403 const auto & c5 = IntegerConstantOperation::Create(*theta1->subregion(), 32, 5);
1405 const auto matchResult1 =
1408 const auto &
c2 = IntegerConstantOperation::Create(graph.GetRootRegion(), 32, 2);
1410 const auto lv2 = theta2->AddLoopVar(
c2.output(0));
1411 const auto lv3 = theta2->AddLoopVar(theta1->output(0));
1414 const auto & res2 = addNode2.output(0);
1416 const auto & c10 = IntegerConstantOperation::Create(*theta2->subregion(), 32, 10);
1419 const auto matchResult2 =
1422 theta1->set_predicate(matchResult1);
1423 lv1.post->divert_to(res1);
1425 theta2->set_predicate(matchResult2);
1426 lv2.post->divert_to(res2);
1434 EXPECT_NE(chrecMap.find(lv1.pre), chrecMap.end());
1436 EXPECT_NE(chrecMap.find(lv2.pre), chrecMap.end());
1437 EXPECT_NE(chrecMap.find(lv3.pre), chrecMap.end());
1441 lv1TestChrec.AddOperand(SCEVConstant::Create(0));
1442 lv1TestChrec.AddOperand(SCEVConstant::Create(1));
1443 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv1TestChrec, *chrecMap.at(lv1.pre)));
1448 lv2TestChrec.AddOperand(SCEVConstant::Create(2));
1450 lv2InnerChrec.AddOperand(SCEVConstant::Create(1));
1451 lv2InnerChrec.AddOperand(SCEVConstant::Create(1));
1452 lv2TestChrec.AddOperand(lv2InnerChrec.Clone());
1453 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv2TestChrec, *chrecMap.at(lv2.pre)));
1457 lv3TestChrec.AddOperand(lv2InnerChrec.Clone());
1458 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv3TestChrec, *chrecMap.at(lv3.pre)));
1461TEST(ScalarEvolutionTests, ComputeRecurrenceForArrayGEP)
1467 const auto intArrayType = ArrayType::Create(intType, 5);
1468 const auto pointerType = PointerType::Create();
1469 const auto memoryStateType = MemoryStateType::Create();
1472 const auto & graph = rvsdgModule.
Rvsdg();
1475 graph.GetRootRegion(),
1476 LlvmLambdaOperation::Create(
1478 { pointerType, memoryStateType },
1479 { intType, memoryStateType }),
1481 Linkage::externalLinkage));
1484 &graph.GetRootRegion(),
1485 LlvmDeltaOperation::Create(intArrayType,
"", Linkage::externalLinkage,
"",
false, 4));
1487 const auto & arrayC1 = IntegerConstantOperation::Create(*delta->subregion(), 32, 1);
1488 const auto & arrayC2 = IntegerConstantOperation::Create(*delta->subregion(), 32, 2);
1489 const auto & arrayC3 = IntegerConstantOperation::Create(*delta->subregion(), 32, 3);
1490 const auto & arrayC4 = IntegerConstantOperation::Create(*delta->subregion(), 32, 4);
1491 const auto & arrayC5 = IntegerConstantOperation::Create(*delta->subregion(), 32, 5);
1493 const auto & constantArray = ConstantDataArrayOperation::Create({ arrayC1.output(0),
1497 arrayC5.output(0) });
1498 delta->finalize(constantArray);
1500 const auto cv1 = lambda->AddContextVar(delta->output());
1502 const auto & c0_1 = IntegerConstantOperation::Create(*lambda->subregion(), 32, 0);
1503 const auto & c1_1 = IntegerConstantOperation::Create(*lambda->subregion(), 32, 1);
1506 const auto memoryState = theta->AddLoopVar(lambda->GetFunctionArguments()[1]);
1507 const auto lv1 = theta->AddLoopVar(c0_1.output(0));
1508 const auto lv2 = theta->AddLoopVar(c1_1.output(0));
1509 const auto lv3 = theta->AddLoopVar(cv1.inner);
1511 const auto & c1_2 = IntegerConstantOperation::Create(*theta->subregion(), 32, 1);
1514 const auto res1 = addNode1.output(0);
1516 const auto & c0_2 = IntegerConstantOperation::Create(*theta->subregion(), 64, 0);
1517 auto & lv1SExt = SExtOperation::create(64, *lv1.pre);
1520 GetElementPtrOperation::create(lv3.pre, { c0_2.output(0), &lv1SExt }, intArrayType);
1522 auto loadedValue = LoadNonVolatileOperation::Create(gep, { memoryState.pre }, intType, 32)[0];
1525 const auto res2 = addNode2.output(0);
1527 const auto & c4 = IntegerConstantOperation::Create(*theta->subregion(), 32, 4);
1529 const auto matchResult =
1532 theta->set_predicate(matchResult);
1534 lv1.post->divert_to(res1);
1535 lv2.post->divert_to(res2);
1543 EXPECT_NE(chrecMap.find(lv1.pre), chrecMap.end());
1544 EXPECT_NE(chrecMap.find(lv2.pre), chrecMap.end());
1545 EXPECT_NE(chrecMap.find(lv3.pre), chrecMap.end());
1546 EXPECT_NE(chrecMap.find(gep), chrecMap.end());
1550 lv1TestChrec.AddOperand(SCEVConstant::Create(0));
1551 lv1TestChrec.AddOperand(SCEVConstant::Create(1));
1552 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv1TestChrec, *chrecMap.at(lv1.pre)));
1556 lv2TestChrec.AddOperand(SCEVConstant::Create(1));
1557 lv2TestChrec.AddOperand(SCEVUnknown::Create());
1558 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv2TestChrec, *chrecMap.at(lv2.pre)));
1562 lv3TestChrec.AddOperand(SCEVInit::Create(*lv3.pre));
1563 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv3TestChrec, *chrecMap.at(lv3.pre)));
1570 gepTestChrec.AddOperand(SCEVInit::Create(*lv3.pre));
1571 gepTestChrec.AddOperand(SCEVConstant::Create(4));
1572 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(gepTestChrec, *chrecMap.at(gep)));
1575TEST(ScalarEvolutionTests, ComputeRecurrenceForStructGEP)
1581 const auto intStructType =
1582 StructType::CreateLiteral({ intType, intType, intType, intType, intType },
false);
1583 const auto pointerType = PointerType::Create();
1584 const auto memoryStateType = MemoryStateType::Create();
1587 const auto & graph = rvsdgModule.
Rvsdg();
1590 graph.GetRootRegion(),
1591 LlvmLambdaOperation::Create(
1593 { pointerType, memoryStateType },
1594 { intType, memoryStateType }),
1596 Linkage::externalLinkage));
1599 &graph.GetRootRegion(),
1600 LlvmDeltaOperation::Create(intStructType,
"", Linkage::externalLinkage,
"",
false, 4));
1602 const auto & structC1 = IntegerConstantOperation::Create(*delta->subregion(), 32, 1);
1603 const auto & structC2 = IntegerConstantOperation::Create(*delta->subregion(), 32, 2);
1604 const auto & structC3 = IntegerConstantOperation::Create(*delta->subregion(), 32, 3);
1605 const auto & structC4 = IntegerConstantOperation::Create(*delta->subregion(), 32, 4);
1606 const auto & structC5 = IntegerConstantOperation::Create(*delta->subregion(), 32, 5);
1608 auto & constantStruct = ConstantStructOperation::Create(
1609 *delta->subregion(),
1610 { structC1.output(0),
1614 structC5.output(0) },
1616 delta->finalize(&constantStruct);
1618 const auto cv1 = lambda->AddContextVar(delta->output());
1620 const auto & c0_1 = IntegerConstantOperation::Create(*lambda->subregion(), 32, 0);
1621 const auto & c1_1 = IntegerConstantOperation::Create(*lambda->subregion(), 32, 1);
1624 const auto memoryState = theta->AddLoopVar(lambda->GetFunctionArguments()[1]);
1625 const auto lv1 = theta->AddLoopVar(c0_1.output(0));
1626 const auto lv2 = theta->AddLoopVar(c1_1.output(0));
1627 const auto lv3 = theta->AddLoopVar(cv1.inner);
1629 const auto & c1_2 = IntegerConstantOperation::Create(*theta->subregion(), 32, 1);
1632 const auto res1 = addNode1.output(0);
1634 auto & lv1SExt = SExtOperation::create(64, *lv1.pre);
1635 const auto gep = GetElementPtrOperation::create(lv3.pre, { &lv1SExt }, intType);
1637 auto loadedValue = LoadNonVolatileOperation::Create(gep, { memoryState.pre }, intType, 32)[0];
1640 const auto res2 = addNode2.output(0);
1642 const auto & c4 = IntegerConstantOperation::Create(*theta->subregion(), 32, 4);
1644 const auto matchResult =
1647 theta->set_predicate(matchResult);
1649 lv1.post->divert_to(res1);
1650 lv2.post->divert_to(res2);
1658 EXPECT_NE(chrecMap.find(lv1.pre), chrecMap.end());
1659 EXPECT_NE(chrecMap.find(lv2.pre), chrecMap.end());
1660 EXPECT_NE(chrecMap.find(lv3.pre), chrecMap.end());
1661 EXPECT_NE(chrecMap.find(gep), chrecMap.end());
1665 lv1TestChrec.AddOperand(SCEVConstant::Create(0));
1666 lv1TestChrec.AddOperand(SCEVConstant::Create(1));
1667 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv1TestChrec, *chrecMap.at(lv1.pre)));
1671 lv2TestChrec.AddOperand(SCEVConstant::Create(1));
1672 lv2TestChrec.AddOperand(SCEVUnknown::Create());
1673 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv2TestChrec, *chrecMap.at(lv2.pre)));
1677 lv3TestChrec.AddOperand(SCEVInit::Create(*lv3.pre));
1678 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(lv3TestChrec, *chrecMap.at(lv3.pre)));
1685 gepTestChrec.AddOperand(SCEVInit::Create(*lv3.pre));
1686 gepTestChrec.AddOperand(SCEVConstant::Create(4));
1687 EXPECT_TRUE(ScalarEvolution::StructurallyEqual(gepTestChrec, *chrecMap.at(gep)));
2035TEST(ScalarEvolutionTests, ComputeTripCountForSimpleQuadraticRecurrence)
2043 const auto & graph = rvsdgModule.
Rvsdg();
2045 const auto & c0 = IntegerConstantOperation::Create(graph.GetRootRegion(), 32, 0);
2046 const auto & c1_1 = IntegerConstantOperation::Create(graph.GetRootRegion(), 32, 1);
2049 const auto lv1 = theta->AddLoopVar(c0.output(0));
2050 const auto lv2 = theta->AddLoopVar(c1_1.output(0));
2052 const auto & c1_2 = IntegerConstantOperation::Create(*theta->subregion(), 32, 1);
2054 const auto res1 = addNode.output(0);
2057 const auto res2 = addNode2.output(0);
2059 const auto & c10 = IntegerConstantOperation::Create(*theta->subregion(), 32, 10);
2061 const auto matchResult =
2064 theta->set_predicate(matchResult);
2065 lv1.post->divert_to(res1);
2066 lv2.post->divert_to(res2);
2074 EXPECT_NE(tripCountMap.find(theta), tripCountMap.end());
2075 const auto tripCount = tripCountMap.at(theta);
2076 EXPECT_TRUE(tripCount == 4);
2079TEST(ScalarEvolutionTests, TestTripCountCouldNotCompute)
2087 const auto & graph = rvsdgModule.
Rvsdg();
2089 const auto &
c2 = IntegerConstantOperation::Create(graph.GetRootRegion(), 32, 2);
2090 const auto & c3 = IntegerConstantOperation::Create(graph.GetRootRegion(), 32, 3);
2091 const auto & c4 = IntegerConstantOperation::Create(graph.GetRootRegion(), 32, 4);
2094 const auto lv1 = theta->AddLoopVar(
c2.output(0));
2095 const auto lv2 = theta->AddLoopVar(c3.output(0));
2096 const auto lv3 = theta->AddLoopVar(c4.output(0));
2098 const auto &
c1 = IntegerConstantOperation::Create(*theta->subregion(), 32, 1);
2100 const auto res1 = addNode1.output(0);
2103 const auto res2 = addNode2.output(0);
2106 const auto res3 = addNode3.output(0);
2108 const auto & c50 = IntegerConstantOperation::Create(*theta->subregion(), 32, 50);
2110 const auto matchResult =
2113 theta->set_predicate(matchResult);
2114 lv1.post->divert_to(res1);
2115 lv2.post->divert_to(res2);
2116 lv3.post->divert_to(res3);
2127 EXPECT_EQ(tripCountMap.find(theta), tripCountMap.end());