47 auto & node1 = Operation::createNode(32, *
c1.output(0), *
c2.output(0));
49 auto & x1 = GraphExport::Create(*node1.output(0),
"x1");
54 ReduceNode<Operation>(Operation::foldConstants,
dynamic_cast<SimpleNode &
>(node1));
62 auto [_, op] = TryGetSimpleNodeAndOptionalOp<IntegerConstantOperation>(*x1.origin());
64 EXPECT_EQ(op->Representation().to_int(), input.expected);
65 EXPECT_EQ(op->Representation().nbits(),
static_cast<size_t>(input.numBitsExpected));
69TEST(IntegerEqOperationTest, foldConstants)
71 TestFoldConstants<IntegerEqOperation>({ 4, 32, 4, 32, -1, 1 });
72 TestFoldConstants<IntegerEqOperation>({ 4, 32, -4, 32, 0, 1 });
75TEST(IntegerNeOperationTest, foldConstants)
77 TestFoldConstants<IntegerNeOperation>({ 4, 32, 4, 32, 0, 1 });
78 TestFoldConstants<IntegerNeOperation>({ 4, 32, -4, 32, -1, 1 });
81TEST(IntegerSgeOperationTest, foldConstants)
83 TestFoldConstants<IntegerSgeOperation>({ 4, 32, 4, 32, -1, 1 });
84 TestFoldConstants<IntegerSgeOperation>({ 4, 32, -4, 32, -1, 1 });
87TEST(IntegerSgtOperationTest, foldConstants)
89 TestFoldConstants<IntegerSgtOperation>({ 4, 32, 4, 32, 0, 1 });
90 TestFoldConstants<IntegerSgtOperation>({ 4, 32, -4, 32, -1, 1 });
93TEST(IntegerSleOperationTest, foldConstants)
95 TestFoldConstants<IntegerSleOperation>({ 4, 32, 4, 32, -1, 1 });
96 TestFoldConstants<IntegerSleOperation>({ 4, 32, -4, 32, 0, 1 });
99TEST(IntegerSltOperationTest, foldConstants)
101 TestFoldConstants<IntegerSltOperation>({ 4, 32, 4, 32, 0, 1 });
102 TestFoldConstants<IntegerSltOperation>({ 4, 32, -4, 32, 0, 1 });
105TEST(IntegerUgeOperationTest, foldConstants)
107 TestFoldConstants<IntegerUgeOperation>({ 4, 32, 4, 32, -1, 1 });
108 TestFoldConstants<IntegerUgeOperation>({ 4, 32, -4, 32, 0, 1 });
111TEST(IntegerUgtOperationTest, foldConstants)
113 TestFoldConstants<IntegerUgtOperation>({ 4, 32, 4, 32, 0, 1 });
114 TestFoldConstants<IntegerUgtOperation>({ 4, 32, -4, 32, 0, 1 });
117TEST(IntegerUleOperationTest, foldConstants)
119 TestFoldConstants<IntegerUleOperation>({ 4, 32, 4, 32, -1, 1 });
120 TestFoldConstants<IntegerUleOperation>({ 4, 32, -4, 32, -1, 1 });
123TEST(IntegerUltOperationTest, foldConstants)
125 TestFoldConstants<IntegerUltOperation>({ 4, 32, 4, 32, 0, 1 });
126 TestFoldConstants<IntegerUltOperation>({ 4, 32, -4, 32, -1, 1 });
129TEST(IntegerOrOperationTest, foldConstants)
131 TestFoldConstants<IntegerOrOperation>({ 4, 32, 4, 32, 4, 32 });
132 TestFoldConstants<IntegerOrOperation>({ 0, 32, -1, 32, -1, 32 });
133 TestFoldConstants<IntegerOrOperation>({ 1, 32, 2, 32, 3, 32 });
136TEST(IntegerAndOperationTest, foldConstants)
138 TestFoldConstants<IntegerAndOperation>({ 4, 32, 4, 32, 4, 32 });
139 TestFoldConstants<IntegerAndOperation>({ 0, 32, -1, 32, 0, 32 });
142TEST(IntegerXorOperationTest, foldConstants)
144 TestFoldConstants<IntegerXorOperation>({ 4, 32, 4, 32, 0, 32 });
145 TestFoldConstants<IntegerXorOperation>({ 0, 32, -1, 32, -1, 32 });
148TEST(IntegerAddOperationTest, foldConstants)
150 TestFoldConstants<IntegerAddOperation>({ 12, 32, 7, 32, 19, 32 });
151 TestFoldConstants<IntegerAddOperation>({ -1, 32, 2, 32, 1, 32 });
154TEST(IntegerSubOperationTest, foldConstants)
156 TestFoldConstants<IntegerSubOperation>({ 12, 32, 7, 32, 5, 32 });
157 TestFoldConstants<IntegerSubOperation>({ 0, 32, 1, 32, -1, 32 });
160TEST(IntegerMulOperationTest, foldConstants)
162 TestFoldConstants<IntegerMulOperation>({ 6, 32, 7, 32, 42, 32 });
163 TestFoldConstants<IntegerMulOperation>({ -6, 32, 7, 32, -42, 32 });
166TEST(IntegerSDivOperationTest, foldConstants)
168 TestFoldConstants<IntegerSDivOperation>({ -13, 32, 3, 32, -4, 32 });
169 TestFoldConstants<IntegerSDivOperation>({ 13, 32, -3, 32, -4, 32 });
172TEST(IntegerUDivOperationTest, foldConstants)
174 TestFoldConstants<IntegerUDivOperation>({ 13, 32, 3, 32, 4, 32 });
175 TestFoldConstants<IntegerUDivOperation>({ -1, 32, 2, 32, 2147483647, 32 });
178TEST(IntegerSRemOperationTest, foldConstants)
180 TestFoldConstants<IntegerSRemOperation>({ -13, 32, 3, 32, -1, 32 });
181 TestFoldConstants<IntegerSRemOperation>({ 13, 32, -3, 32, 1, 32 });
184TEST(IntegerURemOperationTest, foldConstants)
186 TestFoldConstants<IntegerURemOperation>({ 13, 32, 3, 32, 1, 32 });
187 TestFoldConstants<IntegerURemOperation>({ -1, 32, 10, 32, 5, 32 });
190TEST(IntegerAShrOperationTest, foldConstants)
192 TestFoldConstants<IntegerAShrOperation>({ -0x10, 32, 2, 32, -0x4, 32 });
193 TestFoldConstants<IntegerAShrOperation>({ 0x10, 32, 2, 32, 0x4, 32 });
196TEST(IntegerShlOperationTest, foldConstants)
198 TestFoldConstants<IntegerShlOperation>({ 0x3, 32, 2, 32, 0xc, 32 });
199 TestFoldConstants<IntegerShlOperation>({ 0x400, 32, 2, 32, 0x1000, 32 });
202TEST(IntegerLShrOperationTest, foldConstants)
204 TestFoldConstants<IntegerLShrOperation>({ -0x1, 32, 2, 32, 0x3fffffff, 32 });
205 TestFoldConstants<IntegerLShrOperation>({ 0x10, 32, 2, 32, 0x4, 32 });
208TEST(IntegerSubOperationTests, normalizeAdditiveInverse)
213 auto i32Type = BitType::Create(32);
217 auto & i0 = GraphImport::Create(graph, i32Type,
"i0");
219 auto structuralNode = TestStructuralNode::create(&graph.
GetRootRegion(), 1);
220 auto inputVar = structuralNode->addInputWithArguments(i0);
225 auto outputVar = structuralNode->addOutputWithResults({ subNode.output(0) });
227 GraphExport::Create(*outputVar.output,
"x0");
230 ReduceNode<IntegerSubOperation>(
241 TryGetSimpleNodeAndOptionalOp<IntegerConstantOperation>(*outputVar.result[0]->origin());
243 EXPECT_EQ(op->Representation().to_int(), 0u);
244 EXPECT_EQ(op->Representation().nbits(), 32u);