Commit Graph

16 Commits

Author SHA1 Message Date
Wilson Snyder
af51107587 Fix statistics missing some additions. 2024-03-01 20:27:57 -05:00
Yutetsu TAKATSUKASA
999c9ae21c
Fix #4864 of wrong runtime result (#4867)
* Fix #4864. Ignore if EQ/NE is under SHIFTR.
2024-01-30 00:00:00 +09:00
Yutetsu TAKATSUKASA
e4a0e5aad6
Fix #4857 consider NOT when checking EQ/NEQ under AND/OR tree (#4863) 2024-01-28 22:36:09 +09:00
Ryszard Rozak
45edcbb03e
Fix logical expressions with class objects - caching in v3Const (#4552) 2023-10-17 07:38:45 -04:00
Wilson Snyder
46f8a659b3 Fix shift to remove operation side effects (#4563). 2023-10-14 22:34:37 -04:00
Yutetsu TAKATSUKASA
d4107dce52
Improve xor tree optimization (#4071)
* AstNot does not have to be frozen in an xor tree during BitOp tree optimization.

* Tests: Update stats.
2023-03-26 20:36:32 +09:00
Yutetsu TAKATSUKASA
990b19e048
Fix incorrect optimization of bit op tree (#4059) (#4070) 2023-03-26 03:29:10 -04:00
Yutetsu TAKATSUKASA
816cff009a
Fix #3824 of wrong bit op tree optimization (#3825)
* Tests: Add a test to reproduce #3824

* Fix #3824 of wrong bitOpTree optimization. Consider constant 1 in an Or-tree made by shift-out.
2023-01-04 23:10:55 +09:00
Geza Lore
47bce4157d
Introduce DFG based combinational logic optimizer (#3527)
Added a new data-flow graph (DFG) based combinational logic optimizer.
The capabilities of this covers a combination of V3Const and V3Gate, but
is also more capable of transforming combinational logic into simplified
forms and more.

This entail adding a new internal representation, `DfgGraph`, and
appropriate `astToDfg` and `dfgToAst` conversion functions. The graph
represents some of the combinational equations (~continuous assignments)
in a module, and for the duration of the DFG passes, it takes over the
role of AstModule. A bulk of the Dfg vertices represent expressions.
These vertex classes, and the corresponding conversions to/from AST are
mostly auto-generated by astgen, together with a DfgVVisitor that can be
used for dynamic dispatch based on vertex (operation) types.

The resulting combinational logic graph (a `DfgGraph`) is then optimized
in various ways. Currently we perform common sub-expression elimination,
variable inlining, and some specific peephole optimizations, but there
is scope for more optimizations in the future using the same
representation. The optimizer is run directly before and after inlining.
The pre inline pass can operate on smaller graphs and hence converges
faster, but still has a chance of substantially reducing the size of the
logic on some designs, making inlining both faster and less memory
intensive. The post inline pass can then optimize across the inlined
module boundaries. No optimization is performed across a module
boundary.

For debugging purposes, each peephole optimization can be disabled
individually via the -fno-dfg-peepnole-<OPT> option, where <OPT> is one
of the optimizations listed in V3DfgPeephole.h, for example
-fno-dfg-peephole-remove-not-not.

The peephole patterns currently implemented were mostly picked based on
the design that inspired this work, and on that design the optimizations
yields ~30% single threaded speedup, and ~50% speedup on 4 threads. As
you can imagine not having to haul around redundant combinational
networks in the rest of the compilation pipeline also helps with memory
consumption, and up to 30% peak memory usage of Verilator was observed
on the same design.

Gains on other arbitrary designs are smaller (and can be improved by
analyzing those designs). For example OpenTitan gains between 1-15%
speedup depending on build type.
2022-09-23 16:46:22 +01:00
Yutetsu TAKATSUKASA
1f9323d086
Set correct dtype in replaceShiftSame() (#3520)
* Tests: Add a test to reproduce bug3399

* Fix3399. Set the correct dtype in replaceShiftSame().

* Tests: update stats.

* Update Changes
2022-07-29 07:05:04 +09:00
Yutetsu TAKATSUKASA
9f37cef1bb
Fix #3470 of incorrect bit op tree optimization (#3476)
* Tests: Add a test to reproduce #3470

* Update LSB during return path of traversal. No functional change is intended.

* Introduce LeafInfo::m_msb

* Update LeafInfo::m_msb when visitin AstCCast

* Internals: Add comment, reorder. No functional change is intended.

* Delete explicit from copy constructor to fix build error.

* Update Changes

* Internals: Remove unused parameter. No functional change is intended.

* Tests: Add explanation to t_const_opt.
2022-07-06 08:33:37 +09:00
Yutetsu TAKATSUKASA
d64f979f99
Fix BitOpTree optimization to consider polarity of frozen node (#3445) (#3459)
* Tests: add a test to another failing case of #3445

* Consider polarity as lsb in BitOpTree optimization.
2022-06-01 09:26:16 +09:00
Yutetsu TAKATSUKASA
26b7452178
Fix #3445 of BitOpTreeOpt (#3453)
* Tests: Check BitOpTree statistics in t_const_opt.

* Tests: Add a test to reproduce #3445

* Fix #3445. Don't forget LSB of frozen node in BitOpTreeOpt.

* Apply suggestions from code review

Co-authored-by: Geza Lore <gezalore@gmail.com>
2022-05-30 19:33:06 +09:00
Yutetsu TAKATSUKASA
b08c694cd6
Fix wrong bit op tree optimization (#3185)
* Add a test to reproduce bug3182. Run the same HDL with -Oo to confirm the result is same.

* Hopefully fix #3182. The result can be 0 only when polarity is true (no AstNot is found during traversal).
2021-11-06 12:31:50 +09:00
Wilson Snyder
c678e7ec3e Format: perltidy spacing cleanup. No functional change. 2021-09-07 23:50:28 -04:00
Yutetsu TAKATSUKASA
6a31b19224
Tests: Add a test to improve code coverage of V3Const.cpp (#2878) 2021-04-07 22:37:31 +09:00