-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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] Add a strength reduction pass #944
Comments
Thanks for proposing this!
Yes, that would be helpful. But we need to add
Sounds good. I don't think there's a need to separate two passes.
All SGTM. |
Cool! power of 2 is really common. But we don't have that yet, but we can have that in a sep PR for that purpose. eg. bit_shl, bit_shr.
Sounds better than the current sol, thx! I guess we will move the python-side pow opt all into this c++ pass. |
Great! Could you also optimize Currently, taichi/python/taichi/lang/expr.py Lines 91 to 93 in 471392b
And it's preventing such an optimization. Right now if I change this taichi/examples/sdf_renderer.py Line 53 in 471392b
i & 1 == 1 , then the example runs faster by ~4% on Metal... (i.e. 24sps -> 25sps )
|
Let's make it |
I wonder why we didn't just use |
Test case: ti.init(print_ir=True)
@ti.kernel
def func(i: ti.i32):
if i % 2 == 1:
print(i)
func(1) Result:
|
|
Maybe we can just replace |
Yeah, but before that maybe we need an IR pattern matcher so that we can quickly locate patterns like these in Taichi IR. |
I wonder how an "IR pattern matcher" works? |
Halide's source files that starts with |
Current result when the data type is u32 after #2332:
|
I found it hard to optimize |
Maybe we want to refer to numpy/numpy#17727 for further optimizations. |
Update after #1065:
TODO:
shl
andshr
for optimizationa % pot (power of two constant) -> a & (pot - 1)
Concisely describe the proposed feature
I would like to add a pass like https://en.wikipedia.org/wiki/Strength_reduction.
A list of peephole optimizations in this pass (done in #1065):
a * 2 -> a + a
a / const -> a * (1 / const)
(floating point only)a ** 2 -> a * a
(this should fix [Lang] ti.sqr(x) is now deprecated: please use x ** 2 instead #937 (comment) in a more systematic way)a ** 1 -> a
should be added in the algebraic simplification pass)(Feel free to add more optimizations to this list)
Describe the solution you'd like (if any)
I would like to place this pass in
full_simplify
likealg_simp
.Additional comments
Shall we replace
<i32x1> a * c
wherec
is a constant power of 2 witha << log2(c)
(and also replace<i32x1> a / c
witha >> log2(c)
)? Do we have<<
and>>
operators?Shall we just write the optimization in the
alg_simp
pass and add anAlgSimp::alg_is_two
function instead of introducing a new pass?Shall we expose functions
AlgSimp::alg_is_one
to somewhere so that more passes can use them, and we can split the useless assertion elimination to a new pass?The text was updated successfully, but these errors were encountered: