Closed rachitnigam closed 2 years ago
References:
bugpoint
command in Yosys: http://www.clifford.at/yosys/cmd_bugpoint.htmlbugpoint
in LLVM: https://llvm.org/docs/Bugpoint.htmlSimple script I wrote:
#!/usr/bin/env sh
set -euf -o pipefail
FILE='trmm.futil'
DATA='trmm.data'
FLAG1='-p validate -p remove-external-memories -p pre-opt -p compile-empty -p compile-control -p post-opt -p lower'
FLAG2='-p validate -p remove-external-memories -p pre-opt -p compile-empty -p top-down-cc -p post-opt -p lower'
fud e $FILE --to dat -s futil.flags "$FLAG1" -s verilog.data $DATA > one
fud e $FILE --to dat -s futil.flags "$FLAG2" -s verilog.data $DATA > two
cmp --silent one two && "outputs were the same" || echo "outputs were different!"
Cool. FWIW, it might not be a bad idea to try C-Reduce itself or hacking up LLVM's bugpoint somehow. The philosophy of those tools is often not to be particularly smart—for example, avoiding deleting stuff that influences a while
loop's condition. C-Reduce has some C-semantics-aware passes, but it is still fairly effective with those turned off.
Put differently, even a pretty dumb reducer is way better than no reducer. And a smart reducer is likely a bit better than a dumb reducer but the delta is not as big.
For a dumber reducer that might delete conditional-related code: in the first run of the script, calculate the number of cycles (using verilator). Any reduced test case will take no more cycles.
Now, use this cycle number as the bound in future reduction runs.
It just occurred to me that we can actually turn this into a ~creduce~ csmith tool for Verilog—since we can carefully generate programs with particularly funky control flow, maybe we can use this to fuzz edge cases in Verilog synthesizers and simulators.
This is already tracked in our Projects and isn't currently actionable so closing
I was debugging #329 and wrote down a simple script for differential testing. Then, I slowly reduced the program to find a minimal program. A few problems that need to be handled (feel free to add more):
while
loops, we can't just remove things from the loop body willy-nilly. Things that affect the condition should probably not be removed.