-
Notifications
You must be signed in to change notification settings - Fork 785
[Emitting Zero] [Local Tracking] General rule might not handle unary ne emitting zero bits well #7493
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
Comments
Yes, limitations of local tracking hit us here: we don't see all the contents in the local, just part of the pattern we are looking for. I think, however, that a good fix for this would actually be in SimplifyLocals. That will normally move the local into the use: (local.set $0
(i32.shr_s
(i32.shl
(i32.load
(i32.const 0)
)
(i32.const 1)
)
(i32.const 1)
)
)
(if
(i32.ne
(local.get $0)
(i32.const -259031342)
)
(then
(unreachable)
)
)
=>
(if
(i32.ne
(i32.shr_s
(i32.shl
(i32.load
(i32.const 0)
)
(i32.const 1)
)
(i32.const 1)
)
(i32.const -259031342)
)
(then
(unreachable)
)
) (and remove the local.set). The problem here is the inner load, which has effects - that pass sees effects on the
(local.set $0
(i32.eqz
(i32.load)
)
)
=>
(local.set $inner
(i32.load)
)
(local.set $0
(i32.eqz
(local.get $inner)
)
) This is the opposite of what SimplifyLocals does, but it would solve a whole range of these issues, I think. |
That was a clear explanation; I understand now. The Sounds the first solution is limited, second is more general. Add a new pass which could find operations with side-effect and isolate them with temporary variable, thus SimplifyLocals could do inlining as normal. But how much do these solutions cost? Is it good enough to fix #7492? |
It wouldn't fix that particular issue - the problem there wasn't an inner expression with effects like the load in the last example. But it would fix this, and iirc a few others. This is a general situation we don't yet handle well enough. Flatten was, in theory, the solution to this, but it does a lot more: Lines 45 to 55 in e185ff9
We need 1 and 3 from that list, but not 2 and 4. Perhaps a variant of the Flatten pass that only does them is an option here, "minimally flatten" or "flatten expressions (but not control flow)". |
Given the following code:
wasm-opt (755a8d0) should deduce the condition to false, thus fold the branch to
unreachable
(further deletingcall $bar
), which works under-O2
but fails under-O3
.Below is optimized by
-all -O3
:As you can see, the condition here
is not deduced to true.
Similar to #7492, Maybe there a missing rule for it to emit zero bits, or is the local tracking insufficient?
The text was updated successfully, but these errors were encountered: