13TEST(bitstring, arithmetic_test_bitand)
22 const auto c0 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 3 });
23 const auto c1 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 5 });
25 auto & and0 = CreateOpNode<bitand_op>({ s0, s1 }, 32);
26 auto & and1 = CreateOpNode<bitand_op>({ c0,
c1 }, 32);
28 auto & ex0 = GraphExport::Create(*and0.output(0),
"dummy");
29 auto & ex1 = GraphExport::Create(*and1.output(0),
"dummy");
34 ReduceNode<bitand_op>(BitBinaryOperation::foldConstants, and0);
35 ReduceNode<bitand_op>(BitBinaryOperation::foldConstants, and1);
41 EXPECT_EQ(TryGetOwnerNode<SimpleNode>(*ex0.origin())->GetOperation(),
bitand_op(32));
43 TryGetOwnerNode<SimpleNode>(*ex1.origin())->GetOperation(),
47TEST(bitstring, arithmetic_test_bitashr)
56 auto c0 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 16 });
57 auto c1 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, -16 });
58 auto c2 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 2 });
59 auto c3 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 32 });
61 auto & ashr0 = CreateOpNode<bitashr_op>({ s0, s1 }, 32);
62 auto & ashr1 = CreateOpNode<bitashr_op>({ c0,
c2 }, 32);
63 auto & ashr2 = CreateOpNode<bitashr_op>({ c0, c3 }, 32);
64 auto & ashr3 = CreateOpNode<bitashr_op>({
c1,
c2 }, 32);
65 auto & ashr4 = CreateOpNode<bitashr_op>({
c1, c3 }, 32);
67 auto & ex0 = GraphExport::Create(*ashr0.output(0),
"dummy");
68 auto & ex1 = GraphExport::Create(*ashr1.output(0),
"dummy");
69 auto & ex2 = GraphExport::Create(*ashr2.output(0),
"dummy");
70 auto & ex3 = GraphExport::Create(*ashr3.output(0),
"dummy");
71 auto & ex4 = GraphExport::Create(*ashr4.output(0),
"dummy");
76 ReduceNode<bitashr_op>(BitBinaryOperation::foldConstants, ashr0);
77 ReduceNode<bitashr_op>(BitBinaryOperation::foldConstants, ashr1);
78 ReduceNode<bitashr_op>(BitBinaryOperation::foldConstants, ashr2);
79 ReduceNode<bitashr_op>(BitBinaryOperation::foldConstants, ashr3);
80 ReduceNode<bitashr_op>(BitBinaryOperation::foldConstants, ashr4);
86 EXPECT_EQ(TryGetOwnerNode<SimpleNode>(*ex0.origin())->GetOperation(),
bitashr_op(32));
88 TryGetOwnerNode<SimpleNode>(*ex1.origin())->GetOperation(),
91 TryGetOwnerNode<SimpleNode>(*ex2.origin())->GetOperation(),
94 TryGetOwnerNode<SimpleNode>(*ex3.origin())->GetOperation(),
97 TryGetOwnerNode<SimpleNode>(*ex4.origin())->GetOperation(),
101TEST(bitstring, arithmetic_test_bitdifference)
110 auto & diff = CreateOpNode<bitsub_op>({ s0, s1 }, 32);
112 auto & ex0 = GraphExport::Create(*diff.output(0),
"dummy");
117 ReduceNode<bitsub_op>(NormalizeBinaryOperation, diff);
123 EXPECT_EQ(TryGetOwnerNode<SimpleNode>(*ex0.origin())->GetOperation(),
bitsub_op(32));
126TEST(bitstring, arithmetic_test_bitnegate)
133 auto c0 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 3 });
135 auto & neg0 = CreateOpNode<bitneg_op>({ s0 }, 32);
136 auto & neg1 = CreateOpNode<bitneg_op>({ c0 }, 32);
137 auto & neg2 = CreateOpNode<bitneg_op>({ neg1.output(0) }, 32);
139 auto & ex0 = GraphExport::Create(*neg0.output(0),
"dummy");
140 auto & ex1 = GraphExport::Create(*neg1.output(0),
"dummy");
141 auto & ex2 = GraphExport::Create(*neg2.output(0),
"dummy");
146 ReduceNode<bitneg_op>(BitUnaryOperation::foldConstant, neg0);
147 ReduceNode<bitneg_op>(BitUnaryOperation::foldConstant, neg1);
148 ReduceNode<bitneg_op>(BitUnaryOperation::foldConstant, neg2);
154 EXPECT_EQ(TryGetOwnerNode<SimpleNode>(*ex0.origin())->GetOperation(),
bitneg_op(32));
156 TryGetOwnerNode<SimpleNode>(*ex1.origin())->GetOperation(),
159 TryGetOwnerNode<SimpleNode>(*ex2.origin())->GetOperation(),
163TEST(bitstring, arithmetic_test_bitnot)
170 auto c0 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 3 });
172 auto & not0 = CreateOpNode<bitnot_op>({ s0 }, 32);
173 auto & not1 = CreateOpNode<bitnot_op>({ c0 }, 32);
174 auto & not2 = CreateOpNode<bitnot_op>({ not1.output(0) }, 32);
176 auto & ex0 = GraphExport::Create(*not0.output(0),
"dummy");
177 auto & ex1 = GraphExport::Create(*not1.output(0),
"dummy");
178 auto & ex2 = GraphExport::Create(*not2.output(0),
"dummy");
183 ReduceNode<bitnot_op>(BitUnaryOperation::foldConstant, not0);
184 ReduceNode<bitnot_op>(BitUnaryOperation::foldConstant, not1);
185 ReduceNode<bitnot_op>(BitUnaryOperation::foldConstant, not2);
191 EXPECT_EQ(TryGetOwnerNode<SimpleNode>(*ex0.origin())->GetOperation(),
bitnot_op(32));
193 TryGetOwnerNode<SimpleNode>(*ex1.origin())->GetOperation(),
196 TryGetOwnerNode<SimpleNode>(*ex2.origin())->GetOperation(),
200TEST(bitstring, arithmetic_test_bitor)
209 auto c0 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 3 });
210 auto c1 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 5 });
212 auto & or0 = CreateOpNode<bitor_op>({ s0, s1 }, 32);
213 auto & or1 = CreateOpNode<bitor_op>({ c0,
c1 }, 32);
215 auto & ex0 = GraphExport::Create(*or0.output(0),
"dummy");
216 auto & ex1 = GraphExport::Create(*or1.output(0),
"dummy");
221 ReduceNode<bitor_op>(BitBinaryOperation::foldConstants, or0);
222 ReduceNode<bitor_op>(BitBinaryOperation::foldConstants, or1);
228 EXPECT_EQ(TryGetOwnerNode<SimpleNode>(*ex0.origin())->GetOperation(),
bitor_op(32));
230 TryGetOwnerNode<SimpleNode>(*ex1.origin())->GetOperation(),
234TEST(bitstring, arithmetic_test_bitproduct)
243 auto c0 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 3 });
244 auto c1 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 5 });
246 auto & product0 = CreateOpNode<bitmul_op>({ s0, s1 }, 32);
247 auto & product1 = CreateOpNode<bitmul_op>({ c0,
c1 }, 32);
249 auto & ex0 = GraphExport::Create(*product0.output(0),
"dummy");
250 auto & ex1 = GraphExport::Create(*product1.output(0),
"dummy");
255 ReduceNode<bitmul_op>(BitBinaryOperation::foldConstants, product0);
256 ReduceNode<bitmul_op>(BitBinaryOperation::foldConstants, product1);
262 EXPECT_EQ(TryGetOwnerNode<SimpleNode>(*ex0.origin())->GetOperation(),
bitmul_op(32));
264 TryGetOwnerNode<SimpleNode>(*ex1.origin())->GetOperation(),
268TEST(bitstring, arithmetic_test_bitshiproduct)
277 auto & shiproduct = CreateOpNode<bitsmulh_op>({ s0, s1 }, 32);
279 auto & ex0 = GraphExport::Create(*shiproduct.output(0),
"dummy");
284 ReduceNode<bitsmulh_op>(NormalizeBinaryOperation, shiproduct);
290 EXPECT_EQ(TryGetOwnerNode<SimpleNode>(*ex0.origin())->GetOperation(),
bitsmulh_op(32));
293TEST(bitstring, arithmetic_test_bitshl)
302 auto c0 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 16 });
303 auto c1 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 2 });
304 auto c2 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 32 });
306 auto & shl0 = CreateOpNode<bitshl_op>({ s0, s1 }, 32);
307 auto & shl1 = CreateOpNode<bitshl_op>({ c0,
c1 }, 32);
308 auto & shl2 = CreateOpNode<bitshl_op>({ c0,
c2 }, 32);
310 auto & ex0 = GraphExport::Create(*shl0.output(0),
"dummy");
311 auto & ex1 = GraphExport::Create(*shl1.output(0),
"dummy");
312 auto & ex2 = GraphExport::Create(*shl2.output(0),
"dummy");
317 ReduceNode<bitshl_op>(BitBinaryOperation::foldConstants, shl0);
318 ReduceNode<bitshl_op>(BitBinaryOperation::foldConstants, shl1);
319 ReduceNode<bitshl_op>(BitBinaryOperation::foldConstants, shl2);
325 EXPECT_EQ(TryGetOwnerNode<SimpleNode>(*ex0.origin())->GetOperation(),
bitshl_op(32));
327 TryGetOwnerNode<SimpleNode>(*ex1.origin())->GetOperation(),
330 TryGetOwnerNode<SimpleNode>(*ex2.origin())->GetOperation(),
334TEST(bitstring, arithmetic_test_bitshr)
343 auto c0 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 16 });
344 auto c1 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 2 });
345 auto c2 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 32 });
347 auto & shr0 = CreateOpNode<bitshr_op>({ s0, s1 }, 32);
348 auto & shr1 = CreateOpNode<bitshr_op>({ c0,
c1 }, 32);
349 auto & shr2 = CreateOpNode<bitshr_op>({ c0,
c2 }, 32);
351 auto & ex0 = GraphExport::Create(*shr0.output(0),
"dummy");
352 auto & ex1 = GraphExport::Create(*shr1.output(0),
"dummy");
353 auto & ex2 = GraphExport::Create(*shr2.output(0),
"dummy");
358 ReduceNode<bitshr_op>(BitBinaryOperation::foldConstants, shr0);
359 ReduceNode<bitshr_op>(BitBinaryOperation::foldConstants, shr1);
360 ReduceNode<bitshr_op>(BitBinaryOperation::foldConstants, shr2);
366 EXPECT_EQ(TryGetOwnerNode<SimpleNode>(*ex0.origin())->GetOperation(),
bitshr_op(32));
368 TryGetOwnerNode<SimpleNode>(*ex1.origin())->GetOperation(),
371 TryGetOwnerNode<SimpleNode>(*ex2.origin())->GetOperation(),
375TEST(bitstring, arithmetic_test_bitsmod)
384 auto c0 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, -7 });
385 auto c1 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 3 });
387 auto & smod0 = CreateOpNode<bitsmod_op>({ s0, s1 }, 32);
388 auto & smod1 = CreateOpNode<bitsmod_op>({ c0,
c1 }, 32);
390 auto & ex0 = GraphExport::Create(*smod0.output(0),
"dummy");
391 auto & ex1 = GraphExport::Create(*smod1.output(0),
"dummy");
396 ReduceNode<bitsmod_op>(BitBinaryOperation::foldConstants, smod0);
397 ReduceNode<bitsmod_op>(BitBinaryOperation::foldConstants, smod1);
403 EXPECT_EQ(TryGetOwnerNode<SimpleNode>(*ex0.origin())->GetOperation(),
bitsmod_op(32));
405 TryGetOwnerNode<SimpleNode>(*ex1.origin())->GetOperation(),
409TEST(bitstring, arithmetic_test_bitsquotient)
418 auto c0 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 7 });
419 auto c1 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, -3 });
421 auto & squot0 = CreateOpNode<bitsdiv_op>({ s0, s1 }, 32);
422 auto & squot1 = CreateOpNode<bitsdiv_op>({ c0,
c1 }, 32);
424 auto & ex0 = GraphExport::Create(*squot0.output(0),
"dummy");
425 auto & ex1 = GraphExport::Create(*squot1.output(0),
"dummy");
430 ReduceNode<bitsdiv_op>(BitBinaryOperation::foldConstants, squot0);
431 ReduceNode<bitsdiv_op>(BitBinaryOperation::foldConstants, squot1);
437 EXPECT_EQ(TryGetOwnerNode<SimpleNode>(*ex0.origin())->GetOperation(),
bitsdiv_op(32));
439 TryGetOwnerNode<SimpleNode>(*ex1.origin())->GetOperation(),
443TEST(bitstring, arithmetic_test_bitsum)
452 auto c0 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 3 });
453 auto c1 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 5 });
455 auto & sum0 = CreateOpNode<bitadd_op>({ s0, s1 }, 32);
456 auto & sum1 = CreateOpNode<bitadd_op>({ c0,
c1 }, 32);
458 auto & ex0 = GraphExport::Create(*sum0.output(0),
"dummy");
459 auto & ex1 = GraphExport::Create(*sum1.output(0),
"dummy");
464 ReduceNode<bitadd_op>(BitBinaryOperation::foldConstants, sum0);
465 ReduceNode<bitadd_op>(BitBinaryOperation::foldConstants, sum1);
471 EXPECT_EQ(TryGetOwnerNode<SimpleNode>(*ex0.origin())->GetOperation(),
bitadd_op(32));
473 TryGetOwnerNode<SimpleNode>(*ex1.origin())->GetOperation(),
477TEST(bitstring, arithmetic_test_bituhiproduct)
486 auto & uhiproduct = CreateOpNode<bitumulh_op>({ s0, s1 }, 32);
488 auto & ex0 = GraphExport::Create(*uhiproduct.output(0),
"dummy");
493 ReduceNode<bitumulh_op>(NormalizeBinaryOperation, uhiproduct);
499 EXPECT_EQ(TryGetOwnerNode<SimpleNode>(*ex0.origin())->GetOperation(),
bitumulh_op(32));
502TEST(bitstring, arithmetic_test_bitumod)
511 auto c0 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 7 });
512 auto c1 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 3 });
514 auto & umod0 = CreateOpNode<bitumod_op>({ s0, s1 }, 32);
515 auto & umod1 = CreateOpNode<bitumod_op>({ c0,
c1 }, 32);
517 auto & ex0 = GraphExport::Create(*umod0.output(0),
"dummy");
518 auto & ex1 = GraphExport::Create(*umod1.output(0),
"dummy");
523 ReduceNode<bitumod_op>(BitBinaryOperation::foldConstants, umod0);
524 ReduceNode<bitumod_op>(BitBinaryOperation::foldConstants, umod1);
530 EXPECT_EQ(TryGetOwnerNode<SimpleNode>(*ex0.origin())->GetOperation(),
bitumod_op(32));
532 TryGetOwnerNode<SimpleNode>(*ex1.origin())->GetOperation(),
536TEST(bitstring, arithmetic_test_bituquotient)
545 auto c0 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 7 });
546 auto c1 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 3 });
548 auto & uquot0 = CreateOpNode<bitudiv_op>({ s0, s1 }, 32);
549 auto & uquot1 = CreateOpNode<bitudiv_op>({ c0,
c1 }, 32);
551 auto & ex0 = GraphExport::Create(*uquot0.output(0),
"dummy");
552 auto & ex1 = GraphExport::Create(*uquot1.output(0),
"dummy");
557 ReduceNode<bitudiv_op>(BitBinaryOperation::foldConstants, uquot0);
558 ReduceNode<bitudiv_op>(BitBinaryOperation::foldConstants, uquot1);
564 EXPECT_EQ(TryGetOwnerNode<SimpleNode>(*ex0.origin())->GetOperation(),
bitudiv_op(32));
566 TryGetOwnerNode<SimpleNode>(*ex1.origin())->GetOperation(),
570TEST(bitstring, arithmetic_test_bitxor)
579 auto c0 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 3 });
580 auto c1 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 5 });
582 auto & xor0 = CreateOpNode<bitxor_op>({ s0, s1 }, 32);
583 auto & xor1 = CreateOpNode<bitxor_op>({ c0,
c1 }, 32);
585 auto & ex0 = GraphExport::Create(*xor0.output(0),
"dummy");
586 auto & ex1 = GraphExport::Create(*xor1.output(0),
"dummy");
591 ReduceNode<bitxor_op>(BitBinaryOperation::foldConstants, xor0);
592 ReduceNode<bitxor_op>(BitBinaryOperation::foldConstants, xor1);
598 EXPECT_EQ(TryGetOwnerNode<SimpleNode>(*ex0.origin())->GetOperation(),
bitxor_op(32));
600 TryGetOwnerNode<SimpleNode>(*ex1.origin())->GetOperation(),
624TEST(bitstring, comparison_test_bitequal)
632 auto c0 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 4 });
633 auto c1 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 5 });
634 auto c2 = &BitConstantOperation::createUndefined(graph.
GetRootRegion(), 32);
636 auto & equal0 = CreateOpNode<biteq_op>({ s0, s1 }, 32);
637 auto & equal1 = CreateOpNode<biteq_op>({ c0, c0 }, 32);
638 auto & equal2 = CreateOpNode<biteq_op>({ c0,
c1 }, 32);
639 auto & equal3 = CreateOpNode<biteq_op>({ c0,
c2 }, 32);
641 auto & ex0 = GraphExport::Create(*equal0.output(0),
"dummy");
642 auto & ex1 = GraphExport::Create(*equal1.output(0),
"dummy");
643 auto & ex2 = GraphExport::Create(*equal2.output(0),
"dummy");
644 auto & ex3 = GraphExport::Create(*equal3.output(0),
"dummy");
649 ReduceNode<biteq_op>(BitCompareOperation::foldConstants, equal0);
650 ReduceNode<biteq_op>(BitCompareOperation::foldConstants, equal1);
651 ReduceNode<biteq_op>(BitCompareOperation::foldConstants, equal2);
652 ReduceNode<biteq_op>(BitCompareOperation::foldConstants, equal3);
658 EXPECT_EQ(TryGetOwnerNode<SimpleNode>(*ex0.origin())->GetOperation(),
biteq_op(32));
661 EXPECT_EQ(TryGetOwnerNode<SimpleNode>(*ex3.origin())->GetOperation(),
biteq_op(32));
664TEST(bitstring, comparison_test_bitnotequal)
672 auto c0 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 4 });
673 auto c1 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 5 });
674 auto c2 = &BitConstantOperation::createUndefined(graph.
GetRootRegion(), 32);
676 auto & nequal0 = CreateOpNode<bitne_op>({ s0, s1 }, 32);
677 auto & nequal1 = CreateOpNode<bitne_op>({ c0, c0 }, 32);
678 auto & nequal2 = CreateOpNode<bitne_op>({ c0,
c1 }, 32);
679 auto & nequal3 = CreateOpNode<bitne_op>({ c0,
c2 }, 32);
681 auto & ex0 = GraphExport::Create(*nequal0.output(0),
"dummy");
682 auto & ex1 = GraphExport::Create(*nequal1.output(0),
"dummy");
683 auto & ex2 = GraphExport::Create(*nequal2.output(0),
"dummy");
684 auto & ex3 = GraphExport::Create(*nequal3.output(0),
"dummy");
689 ReduceNode<bitne_op>(BitCompareOperation::foldConstants, nequal0);
690 ReduceNode<bitne_op>(BitCompareOperation::foldConstants, nequal1);
691 ReduceNode<bitne_op>(BitCompareOperation::foldConstants, nequal2);
692 ReduceNode<bitne_op>(BitCompareOperation::foldConstants, nequal3);
698 EXPECT_EQ(TryGetOwnerNode<SimpleNode>(*ex0.origin())->GetOperation(),
bitne_op(32));
701 EXPECT_EQ(TryGetOwnerNode<SimpleNode>(*ex3.origin())->GetOperation(),
bitne_op(32));
704TEST(bitstring, comparison_test_bitsgreater)
713 auto c0 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 4 });
714 auto c1 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 5 });
715 auto c2 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 0x7fffffffL });
716 auto c3 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, (-0x7fffffffL - 1) });
718 auto & sgreater0 = CreateOpNode<bitsgt_op>({ s0, s1 }, 32);
719 auto & sgreater1 = CreateOpNode<bitsgt_op>({ c0,
c1 }, 32);
720 auto & sgreater2 = CreateOpNode<bitsgt_op>({
c1, c0 }, 32);
721 auto & sgreater3 = CreateOpNode<bitsgt_op>({ s0,
c2 }, 32);
722 auto & sgreater4 = CreateOpNode<bitsgt_op>({ c3, s1 }, 32);
724 auto & ex0 = GraphExport::Create(*sgreater0.output(0),
"dummy");
725 auto & ex1 = GraphExport::Create(*sgreater1.output(0),
"dummy");
726 auto & ex2 = GraphExport::Create(*sgreater2.output(0),
"dummy");
727 auto & ex3 = GraphExport::Create(*sgreater3.output(0),
"dummy");
728 auto & ex4 = GraphExport::Create(*sgreater4.output(0),
"dummy");
733 ReduceNode<bitsgt_op>(BitCompareOperation::foldConstants, sgreater0);
734 ReduceNode<bitsgt_op>(BitCompareOperation::foldConstants, sgreater1);
735 ReduceNode<bitsgt_op>(BitCompareOperation::foldConstants, sgreater2);
736 ReduceNode<bitsgt_op>(BitCompareOperation::foldConstants, sgreater3);
737 ReduceNode<bitsgt_op>(BitCompareOperation::foldConstants, sgreater4);
743 EXPECT_EQ(TryGetOwnerNode<SimpleNode>(*ex0.origin())->GetOperation(),
bitsgt_op(32));
750TEST(bitstring, comparison_test_bitsgreatereq)
758 auto c0 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 4 });
759 auto c1 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 5 });
760 auto c2 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 0x7fffffffL });
761 auto c3 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, (-0x7fffffffL - 1) });
763 auto & sgreatereq0 = CreateOpNode<bitsge_op>({ s0, s1 }, 32);
764 auto & sgreatereq1 = CreateOpNode<bitsge_op>({ c0,
c1 }, 32);
765 auto & sgreatereq2 = CreateOpNode<bitsge_op>({
c1, c0 }, 32);
766 auto & sgreatereq3 = CreateOpNode<bitsge_op>({ c0, c0 }, 32);
767 auto & sgreatereq4 = CreateOpNode<bitsge_op>({
c2, s0 }, 32);
768 auto & sgreatereq5 = CreateOpNode<bitsge_op>({ s1, c3 }, 32);
770 auto & ex0 = GraphExport::Create(*sgreatereq0.output(0),
"dummy");
771 auto & ex1 = GraphExport::Create(*sgreatereq1.output(0),
"dummy");
772 auto & ex2 = GraphExport::Create(*sgreatereq2.output(0),
"dummy");
773 auto & ex3 = GraphExport::Create(*sgreatereq3.output(0),
"dummy");
774 auto & ex4 = GraphExport::Create(*sgreatereq4.output(0),
"dummy");
775 auto & ex5 = GraphExport::Create(*sgreatereq5.output(0),
"dummy");
780 ReduceNode<bitsge_op>(BitCompareOperation::foldConstants, sgreatereq0);
781 ReduceNode<bitsge_op>(BitCompareOperation::foldConstants, sgreatereq1);
782 ReduceNode<bitsge_op>(BitCompareOperation::foldConstants, sgreatereq2);
783 ReduceNode<bitsge_op>(BitCompareOperation::foldConstants, sgreatereq3);
784 ReduceNode<bitsge_op>(BitCompareOperation::foldConstants, sgreatereq4);
785 ReduceNode<bitsge_op>(BitCompareOperation::foldConstants, sgreatereq5);
791 EXPECT_EQ(TryGetOwnerNode<SimpleNode>(*ex0.origin())->GetOperation(),
bitsge_op(32));
799TEST(bitstring, comparison_test_bitsless)
808 auto c0 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 4 });
809 auto c1 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 5 });
810 auto c2 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 0x7fffffffL });
811 auto c3 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, (-0x7fffffffL - 1) });
813 auto & sless0 = CreateOpNode<bitslt_op>({ s0, s1 }, 32);
814 auto & sless1 = CreateOpNode<bitslt_op>({ c0,
c1 }, 32);
815 auto & sless2 = CreateOpNode<bitslt_op>({
c1, c0 }, 32);
816 auto & sless3 = CreateOpNode<bitslt_op>({
c2, s0 }, 32);
817 auto & sless4 = CreateOpNode<bitslt_op>({ s1, c3 }, 32);
819 auto & ex0 = GraphExport::Create(*sless0.output(0),
"dummy");
820 auto & ex1 = GraphExport::Create(*sless1.output(0),
"dummy");
821 auto & ex2 = GraphExport::Create(*sless2.output(0),
"dummy");
822 auto & ex3 = GraphExport::Create(*sless3.output(0),
"dummy");
823 auto & ex4 = GraphExport::Create(*sless4.output(0),
"dummy");
828 ReduceNode<bitslt_op>(BitCompareOperation::foldConstants, sless0);
829 ReduceNode<bitslt_op>(BitCompareOperation::foldConstants, sless1);
830 ReduceNode<bitslt_op>(BitCompareOperation::foldConstants, sless2);
831 ReduceNode<bitslt_op>(BitCompareOperation::foldConstants, sless3);
832 ReduceNode<bitslt_op>(BitCompareOperation::foldConstants, sless4);
838 EXPECT_EQ(TryGetOwnerNode<SimpleNode>(*ex0.origin())->GetOperation(),
bitslt_op(32));
845TEST(bitstring, comparison_test_bitslesseq)
854 auto c0 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 4 });
855 auto c1 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 5 });
856 auto c2 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 0x7fffffffL });
857 auto c3 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, (-0x7fffffffL - 1) });
859 auto & slesseq0 = CreateOpNode<bitsle_op>({ s0, s1 }, 32);
860 auto & slesseq1 = CreateOpNode<bitsle_op>({ c0,
c1 }, 32);
861 auto & slesseq2 = CreateOpNode<bitsle_op>({ c0, c0 }, 32);
862 auto & slesseq3 = CreateOpNode<bitsle_op>({
c1, c0 }, 32);
863 auto & slesseq4 = CreateOpNode<bitsle_op>({ s0,
c2 }, 32);
864 auto & slesseq5 = CreateOpNode<bitsle_op>({ c3, s1 }, 32);
866 auto & ex0 = GraphExport::Create(*slesseq0.output(0),
"dummy");
867 auto & ex1 = GraphExport::Create(*slesseq1.output(0),
"dummy");
868 auto & ex2 = GraphExport::Create(*slesseq2.output(0),
"dummy");
869 auto & ex3 = GraphExport::Create(*slesseq3.output(0),
"dummy");
870 auto & ex4 = GraphExport::Create(*slesseq4.output(0),
"dummy");
871 auto & ex5 = GraphExport::Create(*slesseq5.output(0),
"dummy");
876 ReduceNode<bitsle_op>(BitCompareOperation::foldConstants, slesseq0);
877 ReduceNode<bitsle_op>(BitCompareOperation::foldConstants, slesseq1);
878 ReduceNode<bitsle_op>(BitCompareOperation::foldConstants, slesseq2);
879 ReduceNode<bitsle_op>(BitCompareOperation::foldConstants, slesseq3);
880 ReduceNode<bitsle_op>(BitCompareOperation::foldConstants, slesseq4);
881 ReduceNode<bitsle_op>(BitCompareOperation::foldConstants, slesseq5);
887 EXPECT_EQ(TryGetOwnerNode<SimpleNode>(*ex0.origin())->GetOperation(),
bitsle_op(32));
895TEST(bitstring, comparison_test_bitugreater)
903 auto c0 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 4 });
904 auto c1 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 5 });
905 auto c2 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, (0xffffffffUL) });
906 auto c3 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 0 });
908 auto & ugreater0 = CreateOpNode<bitugt_op>({ s0, s1 }, 32);
909 auto & ugreater1 = CreateOpNode<bitugt_op>({ c0,
c1 }, 32);
910 auto & ugreater2 = CreateOpNode<bitugt_op>({
c1, c0 }, 32);
911 auto & ugreater3 = CreateOpNode<bitugt_op>({ s0,
c2 }, 32);
912 auto & ugreater4 = CreateOpNode<bitugt_op>({ c3, s1 }, 32);
914 auto & ex0 = GraphExport::Create(*ugreater0.output(0),
"dummy");
915 auto & ex1 = GraphExport::Create(*ugreater1.output(0),
"dummy");
916 auto & ex2 = GraphExport::Create(*ugreater2.output(0),
"dummy");
917 auto & ex3 = GraphExport::Create(*ugreater3.output(0),
"dummy");
918 auto & ex4 = GraphExport::Create(*ugreater4.output(0),
"dummy");
923 ReduceNode<bitugt_op>(BitCompareOperation::foldConstants, ugreater0);
924 ReduceNode<bitugt_op>(BitCompareOperation::foldConstants, ugreater1);
925 ReduceNode<bitugt_op>(BitCompareOperation::foldConstants, ugreater2);
926 ReduceNode<bitugt_op>(BitCompareOperation::foldConstants, ugreater3);
927 ReduceNode<bitugt_op>(BitCompareOperation::foldConstants, ugreater4);
933 EXPECT_EQ(TryGetOwnerNode<SimpleNode>(*ex0.origin())->GetOperation(),
bitugt_op(32));
940TEST(bitstring, comparison_test_bitugreatereq)
948 auto c0 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 4 });
949 auto c1 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 5 });
950 auto c2 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, (0xffffffffUL) });
951 auto c3 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 0 });
953 auto & ugreatereq0 = CreateOpNode<bituge_op>({ s0, s1 }, 32);
954 auto & ugreatereq1 = CreateOpNode<bituge_op>({ c0,
c1 }, 32);
955 auto & ugreatereq2 = CreateOpNode<bituge_op>({
c1, c0 }, 32);
956 auto & ugreatereq3 = CreateOpNode<bituge_op>({ c0, c0 }, 32);
957 auto & ugreatereq4 = CreateOpNode<bituge_op>({
c2, s0 }, 32);
958 auto & ugreatereq5 = CreateOpNode<bituge_op>({ s1, c3 }, 32);
960 auto & ex0 = GraphExport::Create(*ugreatereq0.output(0),
"dummy");
961 auto & ex1 = GraphExport::Create(*ugreatereq1.output(0),
"dummy");
962 auto & ex2 = GraphExport::Create(*ugreatereq2.output(0),
"dummy");
963 auto & ex3 = GraphExport::Create(*ugreatereq3.output(0),
"dummy");
964 auto & ex4 = GraphExport::Create(*ugreatereq4.output(0),
"dummy");
965 auto & ex5 = GraphExport::Create(*ugreatereq5.output(0),
"dummy");
970 ReduceNode<bituge_op>(BitCompareOperation::foldConstants, ugreatereq0);
971 ReduceNode<bituge_op>(BitCompareOperation::foldConstants, ugreatereq1);
972 ReduceNode<bituge_op>(BitCompareOperation::foldConstants, ugreatereq2);
973 ReduceNode<bituge_op>(BitCompareOperation::foldConstants, ugreatereq3);
974 ReduceNode<bituge_op>(BitCompareOperation::foldConstants, ugreatereq4);
975 ReduceNode<bituge_op>(BitCompareOperation::foldConstants, ugreatereq5);
981 EXPECT_EQ(TryGetOwnerNode<SimpleNode>(*ex0.origin())->GetOperation(),
bituge_op(32));
989TEST(bitstring, bitstring_comparison_test_bituless)
998 auto c0 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 4 });
999 auto c1 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 5 });
1000 auto c2 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, (0xffffffffUL) });
1001 auto c3 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 0 });
1003 auto & uless0 = CreateOpNode<bitult_op>({ s0, s1 }, 32);
1004 auto & uless1 = CreateOpNode<bitult_op>({ c0,
c1 }, 32);
1005 auto & uless2 = CreateOpNode<bitult_op>({
c1, c0 }, 32);
1006 auto & uless3 = CreateOpNode<bitult_op>({
c2, s0 }, 32);
1007 auto & uless4 = CreateOpNode<bitult_op>({ s1, c3 }, 32);
1009 auto & ex0 = GraphExport::Create(*uless0.output(0),
"dummy");
1010 auto & ex1 = GraphExport::Create(*uless1.output(0),
"dummy");
1011 auto & ex2 = GraphExport::Create(*uless2.output(0),
"dummy");
1012 auto & ex3 = GraphExport::Create(*uless3.output(0),
"dummy");
1013 auto & ex4 = GraphExport::Create(*uless4.output(0),
"dummy");
1018 ReduceNode<bitult_op>(BitCompareOperation::foldConstants, uless0);
1019 ReduceNode<bitult_op>(BitCompareOperation::foldConstants, uless1);
1020 ReduceNode<bitult_op>(BitCompareOperation::foldConstants, uless2);
1021 ReduceNode<bitult_op>(BitCompareOperation::foldConstants, uless3);
1022 ReduceNode<bitult_op>(BitCompareOperation::foldConstants, uless4);
1028 EXPECT_EQ(TryGetOwnerNode<SimpleNode>(*ex0.origin())->GetOperation(),
bitult_op(32));
1035TEST(bitstring, bitstring_comparison_test_bitulesseq)
1044 auto c0 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 4 });
1045 auto c1 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 5 });
1046 auto c2 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, (0xffffffffUL) });
1047 auto c3 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 0 });
1049 auto & ulesseq0 = CreateOpNode<bitule_op>({ s0, s1 }, 32);
1050 auto & ulesseq1 = CreateOpNode<bitule_op>({ c0,
c1 }, 32);
1051 auto & ulesseq2 = CreateOpNode<bitule_op>({ c0, c0 }, 32);
1052 auto & ulesseq3 = CreateOpNode<bitule_op>({
c1, c0 }, 32);
1053 auto & ulesseq4 = CreateOpNode<bitule_op>({ s0,
c2 }, 32);
1054 auto & ulesseq5 = CreateOpNode<bitule_op>({ c3, s1 }, 32);
1056 auto & ex0 = GraphExport::Create(*ulesseq0.output(0),
"dummy");
1057 auto & ex1 = GraphExport::Create(*ulesseq1.output(0),
"dummy");
1058 auto & ex2 = GraphExport::Create(*ulesseq2.output(0),
"dummy");
1059 auto & ex3 = GraphExport::Create(*ulesseq3.output(0),
"dummy");
1060 auto & ex4 = GraphExport::Create(*ulesseq4.output(0),
"dummy");
1061 auto & ex5 = GraphExport::Create(*ulesseq5.output(0),
"dummy");
1066 ReduceNode<bitule_op>(BitCompareOperation::foldConstants, ulesseq0);
1067 ReduceNode<bitule_op>(BitCompareOperation::foldConstants, ulesseq1);
1068 ReduceNode<bitule_op>(BitCompareOperation::foldConstants, ulesseq2);
1069 ReduceNode<bitule_op>(BitCompareOperation::foldConstants, ulesseq3);
1070 ReduceNode<bitule_op>(BitCompareOperation::foldConstants, ulesseq4);
1071 ReduceNode<bitule_op>(BitCompareOperation::foldConstants, ulesseq5);
1077 EXPECT_EQ(TryGetOwnerNode<SimpleNode>(*ex0.origin())->GetOperation(),
bitule_op(32));
1113TEST(bitstring, bitstring_test_constant)
1121 [&](
const SimpleOperation & operation,
const std::vector<jlm::rvsdg::Output *> & operands)
1123 return NormalizeSimpleOperationCommonNodeElimination(
1129 auto & b1 = CreateOpNode<BitConstantOperation>(graph.
GetRootRegion(),
"00110011");
1131 *TryGetOwnerNode<Node>(BitConstantOperation::create(graph.
GetRootRegion(), { 8, 204 }));
1133 *TryGetOwnerNode<Node>(BitConstantOperation::create(graph.
GetRootRegion(), { 8, 204 }));
1134 auto & b4 = CreateOpNode<BitConstantOperation>(graph.
GetRootRegion(),
"001100110");
1136 auto & ex1 = GraphExport::Create(*b1.output(0),
"b1");
1137 auto & ex2 = GraphExport::Create(*b2.output(0),
"b2");
1138 auto & ex3 = GraphExport::Create(*b3.output(0),
"b3");
1139 auto & ex4 = GraphExport::Create(*b4.output(0),
"b4");
1141 view(graph, stdout);
1147 ReduceNode<BitConstantOperation>(NormalizeCne, *TryGetOwnerNode<SimpleNode>(*ex1.origin()));
1148 ReduceNode<BitConstantOperation>(NormalizeCne, *TryGetOwnerNode<SimpleNode>(*ex2.origin()));
1149 ReduceNode<BitConstantOperation>(NormalizeCne, *TryGetOwnerNode<SimpleNode>(*ex3.origin()));
1150 ReduceNode<BitConstantOperation>(NormalizeCne, *TryGetOwnerNode<SimpleNode>(*ex4.origin()));
1152 EXPECT_EQ(ex1.origin(), ex2.origin());
1153 EXPECT_EQ(ex1.origin(), ex3.origin());
1155 const auto node1 = TryGetOwnerNode<SimpleNode>(*ex1.origin());
1159 const auto node4 = TryGetOwnerNode<SimpleNode>(*ex4.origin());
1163 const auto & plus_one_128 =
1168 const auto & minus_one_128 =
1175TEST(bitstring, bitstring_test_normalize)
1185 auto c0 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 3 });
1186 auto c1 = &BitConstantOperation::create(graph.
GetRootRegion(), { 32, 4 });
1188 auto & sum0 = CreateOpNode<bitadd_op>({ imp, c0 }, 32);
1189 auto & sum1 = CreateOpNode<bitadd_op>({ sum0.output(0),
c1 }, 32);
1191 auto & ex = GraphExport::Create(*sum1.output(0),
"dummy");
1196 ReduceNode<bitadd_op>(FlattenAssociativeBinaryOperation, sum1);
1197 auto & flattenedBinaryNode = *TryGetOwnerNode<SimpleNode>(*ex.origin());
1198 ReduceNode<FlattenedBinaryOperation>(NormalizeFlattenedBinaryOperation, flattenedBinaryNode);
1204 auto node = TryGetOwnerNode<SimpleNode>(*ex.origin());
1205 EXPECT_EQ(node->GetOperation(),
bitadd_op(32));
1206 EXPECT_EQ(node->ninputs(), 2u);
1207 auto op1 = node->input(0)->origin();
1208 auto op2 = node->input(1)->origin();
1209 if (!is<NodeOutput>(op1))
1216 EXPECT_EQ(TryGetOwnerNode<SimpleNode>(*op1)->GetOperation(),
BitConstantOperation({ 32, 3 + 4 }));
1217 EXPECT_EQ(op2, imp);
1236 auto bit4Type = BitType::Create(4);
1237 std::vector types({ bit4Type, bit4Type });
1242 auto & bitAndNode = CreateOpNode<bitand_op>({ a, b }, 4);
1243 auto & bitOrNode = CreateOpNode<bitor_op>({ a, b }, 4);
1244 auto & bitXorNode = CreateOpNode<bitxor_op>({ a, b }, 4);
1245 auto & bitAddNode = CreateOpNode<bitadd_op>({ a, b }, 4);
1246 auto & bitMulNode = CreateOpNode<bitmul_op>({ a, b }, 4);
1247 auto & bitConcatNode = CreateOpNode<BitConcatOperation>({ a, b }, types);
1248 auto & bitNegNode1 = CreateOpNode<bitneg_op>({ a }, 4);
1249 auto & bitNegNode2 = CreateOpNode<bitneg_op>({ b }, 4);
1251 auto & exBitAnd = GraphExport::Create(*bitAndNode.output(0),
"bitAnd");
1252 auto & exBitOr = GraphExport::Create(*bitOrNode.output(0),
"bitOr");
1253 auto & exBitXor = GraphExport::Create(*bitXorNode.output(0),
"bitXor");
1254 auto & exBitAdd = GraphExport::Create(*bitAddNode.output(0),
"bitAdd");
1255 auto & exBitMul = GraphExport::Create(*bitMulNode.output(0),
"bitMul");
1256 auto & exBitConcat = GraphExport::Create(*bitConcatNode.output(0),
"bitConcat");
1257 auto & exBitNeg1 = GraphExport::Create(*bitNegNode1.output(0),
"bitNeg1");
1258 auto & exBitNeg2 = GraphExport::Create(*bitNegNode2.output(0),
"bitNeg2");
1263 ReduceNode<bitand_op>(BitBinaryOperation::foldConstants, bitAndNode);
1264 ReduceNode<bitor_op>(BitBinaryOperation::foldConstants, bitOrNode);
1265 ReduceNode<bitxor_op>(BitBinaryOperation::foldConstants, bitXorNode);
1266 ReduceNode<bitadd_op>(BitBinaryOperation::foldConstants, bitAddNode);
1267 ReduceNode<bitmul_op>(BitBinaryOperation::foldConstants, bitMulNode);
1268 ReduceNode<BitConcatOperation>(NormalizeBinaryOperation, bitConcatNode);
1269 ReduceNode<bitneg_op>(BitUnaryOperation::foldConstant, bitNegNode1);
1270 ReduceNode<bitneg_op>(BitUnaryOperation::foldConstant, bitNegNode2);
1285TEST(bitstring, SliceOfConcatReduction)
1291 auto bit16Type = BitType::Create(16);
1292 auto bit32Type = BitType::Create(32);
1293 std::vector types({ bit16Type, bit16Type });
1298 auto & concatNode = CreateOpNode<BitConcatOperation>({ x, y }, types);
1299 auto & sliceNode = CreateOpNode<BitSliceOperation>({ concatNode.output(0) }, bit32Type, 8, 24);
1301 auto & ex = GraphExport::Create(*sliceNode.output(0),
"bitAnd");
1306 ReduceNode<BitSliceOperation>(BitSliceOperation::distributeSlice, sliceNode);
1312 const auto node = TryGetOwnerNode<SimpleNode>(*ex.origin());
1313 const auto o0_node = TryGetOwnerNode<SimpleNode>(*node->input(0)->origin());
1314 const auto o1_node = TryGetOwnerNode<SimpleNode>(*node->input(1)->origin());
1315 EXPECT_TRUE(is<BitConcatOperation>(node->GetOperation()));
1316 EXPECT_EQ(node->ninputs(), 2u);
1317 EXPECT_TRUE(is<BitSliceOperation>(o0_node->GetOperation()));
1318 EXPECT_TRUE(is<BitSliceOperation>(o1_node->GetOperation()));
1321 EXPECT_EQ(attrs->low(), 8u);
1322 EXPECT_EQ(attrs->high(), 16u);
1324 EXPECT_EQ(attrs->low(), 0u);
1325 EXPECT_EQ(attrs->high(), 8u);
1327 EXPECT_EQ(o0_node->input(0)->origin(), x);
1328 EXPECT_EQ(o1_node->input(0)->origin(), y);
1331TEST(bitstring, ConcatOfSliceReduction)
1337 auto bit8Type = BitType::Create(8);
1338 auto bit16Type = BitType::Create(16);
1339 std::vector types({ bit8Type, bit8Type });
1343 auto slice1 = bitslice(x, 0, 8);
1344 auto slice2 = bitslice(x, 8, 16);
1345 auto & concatNode = CreateOpNode<BitConcatOperation>({ slice1, slice2 }, types);
1347 auto & ex = GraphExport::Create(*concatNode.output(0),
"bitAnd");
1352 ReduceNode<BitConcatOperation>(NormalizeBinaryOperation, concatNode);
1358 const auto sliceNode = TryGetOwnerNode<SimpleNode>(*ex.origin());
1360 EXPECT_EQ(sliceNode->input(0)->origin(), x);
1369 auto bit8Type = BitType::Create(8);
1371 const auto constant =
1373 auto & sliceNode = CreateOpNode<BitSliceOperation>({ constant }, bit8Type, 2, 6);
1374 auto & ex = GraphExport::Create(*sliceNode.output(0),
"dummy");
1376 view(graph, stdout);
1379 ReduceNode<BitSliceOperation>(BitSliceOperation::foldConstant, sliceNode);
1382 view(graph, stdout);
1385 const auto node = TryGetOwnerNode<SimpleNode>(*ex.origin());
1396 auto bit4Type = BitType::Create(4);
1400 auto slice1 = bitslice(x, 2, 6);
1401 auto & sliceNode2 = CreateOpNode<BitSliceOperation>({ slice1 }, bit4Type, 1, 3);
1403 auto & ex = GraphExport::Create(*sliceNode2.output(0),
"dummy");
1404 view(graph, stdout);
1407 ReduceNode<BitSliceOperation>(BitSliceOperation::narrowSlice, sliceNode2);
1410 view(graph, stdout);
1413 const auto node = TryGetOwnerNode<SimpleNode>(*ex.origin());
1414 const auto operation =
dynamic_cast<const BitSliceOperation *
>(&node->GetOperation());
1415 EXPECT_EQ(operation->low(), 3u);
1416 EXPECT_EQ(operation->high(), 5u);
1425 auto bit8Type = BitType::Create(8);
1429 auto & sliceNode = CreateOpNode<BitSliceOperation>({ x }, bit8Type, 0, 8);
1431 auto & ex = GraphExport::Create(*sliceNode.output(0),
"dummy");
1432 view(graph, stdout);
1435 ReduceNode<BitSliceOperation>(BitSliceOperation::normalizeIdempotent, sliceNode);
1438 view(graph, stdout);
1441 EXPECT_EQ(ex.origin(), x);
1450 auto bit16Type = BitType::Create(16);
1455 auto concatResult = bitconcat({ x, y });
1456 auto & sliceNode = CreateOpNode<BitSliceOperation>({ concatResult }, bit16Type, 0, 8);
1458 auto & ex = GraphExport::Create(*sliceNode.output(0),
"dummy");
1459 view(graph, stdout);
1462 ReduceNode<BitSliceOperation>(BitSliceOperation::distributeSlice, sliceNode);
1463 auto concatNode = TryGetOwnerNode<SimpleNode>(*ex.origin());
1464 ReduceNode<BitSliceOperation>(
1465 BitSliceOperation::normalizeIdempotent,
1466 *TryGetOwnerNode<SimpleNode>(*concatNode->input(0)->origin()));
1467 concatNode = TryGetOwnerNode<SimpleNode>(*ex.origin());
1468 ReduceNode<BitConcatOperation>(NormalizeBinaryOperation, *concatNode);
1471 view(graph, stdout);
1474 const auto bitType = std::dynamic_pointer_cast<const BitType>(ex.origin()->Type());
1475 ASSERT_TRUE(bitType);
1476 EXPECT_EQ(bitType->nbits(), 8u);
1477 EXPECT_EQ(ex.origin(), x);
1490 auto concatResult1 = bitconcat({ x, y });
1491 auto concatResult2 = bitconcat({ concatResult1, z });
1493 auto & ex = GraphExport::Create(*concatResult2,
"dummy");
1494 view(graph, stdout);
1497 const auto concatNode = TryGetOwnerNode<SimpleNode>(*ex.origin());
1498 ReduceNode<BitConcatOperation>(FlattenBitConcatOperation, *concatNode);
1500 view(graph, stdout);
1503 auto node = TryGetOwnerNode<SimpleNode>(*ex.origin());
1504 EXPECT_TRUE(is<BitConcatOperation>(node->GetOperation()));
1505 EXPECT_EQ(node->ninputs(), 3u);
1506 EXPECT_EQ(node->input(0)->origin(), x);
1507 EXPECT_EQ(node->input(1)->origin(), y);
1508 EXPECT_EQ(node->input(2)->origin(), z);
1511TEST(bitstring, ConcatWithSingleOperand)
1517 auto bit8Type = BitType::Create(8);
1518 std::vector bit8Types({ bit8Type });
1522 auto & concatNode = CreateOpNode<BitConcatOperation>({ x }, bit8Types);
1524 auto & ex = GraphExport::Create(*concatNode.output(0),
"dummy");
1525 view(graph, stdout);
1528 ReduceNode<BitConcatOperation>(NormalizeBinaryOperation, concatNode);
1531 view(graph, stdout);
1534 EXPECT_EQ(ex.origin(), x);
1543 auto bit4Type = BitType::Create(4);
1544 std::vector bit4Types({ bit4Type, bit4Type });
1548 auto sliceResult1 = bitslice(x, 0, 4);
1549 auto sliceResult2 = bitslice(x, 4, 8);
1550 auto & concatNode = CreateOpNode<BitConcatOperation>({ sliceResult1, sliceResult2 }, bit4Types);
1552 auto & ex = GraphExport::Create(*concatNode.output(0),
"dummy");
1553 view(graph, stdout);
1556 ReduceNode<BitConcatOperation>(NormalizeBinaryOperation, concatNode);
1557 ReduceNode<BitSliceOperation>(
1558 BitSliceOperation::normalizeIdempotent,
1559 *TryGetOwnerNode<SimpleNode>(*ex.origin()));
1562 view(graph, stdout);
1565 EXPECT_EQ(ex.origin(), x);
1574 auto c1 = &BitConstantOperation::create(graph.
GetRootRegion(),
"00110111");
1575 auto c2 = &BitConstantOperation::create(graph.
GetRootRegion(),
"11001000");
1577 auto concatResult = bitconcat({
c1,
c2 });
1579 auto & ex = GraphExport::Create(*concatResult,
"dummy");
1580 view(graph, stdout);
1583 ReduceNode<BitConcatOperation>(
1584 NormalizeBinaryOperation,
1585 *TryGetOwnerNode<SimpleNode>(*ex.origin()));
1588 auto node = TryGetOwnerNode<SimpleNode>(*ex.origin());
1600 [&](
const SimpleOperation & operation,
const std::vector<jlm::rvsdg::Output *> & operands)
1602 return NormalizeSimpleOperationCommonNodeElimination(
1608 auto bitType8 = BitType::Create(8);
1609 std::vector bitTypes({ bitType8, bitType8 });
1614 auto & concatNode1 = CreateOpNode<BitConcatOperation>({ x, y }, bitTypes);
1615 auto & concatNode2 = CreateOpNode<BitConcatOperation>({ x, y }, bitTypes);
1617 auto & ex1 = GraphExport::Create(*concatNode1.output(0),
"dummy");
1618 auto & ex2 = GraphExport::Create(*concatNode2.output(0),
"dummy");
1620 view(graph, stdout);
1623 ReduceNode<BitConcatOperation>(NormalizeCne, *TryGetOwnerNode<SimpleNode>(*ex1.origin()));
1624 ReduceNode<BitConcatOperation>(NormalizeCne, *TryGetOwnerNode<SimpleNode>(*ex2.origin()));
1627 view(graph, stdout);
1630 EXPECT_EQ(ex1.origin(), ex2.origin());
1640 [&](
const SimpleOperation & operation,
const std::vector<jlm::rvsdg::Output *> & operands)
1642 return NormalizeSimpleOperationCommonNodeElimination(
1648 auto bitType8 = BitType::Create(8);
1652 auto & sliceNode1 = CreateOpNode<BitSliceOperation>({ x }, bitType8, 2, 6);
1653 auto & sliceNode2 = CreateOpNode<BitSliceOperation>({ x }, bitType8, 2, 6);
1655 auto & ex1 = GraphExport::Create(*sliceNode1.output(0),
"dummy");
1656 auto & ex2 = GraphExport::Create(*sliceNode2.output(0),
"dummy");
1658 view(graph, stdout);
1661 ReduceNode<BitSliceOperation>(NormalizeCne, *TryGetOwnerNode<SimpleNode>(*ex1.origin()));
1662 ReduceNode<BitSliceOperation>(NormalizeCne, *TryGetOwnerNode<SimpleNode>(*ex2.origin()));
1664 view(graph, stdout);
1667 EXPECT_EQ(ex1.origin(), ex2.origin());