-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[test] Add tests for value_diff_ptr_index pass (#2244)
* [test] Add tests for value_diff_ptr_index pass * comment
- Loading branch information
Showing
5 changed files
with
128 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#include "gtest/gtest.h" | ||
|
||
#include "taichi/ir/analysis.h" | ||
#include "taichi/ir/ir_builder.h" | ||
#include "taichi/ir/statements.h" | ||
|
||
namespace taichi { | ||
namespace lang { | ||
namespace irpass { | ||
namespace analysis { | ||
|
||
TEST(ValueDiffPtrIndex, ConstI32) { | ||
IRBuilder builder; | ||
|
||
auto *const1 = builder.get_int32(42); | ||
auto *const2 = builder.get_int32(2); | ||
|
||
const auto diff = value_diff_ptr_index(const1, const2); | ||
EXPECT_TRUE(diff.is_diff_certain); | ||
EXPECT_EQ(diff.diff_range, 40); | ||
} | ||
|
||
TEST(ValueDiffPtrIndex, ConstF32) { | ||
IRBuilder builder; | ||
|
||
auto *const1 = builder.get_float32(1.0f); | ||
auto *const2 = builder.get_float32(1.0f); | ||
|
||
const auto diff = value_diff_ptr_index(const1, const2); | ||
// We don't check floating-point numbers since the pass is for pointer indices | ||
EXPECT_FALSE(diff.is_diff_certain); | ||
} | ||
|
||
TEST(ValueDiffPtrIndex, BinOp) { | ||
IRBuilder builder; | ||
|
||
auto *alloca = builder.create_local_var(PrimitiveType::i32); | ||
auto *load = builder.create_local_load(alloca); | ||
auto *const1 = builder.get_int32(1); | ||
auto *bin1 = builder.create_add(load, const1); | ||
auto *bin2 = builder.create_sub(load, const1); | ||
|
||
const auto diff = value_diff_ptr_index(bin1, bin2); | ||
EXPECT_TRUE(diff.is_diff_certain); | ||
EXPECT_EQ(diff.diff_range, 2); | ||
} | ||
|
||
TEST(ValueDiffPtrIndex, BinOpButDiff) { | ||
IRBuilder builder; | ||
|
||
auto *val1_1 = builder.get_int32(1); | ||
auto *val1_2 = builder.get_int32(1); | ||
auto *val2 = builder.get_int32(3); | ||
auto *bin1 = builder.create_add(val1_1, val2); | ||
auto *bin2 = builder.create_add(val1_2, val2); | ||
|
||
const auto diff = value_diff_ptr_index(bin1, bin2); | ||
EXPECT_FALSE(diff.is_diff_certain); | ||
} | ||
|
||
} // namespace analysis | ||
} // namespace irpass | ||
} // namespace lang | ||
} // namespace taichi |