Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tic
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wenyuanbo
tic
Commits
e6da0f0b
Unverified
Commit
e6da0f0b
authored
Jun 30, 2019
by
Tianqi Chen
Committed by
GitHub
Jun 30, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[ARITH] CanonicalSimplifier, better folding, eliminate store. (#3464)
parent
75c29c6a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
3 deletions
+34
-3
src/arithmetic/canonical_simplify.cc
+8
-3
src/arithmetic/stmt_simplify.cc
+13
-0
tests/python/unittest/test_arith_canonical_simplify.py
+13
-0
No files found.
src/arithmetic/canonical_simplify.cc
View file @
e6da0f0b
...
...
@@ -256,9 +256,14 @@ class SumExprNode : public CanonicalExprNode {
SplitExpr
&
rhs
=
args
[
j
];
if
(
!
lhs
->
IndexEqual
(
rhs
))
break
;
if
(
lhs
->
upper_factor
<
rhs
->
lower_factor
)
break
;
if
(
lhs
->
lower_factor
==
rhs
->
upper_factor
&&
lhs
->
scale
%
rhs
->
scale
==
0
&&
lhs
->
lower_factor
==
(
lhs
->
scale
/
rhs
->
scale
)
*
rhs
->
lower_factor
)
{
if
(
lhs
->
upper_factor
==
rhs
->
upper_factor
&&
lhs
->
lower_factor
==
rhs
->
lower_factor
)
{
// folding same co-efficient.
rhs
.
CopyOnWrite
()
->
scale
+=
lhs
->
scale
;
lhs
.
CopyOnWrite
()
->
scale
=
0
;
}
else
if
(
lhs
->
lower_factor
==
rhs
->
upper_factor
&&
lhs
->
scale
%
rhs
->
scale
==
0
&&
lhs
->
lower_factor
==
(
lhs
->
scale
/
rhs
->
scale
)
*
rhs
->
lower_factor
)
{
// Rules used in the proof:
//
// Rule 1: (x % (c * s)) / c = (x / c) % s
...
...
src/arithmetic/stmt_simplify.cc
View file @
e6da0f0b
...
...
@@ -106,6 +106,19 @@ class StmtSimplifier : public IRMutator {
}
}
// eliminate useless stores
Stmt
Mutate_
(
const
Store
*
op
,
const
Stmt
&
s
)
{
Stmt
stmt
=
IRMutator
::
Mutate_
(
op
,
s
);
op
=
stmt
.
as
<
Store
>
();
if
(
const
Load
*
load
=
op
->
value
.
as
<
Load
>
())
{
if
(
load
->
buffer_var
.
same_as
(
op
->
buffer_var
)
&&
Equal
(
load
->
index
,
op
->
index
))
{
return
Evaluate
::
make
(
0
);
}
}
return
stmt
;
}
protected
:
Analyzer
analyzer_
;
// variable domain
...
...
tests/python/unittest/test_arith_canonical_simplify.py
View file @
e6da0f0b
...
...
@@ -187,6 +187,18 @@ def test_simplify_if_then_else():
ck
.
verify
(
res
,
0
)
def
test_complex_cases
():
ck
=
CanonicalChecker
()
x
=
tvm
.
var
(
"x"
)
y
=
tvm
.
var
(
"y"
)
res2
=
(((((((((((
x
*
128
)
+
y
)
%
1296
)
/
36
)
*
2
)
+
1
)
/
2
)
*
36
)
+
((((((
x
*
128
)
+
y
)
%
36
)
*
2
)
+
1
)
/
2
))
-
(((
x
*
128
)
+
y
)
%
1296
))
+
1
)
ck
.
analyzer
.
update
(
x
,
tvm
.
arith
.
ConstIntBound
(
0
,
5
))
ck
.
analyzer
.
update
(
y
,
tvm
.
arith
.
ConstIntBound
(
0
,
127
))
ck
.
verify
(
res2
,
1
)
if
__name__
==
"__main__"
:
test_simplify_if_then_else
()
test_div_simplify
()
...
...
@@ -195,3 +207,4 @@ if __name__ == "__main__":
test_mul_sum_simplify
()
test_split_index_simplify
()
test_canonical_mixed
()
test_complex_cases
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment