Fix expression coverage in loops (#7511)

This commit is contained in:
Todd Strader 2026-04-28 15:33:41 -04:00 committed by GitHub
parent 76c1b26e3b
commit 0188679631
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 41 additions and 8 deletions

View File

@ -300,7 +300,9 @@ class CoverageVisitor final : public VNVisitor {
void visit(AstLoop* nodep) override {
UASSERT_OBJ(!nodep->contsp(), nodep, "'contsp' only used before LinkJump");
VL_RESTORER(m_state);
VL_RESTORER(m_exprStmtsp);
VL_RESTORER(m_inToggleOff);
m_exprStmtsp = nodep;
m_inToggleOff = true;
createHandle(nodep);
iterateAndNextNull(nodep->stmtsp());

View File

@ -209,6 +209,12 @@
-000000 point: type=expr comment=(t2==0) => 0 hier=top.t
end
end
for (int loop_var_2 = 0; loop_var_2 < 32; loop_var_2 += 2) begin
~000131 if (cyc[loop_var_2] | cyc[loop_var_2 + 1]) $write("");
-000006 point: type=expr comment=(cyc[(loop_var_2 + 32'sh1)[4:0]+:1]==1) => 1 hier=top.t
+000131 point: type=expr comment=(cyc[loop_var_2[4:0]+:1]==0 && cyc[(loop_var_2 + 32'sh1)[4:0]+:1]==0) => 0 hier=top.t
-000009 point: type=expr comment=(cyc[loop_var_2[4:0]+:1]==1) => 1 hier=top.t
end
// stop at the first layer even if there's more to find
%000007 if ((cyc[3+32'(t1&&t2)+:2] == cyc[5+32'(t3||t4)+:2]) || cyc[31]) $write("");
-000002 point: type=expr comment=((cyc[(32'sh3 + (t1 && t2))[4:0]+:2] == cyc[(32'sh5 + (t3 || t4))[4:0]+:2])==0 && cyc[31]==0) => 0 hier=top.t
@ -295,8 +301,8 @@
%000001 while (ta || tb || tc) begin
-000001 point: type=expr comment=(ta==0 && tb==0 && tc==0) => 0 hier=top.t
-000000 point: type=expr comment=(ta==1) => 1 hier=top.t
-000000 point: type=expr comment=(tb==1) => 1 hier=top.t
-000000 point: type=expr comment=(tc==1) => 1 hier=top.t
-000001 point: type=expr comment=(tb==1) => 1 hier=top.t
-000001 point: type=expr comment=(tc==1) => 1 hier=top.t
tc = tb;
tb = ta;
ta = '0;

View File

@ -86,6 +86,9 @@ module t (
if (cyc[loop_var] && t2) $write("");
end
end
for (int loop_var_2 = 0; loop_var_2 < 32; loop_var_2 += 2) begin
if (cyc[loop_var_2] | cyc[loop_var_2 + 1]) $write("");
end
// stop at the first layer even if there's more to find
if ((cyc[3+32'(t1&&t2)+:2] == cyc[5+32'(t3||t4)+:2]) || cyc[31]) $write("");
// impossible branches and redundant terms

View File

@ -209,6 +209,12 @@
-000000 point: type=expr comment=(t2==0) => 0 hier=top.t
end
end
for (int loop_var_2 = 0; loop_var_2 < 32; loop_var_2 += 2) begin
~000131 if (cyc[loop_var_2] | cyc[loop_var_2 + 1]) $write("");
-000006 point: type=expr comment=(cyc[(loop_var_2 + 32'sh1)[4:0]+:1]==1) => 1 hier=top.t
+000131 point: type=expr comment=(cyc[loop_var_2[4:0]+:1]==0 && cyc[(loop_var_2 + 32'sh1)[4:0]+:1]==0) => 0 hier=top.t
-000009 point: type=expr comment=(cyc[loop_var_2[4:0]+:1]==1) => 1 hier=top.t
end
// stop at the first layer even if there's more to find
%000007 if ((cyc[3+32'(t1&&t2)+:2] == cyc[5+32'(t3||t4)+:2]) || cyc[31]) $write("");
-000002 point: type=expr comment=((cyc[(32'sh3 + (t1 && t2))[4:0]+:2] == cyc[(32'sh5 + (t3 || t4))[4:0]+:2])==0 && cyc[31]==0) => 0 hier=top.t
@ -423,8 +429,8 @@
%000001 while (ta || tb || tc) begin
-000001 point: type=expr comment=(ta==0 && tb==0 && tc==0) => 0 hier=top.t
-000000 point: type=expr comment=(ta==1) => 1 hier=top.t
-000000 point: type=expr comment=(tb==1) => 1 hier=top.t
-000000 point: type=expr comment=(tc==1) => 1 hier=top.t
-000001 point: type=expr comment=(tb==1) => 1 hier=top.t
-000001 point: type=expr comment=(tc==1) => 1 hier=top.t
tc = tb;
tb = ta;
ta = '0;

View File

@ -209,6 +209,12 @@
-000000 point: type=expr comment=(t2==0) => 0 hier=top.t
end
end
for (int loop_var_2 = 0; loop_var_2 < 32; loop_var_2 += 2) begin
~000131 if (cyc[loop_var_2] | cyc[loop_var_2 + 1]) $write("");
-000006 point: type=expr comment=(cyc[(loop_var_2 + 32'sh1)[4:0]+:1]==1) => 1 hier=top.t
+000131 point: type=expr comment=(cyc[loop_var_2[4:0]+:1]==0 && cyc[(loop_var_2 + 32'sh1)[4:0]+:1]==0) => 0 hier=top.t
-000009 point: type=expr comment=(cyc[loop_var_2[4:0]+:1]==1) => 1 hier=top.t
end
// stop at the first layer even if there's more to find
%000007 if ((cyc[3+32'(t1&&t2)+:2] == cyc[5+32'(t3||t4)+:2]) || cyc[31]) $write("");
-000002 point: type=expr comment=((cyc[(32'sh3 + (t1 && t2))[4:0]+:2] == cyc[(32'sh5 + (t3 || t4))[4:0]+:2])==0 && cyc[31]==0) => 0 hier=top.t
@ -295,8 +301,8 @@
%000001 while (ta || tb || tc) begin
-000001 point: type=expr comment=(ta==0 && tb==0 && tc==0) => 0 hier=top.t
-000000 point: type=expr comment=(ta==1) => 1 hier=top.t
-000000 point: type=expr comment=(tb==1) => 1 hier=top.t
-000000 point: type=expr comment=(tc==1) => 1 hier=top.t
-000001 point: type=expr comment=(tb==1) => 1 hier=top.t
-000001 point: type=expr comment=(tc==1) => 1 hier=top.t
tc = tb;
tb = ta;
ta = '0;

View File

@ -285,6 +285,16 @@
-000000 point: type=branch comment=if hier=top.t
end
end
~000144 for (int loop_var_2 = 0; loop_var_2 < 32; loop_var_2 += 2) begin
-000009 point: type=line comment=block hier=top.t
+000144 point: type=line comment=block hier=top.t
~000131 if (cyc[loop_var_2] | cyc[loop_var_2 + 1]) $write("");
-000006 point: type=expr comment=(cyc[(loop_var_2 + 32'sh1)[4:0]+:1]==1) => 1 hier=top.t
+000131 point: type=expr comment=(cyc[loop_var_2[4:0]+:1]==0 && cyc[(loop_var_2 + 32'sh1)[4:0]+:1]==0) => 0 hier=top.t
-000009 point: type=expr comment=(cyc[loop_var_2[4:0]+:1]==1) => 1 hier=top.t
+000013 point: type=branch comment=if hier=top.t
+000131 point: type=branch comment=else hier=top.t
end
// stop at the first layer even if there's more to find
%000007 if ((cyc[3+32'(t1&&t2)+:2] == cyc[5+32'(t3||t4)+:2]) || cyc[31]) $write("");
-000007 point: type=branch comment=if hier=top.t
@ -411,8 +421,8 @@
%000003 while (ta || tb || tc) begin
-000001 point: type=expr comment=(ta==0 && tb==0 && tc==0) => 0 hier=top.t
-000000 point: type=expr comment=(ta==1) => 1 hier=top.t
-000000 point: type=expr comment=(tb==1) => 1 hier=top.t
-000000 point: type=expr comment=(tc==1) => 1 hier=top.t
-000001 point: type=expr comment=(tb==1) => 1 hier=top.t
-000001 point: type=expr comment=(tc==1) => 1 hier=top.t
-000003 point: type=line comment=block hier=top.t
%000003 tc = tb;
-000003 point: type=line comment=block hier=top.t