如何使用bugpoint隔离代码传递?

时间:2016-01-26 22:36:27

标签: llvm

我有一个LLVM IR源文件,在我优化它时会改变行为。我想知道哪个LLVM传递导致了这个问题。

这是预期的行为,将stdin上的数字分解为:

$ wget https://gist.githubusercontent.com/Wilfred/dde83b701d9bb8d7207a/raw/3eea89526ded7efa995f5bda89012b526dd49691/with_zeroing.ll        
$ echo 1337 | lli with_zeroing.ll 
1337: 7 191

在浏览opt之后,它只回显原始数字:

$ opt -S -O2 with_zeroing.ll -o with_zeroing_o2.ll
$ echo 1337 | lli with_zeroing_o2.ll              
1337: 1337

如何使用bugpoint来确定哪种优化过程正在改变这种行为?

我已经尝试bugpoint with_zeroing.ll -llc-safe但我认为我需要一种方法来将输入输入到生成的编译二进制文件中。

1 个答案:

答案 0 :(得分:1)

LLVM错误报告文档has a great section on optimisation bugs

首先,找出opt在您的代码上运行的传递:

$ opt -O2 -debug-pass=Arguments with_zeroing.ll -disable-output
Pass Arguments:  -tti -no-aa -tbaa -scoped-noalias -assumption-cache-tracker -targetlibinfo -basicaa -verify -simplifycfg -domtree -sroa -early-cse -lower-expect
Pass Arguments:  -targetlibinfo -tti -no-aa -tbaa -scoped-noalias -assumption-cache-tracker -basicaa -ipsccp -globalopt -deadargelim -domtree -instcombine -simplifycfg -basiccg -prune-eh -inline-cost -inline -functionattrs -domtree -sroa -early-cse -lazy-value-info -jump-threading -correlated-propagation -simplifycfg -domtree -instcombine -tailcallelim -simplifycfg -reassociate -domtree -loops -loop-simplify -lcssa -loop-rotate -licm -loop-unswitch -instcombine -scalar-evolution -loop-simplify -lcssa -indvars -loop-idiom -loop-deletion -loop-unroll -mldst-motion -domtree -memdep -gvn -memdep -memcpyopt -sccp -domtree -bdce -instcombine -lazy-value-info -jump-threading -correlated-propagation -domtree -memdep -dse -loops -loop-simplify -lcssa -licm -adce -simplifycfg -domtree -instcombine -barrier -float2int -domtree -loops -loop-simplify -lcssa -loop-rotate -branch-prob -block-freq -scalar-evolution -loop-accesses -loop-vectorize -instcombine -scalar-evolution -slp-vectorizer -simplifycfg -domtree -instcombine -loops -loop-simplify -lcssa -scalar-evolution -loop-unroll -instcombine -loop-simplify -lcssa -licm -scalar-evolution -alignment-from-assumptions -strip-dead-prototypes -elim-avail-extern -globaldce -constmerge -verify

接下来,使用-input调用bugpoint来指定程序的输入:

$ echo "1337" > input.txt
$ bugpoint with_zeroing.ll -input input.txt -run-int \
         -targetlibinfo -tti -no-aa -tbaa -scoped-noalias -assumption-cache-tracker -basicaa -ipsccp -globalopt -deadargelim -domtree -instcombine -simplifycfg -basiccg -prune-eh -inline-cost -inline -functionattrs -domtree -sroa -early-cse -lazy-value-info -jump-threading -correlated-propagation -simplifycfg -domtree -instcombine -tailcallelim -simplifycfg -reassociate -domtree -loops -loop-simplify -lcssa -loop-rotate -licm -loop-unswitch -instcombine -scalar-evolution -loop-simplify -lcssa -indvars -loop-idiom -loop-deletion -loop-unroll -mldst-motion -domtree -memdep -gvn -memdep -memcpyopt -sccp -domtree -bdce -instcombine -lazy-value-info -jump-threading -correlated-propagation -domtree -memdep -dse -loops -loop-simplify -lcssa -licm -adce -simplifycfg -domtree -instcombine -barrier -float2int -domtree -loops -loop-simplify -lcssa -loop-rotate -branch-prob -block-freq -scalar-evolution -loop-accesses -loop-vectorize -instcombine -scalar-evolution -slp-vectorizer -simplifycfg -domtree -instcombine -loops -loop-simplify -lcssa -scalar-evolution -loop-unroll -instcombine -loop-simplify -lcssa -licm -scalar-evolution -alignment-from-assumptions -strip-dead-prototypes -elim-avail-extern -globaldce -constmerge -verify