I’m proposing changes to integrate SingleByteCoverage with Branch coverage. SingleByteCoverage, introduced in #75425, currently suppresses Branch coverage. I’ve tested a prototype with good results.
Cc: @evodius96 @gulfemsavrun @ellishg
Overview of SingleByteCoverage
SingleByteCoverage uses binary counters set to False (0xFF, initial value) and True (0x00) to save on instruction bytes. It avoids using CounterExpr and suppresses Branch coverage. This works well on manycore builders, where using 64-bit counters is very difficult.
SingleByteCoverage and CounterExpr
The current implementation of SingleByteCoverage avoids CounterExpr. However, CounterExpr::Add
is still available because counters can be handled as if their upper limit is 1, but CounterExpr::Subtract
is unavailable. Most subtractions happen in BranchRegions, so extra counters are needed for False paths.
Counter expressions from non-SingleByteCoverage can be used by replacing and removing CounterExpr::Subtract
.
Proposed Plan
- Introduce “CounterPair” for BranchRegions on
RegionCounterMap
. - Add more counters for False paths.
- By enabling CounterExpr, introduce a new option or rewind parts of the current implementation.
Additional Ideas
Reducing Counters more with FalsePath
Example:
C0++; // ParentCnt
if (Cond)
C1++; // TruePath
else
C2++; // FalsePath, (C0 - C1)
Replace (C0 - C1)
with C2
, and apply C0 = (C1 + C2)
. We can remove C0
if all instances in a function can be replaced. This isn’t always possible.
Selective Counter Activation
BranchRegion flags are exclusive between TruePath and FalsePath. An intrinsic for selective flag setting could help:
Counter[Cond ? TrueIdx : FalseIdx] = true;
If TruePath is replaced with CounterExpr, use:
if (!Cond) Counter[FalseIdx] = true;
This works better with conditional-counter-update
mode.
Using MC/DC Test Vectors
As mentioned in 79629, binary counters are equivalent to MC/DC test vectors, which can be used to reduce counter numbers in MC/DC mode.
Thank you.
P.S. I’ll attend the devmtg2024.