1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20 #include <dmlc/logging.h>
21 #include <gtest/gtest.h>
22 #include <tvm/ir_pass.h>
23 #include <tvm/operation.h>
24
TEST(IRSIMPLIFY,MinMax)25 TEST(IRSIMPLIFY, MinMax) {
26 auto x = tvm::var("x");
27 auto e1 = (tvm::max(x, 1) - tvm::max(x, 1)) ;
28 auto e1s = tvm::ir::CanonicalSimplify(e1);
29 CHECK(is_zero(e1s));
30
31 auto e2 = (x * tvm::min(x, 1)) - (x * tvm::min(x, 1));
32 auto e2s = tvm::ir::CanonicalSimplify(e2);
33 CHECK(is_zero(e2s));
34 }
35
TEST(IRSIMPLIFY,Mul)36 TEST(IRSIMPLIFY, Mul) {
37 auto x = tvm::var("x");
38 auto e = (x * x) - (x * x) ;
39 auto es = tvm::ir::CanonicalSimplify(e);
40 CHECK(is_zero(es));
41 }
42
TEST(IRSIMPLIFY,Mod)43 TEST(IRSIMPLIFY, Mod) {
44 auto x = tvm::Integer(10);
45 auto y = tvm::Integer(12);
46 // Mod::make is used instead of % to avoid constant folding during
47 // calling operator%(x,y). Mod::make doesn't try constant folding,
48 // and therefore, the constant folding will be attempted in CanonicalSimplify
49 auto mod = tvm::ir::CanonicalSimplify(tvm::ir::Mod::make(x, y));
50 auto es = tvm::ir::CanonicalSimplify(mod - x);
51 CHECK(is_zero(es));
52 }
main(int argc,char ** argv)53 int main(int argc, char ** argv) {
54 testing::InitGoogleTest(&argc, argv);
55 testing::FLAGS_gtest_death_test_style = "threadsafe";
56 return RUN_ALL_TESTS();
57 }
58