Tests: Add tests for -fno-dfg-peephole* (#6606)

Fixes -fno-dfg-peeophole-right-leaning-assoc.

Fixes #6601
This commit is contained in:
Geza Lore 2025-10-28 18:59:11 +01:00 committed by GitHub
parent 766514bdcf
commit 5642de432b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 56 additions and 8 deletions

View File

@ -373,7 +373,11 @@ class V3DfgPeephole final : public DfgVisitor {
replace(vtxp, rootp);
changed = true;
vtxp = rootp;
continue;
}
// If we didn't apply the change (pattern was disabled), break the loop
break;
}
return changed;

View File

@ -11,6 +11,7 @@ import vltest_bootstrap
test.scenarios('vlt_all')
test.sim_time = 2000000
test.top_filename = "t/t_dfg_peephole.v"
if not os.path.exists(test.root + "/.git"):
test.skip("Not in a git repository")
@ -72,6 +73,16 @@ test.compile(verilator_flags2=[
]) # yapf:disable
# Compile optimized - also builds executable
extraArgs = []
if test.name == "t_dfg_peephole_off_all":
extraArgs.append("-fno-dfg-peephole")
if test.name == "t_dfg_peephole_off_each":
for opt in optimizations:
opt = opt.lower()
opt = re.sub(r"_", "-", opt)
extraArgs.append("-fno-dfg-peephole-" + opt)
test.compile(verilator_flags2=[
"--stats",
"--build",
@ -84,20 +95,23 @@ test.compile(verilator_flags2=[
"--dump-dfg", # To fill code coverage
"-CFLAGS \"-I .. -I ../obj_ref\"",
"../obj_ref/Vref__ALL.a",
"../../t/" + test.name + ".cpp"
]) # yapf:disable
"../../t/t_dfg_peephole.cpp"
] + extraArgs) # yapf:disable
def check(name):
def check(name, enabled):
name = name.lower()
name = re.sub(r'_', ' ', name)
test.file_grep(test.obj_dir + "/obj_opt/Vopt__stats.txt",
r'DFG\s+(pre inline|post inline|scoped) Peephole, ' + name + r'\s+([1-9]\d*)')
pattern = r'DFG\s+(pre inline|post inline|scoped) Peephole, ' + name + r'\s+([1-9]\d*)\s*$'
if enabled:
test.file_grep(test.obj_dir + "/obj_opt/Vopt__stats.txt", pattern)
else:
test.file_grep_not(test.obj_dir + "/obj_opt/Vopt__stats.txt", pattern)
# Check all optimizations defined in
for opt in optimizations:
check(opt)
check(opt, test.name == "t_dfg_peephole")
test.file_grep_not(test.obj_dir + "/obj_opt/Vopt__stats.txt",
r'DFG.*non-representable.*\s[1-9]\d*$')

View File

@ -0,0 +1,16 @@
#!/usr/bin/env python3
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
#
# Copyright 2025 by Wilson Snyder. This program is free software; you
# can redistribute it and/or modify it under the terms of either the GNU
# Lesser General Public License Version 3 or the Perl Artistic License
# Version 2.0.
# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
import vltest_bootstrap
import runpy
test.scenarios('vlt_all')
runpy.run_path("t/t_dfg_peephole.py", globals())

View File

@ -0,0 +1,16 @@
#!/usr/bin/env python3
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
#
# Copyright 2025 by Wilson Snyder. This program is free software; you
# can redistribute it and/or modify it under the terms of either the GNU
# Lesser General Public License Version 3 or the Perl Artistic License
# Version 2.0.
# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
import vltest_bootstrap
import runpy
test.scenarios('vlt_all')
runpy.run_path("t/t_dfg_peephole.py", globals())

View File

@ -30,8 +30,6 @@ Test_Waivers = [
'-rr', # Not testing; not requiring rr installation
# Need testing:
'-fconst', # TODO breaks due to some needed V3Const steps
'-fdfg-peephole', # Need test of -fno-...
'-fdfg-peephole-', # Need test of -fno-...
]
Sums = {}