summaryrefslogtreecommitdiff
path: root/src/passes/RedundantSetElimination.cpp
Commit message (Collapse)AuthorAgeFilesLines
* CFGWalker: Allow users to ignore branches outside the function [NFC] (#5838)Alon Zakai2023-07-261-0/+4
| | | | | | | | | A pass that just operates on locals, for example, does not care about branches outside of the function. That means that when we see a call, then even if EH is enabled we don't need to create a new basic block right after it (unless the call is inside a try-catch - then it might branch to the catch, of course). This makes CFG-using passes 9% faster compared to before this PR. This plus #5827 offset the slowdown from #5823 and overall give an improvement compared to before.
* [Wasm GC] RSE: Switch local.get to use a more refined type when possible (#5216)Alon Zakai2022-11-041-28/+92
| | | | | | | | | | | | | | | | Similar to #5194 but for RedundantSetElimination. This has similar benefits in terms of using a more refined local in hopes of avoiding casts in followup opts, but unlike SimplifyLocals this will operate across basic blocks. To do this, we need to track not just local.set but also local.get in that pass. Then in each basic block we can track the equivalent locals and pick from them. I see a few dozen casts removed in the J2Wasm binary. Often stuff like this happens: y = cast(x); if (..) { foo(x); // this could use y }
* RedundantSetElimination: Look at fallthrough values (#5213)Alon Zakai2022-11-031-2/+6
| | | | | | | | | | | This can help in rare cases in MVP wasm, say for the return value of a block. But for wasm GC it is very important due to casts. Similar logic was added as part of #5194 for SimplifyLocals. It should probably have been in a separate PR then. This does the right thing for RedundantSetElimination, as a separate PR. Full tests will appear in that later PR (it is not really possible to test the GC side yet - we need the logic in the later PR that actually switches to a more refined local index when available).
* Refactor interaction between Pass and PassRunner (#5093)Thomas Lively2022-09-301-1/+3
| | | | | | | | | | | | | | Previously only WalkerPasses had access to the `getPassRunner` and `getPassOptions` methods. Move those methods to `Pass` so all passes can use them. As a result, the `PassRunner` passed to `Pass::run` and `Pass::runOnFunction` is no longer necessary, so remove it. Also update `Pass::create` to return a unique_ptr, which is more efficient than having it return a raw pointer only to have the `PassRunner` wrap that raw pointer in a `unique_ptr`. Delete the unused template `PassRunner::getLast()`, which looks like it was intended to enable retrieving previous analyses and has been in the code base since 2015 but is not implemented anywhere.
* RedundantSetElimination: ReFinalize when needed (#4877)Alon Zakai2022-08-091-0/+21
|
* Use LiteralUtils::canMakeZero before calling makeZero (#4568)Alon Zakai2022-04-011-2/+2
| | | | | Fixes #4562 Fixes #4564
* [NFC] Move value numbering code to a header (#4345)Alon Zakai2021-11-191-48/+33
| | | This just moves code out of RedundantSetElimination.
* [Wasm GC] Add a isNonNullable() convenience method. NFC (#3978)Alon Zakai2021-07-121-1/+1
|
* [Wasm GC] Fix RSE on non-nullable locals (#3943)Alon Zakai2021-06-181-2/+7
| | | | | | | | | | RedundantSetElimination checks if a local already has the default value when we assign the default to it. For a non-nullable local, however, there is no initial value - it cannot be used before it is assigned to. So we just need to skip such locals, and not assume they contain a default value we can compare against (we would assert on trying to create a "zero" for such a non-nullable type). Fixes #3942
* Refactor naming convention for functions handling tuples (#3196)Max Graey2020-10-091-1/+1
| | | When there are two versions of a function, one handling tuples and the other handling non-tuple values, the previous naming convention was to have "Single" in the name of the non-tuple handling function. This PR simplifies the convention and shortens function names by making the names plural for the tuple-handling version and singular for the non-tuple-handling version.
* Avoid wasted work when there are no locals (#3060)Max Graey2020-08-241-0/+3
| | | Adds early returns to local optimizations passes in cases where there are no locals to optimize.
* Update RedundantSetElimination to work with tuples (#2688)Thomas Lively2020-03-111-2/+3
| | | | | | | | Also makes it work with any other constant expression such as a ref.func or ref.null instructions. This optimization may not be very important, but it illustrates how simple it can be to update a pass to handle tuples (and also I was already looking at it because of the prior changes that had to be made to it).
* Update Precompute to handle tuples (#2687)Thomas Lively2020-03-101-6/+8
| | | | | | This involves replacing `Literal::makeZero` with `Literal::makeZeroes` and `Literal::makeSingleZero` and updating `isConstantExpression` to handle constant tuples as well. Also makes `Literals` its own struct and adds convenience methods on it.
* Reflect instruction renaming in code (#2128)Heejin Ahn2019-05-211-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | - Reflected new renamed instruction names in code and tests: - `get_local` -> `local.get` - `set_local` -> `local.set` - `tee_local` -> `local.tee` - `get_global` -> `global.get` - `set_global` -> `global.set` - `current_memory` -> `memory.size` - `grow_memory` -> `memory.grow` - Removed APIs related to old instruction names in Binaryen.js and added APIs with new names if they are missing. - Renamed `typedef SortedVector LocalSet` to `SetsOfLocals` to prevent name clashes. - Resolved several TODO renaming items in wasm-binary.h: - `TableSwitch` -> `BrTable` - `I32ConvertI64` -> `I32WrapI64` - `I64STruncI32` -> `I64SExtendI32` - `I64UTruncI32` -> `I64UExtendI32` - `F32ConvertF64` -> `F32DemoteI64` - `F64ConvertF32` -> `F64PromoteF32` - Renamed `BinaryenGetFeatures` and `BinaryenSetFeatures` to `BinaryenModuleGetFeatures` and `BinaryenModuleSetFeatures` for consistency.
* clang-tidy braces changes (#2075)Alon Zakai2019-05-011-2/+4
| | | Applies the changes in #2065, and temprarily disables the hook since it's too slow to run on a change this large. We should re-enable it in a later commit.
* Apply format changes from #2048 (#2059)Alon Zakai2019-04-261-15/+28
| | | Mass change to apply clang-format to everything. We are applying this in a PR by me so the (git) blame is all mine ;) but @aheejin did all the work to get clang-format set up and all the manual work to tidy up some things to make the output nicer in #2048
* Massive renaming (#1855)Thomas Lively2019-01-071-2/+2
| | | | | | Automated renaming according to https://github.com/WebAssembly/spec/issues/884#issuecomment-426433329.
* SIMD (#1820)Thomas Lively2018-12-131-2/+1
| | | | | | | | | Implement and test the following functionality for SIMD. - Parsing and printing - Assembling and disassembling - Interpretation - C API - JS API
* Loop Invariant Code Motion (#1658)Alon Zakai2018-09-041-0/+4
| | | | | | | | | | | | | | | | | | | | | This adds an licm pass. Not that important for LLVM-originating code obviously, but for AssemblyScript and other non-LLVM compilers this might help a lot. Also when wasm has GC a bunch more non-LLVM languages may arrive that can benefit. The pass is mostly straightforward. I considered using the DataFlow IR since it's in SSA form, or the CFG IR, but in the end it's actually pretty convenient to use the main IR as it is - with explicit loops already present - plus LocalGraph which connects each get to the sets influencing it. Passed a bunch of fuzzing, and also the emscripten test suite at -O1 with licm added to the default passes (but I don't think it would make sense to run this by default, as LLVM doesn't need it). We limit code moved by this pass as follows: An increased code size on fuzz testcases (and, more rarely, on real inputs) can happen due to stuff like this: (loop (set_local $x (i32.const 1)) .. ) => (set_local $x (i32.const 1)) (loop .. ) For a const or a get_local, such an assignment to a local is both very cheap (a copy to another local may be optimized out later), and moving it out may prevent other optimizations (since we have no pass that tries to move code back in to a loop edit well, not by default, precompute-propagate etc. would do it, but are only run on high opt levels). So I made the pass not move such trivial code (sets/tees of consts or gets). However, the risk remains if code is moved out that is later reduced to a constant, so something like -Os --flatten --licm -Os may make sense.
* Redundant Set Elimination pass (#1344)Alon Zakai2018-01-051-0/+374
This optimizes #1343. It looks for stores of a value that is already present in the local, which in particular can remove the initial set to 0 of loops starting at zero, since all locals are initialized to that already. This helps in real-world code, but is not super-common since coalescing means we tend to have assigned something else to it anyhow before we need it to be zero, so this mainly helps in small functions (and running this before coalescing would extend live ranges in potentially bad ways).