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] Simplify multiplying/dividing POT #2332

Merged
merged 6 commits into from
May 12, 2021
Merged

Conversation

xumingkuan
Copy link
Contributor

@xumingkuan xumingkuan commented May 11, 2021

Related issue = #944 #656 #2177

This PR may help with some optimizations after #2327 is merged. When we want to access a leaf (place) SNode and (the same address of) its parent or some ancestor, simple optimizations such as CSE can remove the duplicated part of the access paths after lower_access when nonconsecutive indices are used (now). However, when consecutive indices are used, we may have some code like this:

a = ti.field(ti.i32)
block = root.dense(ti.i, 64)
block.dense(ti.i, 3).place(a)

@ti.kernel
def foo():
  for i in ...:
    ti.activate(block, i / 8)
    a[i]...

And we want the common part of block[i / 8] and a[i] is reused in the two accesses. After expanding the BitExtractStmt, the former one will be (i / 8) & 63 and the latter one will be (i >> 3) & 63. This PR replaces i / 8 with i >> 3, and further replaces (a >> b) >> c with a >> (b + c) when both b and c are constants, so that CSE will be able to remove the duplicated access paths after lower_access.

This PR also enables constant folding for unsigned data types.

[Click here for the format server]


@xumingkuan xumingkuan requested a review from k-ye May 11, 2021 10:54
Copy link
Member

@k-ye k-ye left a comment

Choose a reason for hiding this comment

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

LGTM!

@k-ye k-ye merged commit ef8d89d into taichi-dev:master May 12, 2021
@BillXu2000 BillXu2000 mentioned this pull request May 13, 2021
@xumingkuan xumingkuan deleted the alg-pot branch June 8, 2021 06:56
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.

2 participants