Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Opt] Constant folding for BitExtractStmt #1307

Merged
merged 3 commits into from
Jun 23, 2020

Conversation

xumingkuan
Copy link
Collaborator

@xumingkuan xumingkuan commented Jun 23, 2020

@xumingkuan xumingkuan marked this pull request as draft June 23, 2020 03:40
@xumingkuan xumingkuan marked this pull request as ready for review June 23, 2020 03:48
@codecov
Copy link

codecov bot commented Jun 23, 2020

Codecov Report

Merging #1307 into master will increase coverage by 0.52%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1307      +/-   ##
==========================================
+ Coverage   66.16%   66.68%   +0.52%     
==========================================
  Files          36       36              
  Lines        5077     5094      +17     
  Branches      934      931       -3     
==========================================
+ Hits         3359     3397      +38     
+ Misses       1554     1539      -15     
+ Partials      164      158       -6     
Impacted Files Coverage Δ
python/taichi/core/util.py 21.55% <0.00%> (-0.48%) ⬇️
python/taichi/lang/impl.py 90.06% <0.00%> (-0.14%) ⬇️
python/taichi/lang/matrix.py 90.67% <0.00%> (+0.50%) ⬆️
python/taichi/lang/expr.py 89.75% <0.00%> (+1.69%) ⬆️
python/taichi/lang/__init__.py 75.35% <0.00%> (+2.22%) ⬆️
python/taichi/lang/snode.py 86.02% <0.00%> (+8.68%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1bebc23...a1dcf57. Read the comment docs.

Copy link
Collaborator

@archibate archibate left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, LGTM in general, I only have nits.

Comment on lines 193 to 197
result = (input->val[0].val_int() >> stmt->bit_begin) &
((1LL << (stmt->bit_end - stmt->bit_begin)) - 1);
} else {
result = (input->val[0].val_uint() >> stmt->bit_begin) &
((1LL << (stmt->bit_end - stmt->bit_begin)) - 1);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought BitExtractStmt is only used for i32?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably need to support unsigned inputs as well :-)

Comment on lines +187 to +188
if (!input)
return;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!input)
return;
if (!input || input->element_type() == DataType::i32)
return;

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not do constant folding when the input is i32?

Copy link
Member

@yuanming-hu yuanming-hu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! Just one nit. Thanks!

Comment on lines 193 to 197
result = (input->val[0].val_int() >> stmt->bit_begin) &
((1LL << (stmt->bit_end - stmt->bit_begin)) - 1);
} else {
result = (input->val[0].val_uint() >> stmt->bit_begin) &
((1LL << (stmt->bit_end - stmt->bit_begin)) - 1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably need to support unsigned inputs as well :-)

Comment on lines 199 to 200
auto result_stmt = Stmt::make<ConstStmt>(
LaneAttribute<TypedConstant>(TypedConstant(DataType::i32, result)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the part before already uses uint and int which covers all integral types, here maybe we should support all integral types as well? Just change DataType::i32 into the input data type.

Copy link
Collaborator

@archibate archibate Jun 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or we may need an assertion on input_type != DataType::i8 && input_type != DataType::i16?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the part before already uses uint and int which covers all integral types, here maybe we should support all integral types as well? Just change DataType::i32 into the input data type.

The typecheck pass set ret_type = i32 for OffsetAndExtractBitsStmt. Shall we also change it to the input data type?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or we may need an assertion on input_type != DataType::i8 && input_type != DataType::i16?

I think this is OK -- if the input is representable by i8, so is the output.

@xumingkuan xumingkuan merged commit 5ca95e4 into taichi-dev:master Jun 23, 2020
@FantasyVR FantasyVR mentioned this pull request Jun 24, 2020
Rullec pushed a commit to Rullec/taichi that referenced this pull request Jun 26, 2020
* [Opt] Constant folding for BitExtractStmt

* fix tests

* Let BitExtractStmt support all integral types
@xumingkuan xumingkuan deleted the offset2 branch June 28, 2020 22:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Opt] Let the constant folding pass support OffsetAndExtractBitsStmt
3 participants