39
39
#include " xls/passes/optimization_pass.h"
40
40
#include " xls/passes/pass_base.h"
41
41
#include " xls/solvers/z3_ir_equivalence.h"
42
+ #include " xls/solvers/z3_ir_equivalence_testutils.h"
42
43
43
44
namespace m = ::xls::op_matchers;
44
45
@@ -48,6 +49,7 @@ namespace {
48
49
constexpr absl::Duration kProverTimeout = absl::Seconds(10 );
49
50
50
51
using status_testing::IsOkAndHolds;
52
+ using ::xls::solvers::z3::ScopedVerifyEquivalence;
51
53
using ::xls::solvers::z3::TryProveEquivalence;
52
54
53
55
using ::testing::AllOf;
@@ -329,7 +331,7 @@ TEST_F(ArithSimplificationPassTest, SubFallsToZero) {
329
331
FunctionBuilder fb (TestName (), p.get ());
330
332
auto param = fb.Param (" x" , p->GetBitsType (32 ));
331
333
fb.Subtract (param, param);
332
- XLS_ASSERT_OK_AND_ASSIGN (Function* f, fb.Build ());
334
+ XLS_ASSERT_OK_AND_ASSIGN (Function * f, fb.Build ());
333
335
ASSERT_THAT (Run (p.get ()), IsOkAndHolds (true ));
334
336
EXPECT_THAT (f->return_value (), m::Literal (0 ));
335
337
}
@@ -2177,5 +2179,45 @@ TEST_F(ArithSimplificationPassTest, ShiftLeftOfPowerOfTwo) {
2177
2179
IsOkAndHolds (true ));
2178
2180
}
2179
2181
2182
+ TEST_F (ArithSimplificationPassTest, AddInverses) {
2183
+ auto p = CreatePackage ();
2184
+ FunctionBuilder fb (TestName (), p.get ());
2185
+ BValue p1 = fb.Param (" p1" , p->GetBitsType (32 ));
2186
+ fb.Tuple ({
2187
+ fb.Add (p1, fb.Not (p1)),
2188
+ fb.Add (fb.Not (p1), p1),
2189
+ });
2190
+ XLS_ASSERT_OK_AND_ASSIGN (Function * f, fb.Build ());
2191
+
2192
+ ScopedVerifyEquivalence sve (f);
2193
+ ASSERT_THAT (Run (p.get ()), IsOkAndHolds (true ));
2194
+
2195
+ EXPECT_THAT (
2196
+ f->return_value (),
2197
+ m::Tuple (m::Literal (Bits::AllOnes (32 )), m::Literal (Bits::AllOnes (32 ))));
2198
+ }
2199
+
2200
+ TEST_F (ArithSimplificationPassTest, OrInverses) {
2201
+ auto p = CreatePackage ();
2202
+ FunctionBuilder fb (TestName (), p.get ());
2203
+ BValue p1 = fb.Param (" p1" , p->GetBitsType (32 ));
2204
+ BValue p2 = fb.Param (" p2" , p->GetBitsType (32 ));
2205
+ fb.Tuple ({
2206
+ fb.Or (p1, fb.Not (p1)),
2207
+ fb.Or (fb.Not (p1), p1),
2208
+ fb.Or ({p1, p2, fb.Not (p1)}),
2209
+ fb.Or ({p1, p2, fb.Not (p2)}),
2210
+ });
2211
+ XLS_ASSERT_OK_AND_ASSIGN (Function * f, fb.Build ());
2212
+
2213
+ ScopedVerifyEquivalence sve (f);
2214
+ ASSERT_THAT (Run (p.get ()), IsOkAndHolds (true ));
2215
+
2216
+ EXPECT_THAT (
2217
+ f->return_value (),
2218
+ m::Tuple (m::Literal (Bits::AllOnes (32 )), m::Literal (Bits::AllOnes (32 )),
2219
+ m::Literal (Bits::AllOnes (32 )), m::Literal (Bits::AllOnes (32 ))));
2220
+ }
2221
+
2180
2222
} // namespace
2181
2223
} // namespace xls
0 commit comments