llvm.org GIT mirror llvm / 33c9683
Provide a script that can track down which optimization pass causes different code to be produced between two llvm builds that differe slightly. This is useful in tracking down mis-optimization bugs. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32435 91177308-0d34-0410-b5e6-96231b3b80d8 Reid Spencer 13 years ago
1 changed file(s) with 99 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 #!/bin/bash
1 #
2 # findoptdiff
3 #
4 # This script helps find the optimization difference between two llvm
5 # builds. It is useful when you have a build that is known to work and
6 # one that exhibits an optimization problem. Identifying the difference
7 # between the two builds can lead to discovery of the source of a
8 # mis-optimization.
9 #
10 # The script takes two llvm build paths as arguments. These specify the
11 # the two llvm builds to compare. It is generally expected that they
12 # are "close cousins". That is, they are the same except that the
13 # second build contains some experimental optimization features that
14 # are suspected of producing a misoptimization.
15 #
16 # The script takes two bytecode files, one from each build. They are
17 # presumed to be a compilation of the same program or program fragment
18 # with the only difference being the builds.
19 #
20 # The script operates by iteratively applying the optimizations that gccas
21 # and gccld run until there is a difference in the assembly resulting
22 # from the optimization. The difference is then reported with the set of
23 # optimization passes that produce the difference.
24 #
25 # To work around differences in the assembly language format, the script
26 # can also take two filter arguments that post-process the assembly
27 # so they can be differenced without making false positives for known
28 # differences in the two builds. These filters are optional.
29 #
30 # Usage:
31 # findoptdiff llvm1 llvm2 bc1 bc2 filter1 filter2
32 #
33 # Where:
34 # llvm1
35 # is the path to the first llvm build dir
36 # llvm2
37 # is the path to the second llvm build dir
38 # bc1
39 # is the bytecode file for the first llvm environment
40 # bc2
41 # is the bytecode file for the second llvm environment
42 # filter1
43 # is an optional filter for filtering the llvm1 generated assembly
44 # filter2
45 # is an optional filter for filtering the llvm2 generated assembly
46 #
47 llvm1=$1
48 llvm2=$2
49 bc1=$3
50 bc2=$4
51 filt1=$5
52 if [ -z "$filt1" ] ; then
53 filt1="cat"
54 fi
55 filt2=$6
56 if [ -z "$filt2" ] ; then
57 filt2="cat"
58 fi
59 opt1=opt.$bc1
60 opt2=opt.$bc2
61 ll1=${bc1}.ll
62 ll2=${bc2}.ll
63 dir1="/proj/llvm/llvm-test-1/External/SPEC/CINT2000/300.twolf"
64 opt1="/proj/llvm/llvm-1/Debug/bin/opt"
65 dis1="/proj/llvm/llvm-1/Debug/bin/llvm-dis"
66 dir2="/proj/llvm/llvm-test-2/External/SPEC/CINT2000/300.twolf"
67 opt2="/proj/llvm/llvm-2/Debug/bin/opt"
68 dis2="/proj/llvm/llvm-2/Debug/bin/llvm-dis"
69 bcfile="Output/300.twolf.linked.rbc"
70 optll="opt.ll"
71
72 all_switches="-verify -lowersetjmp -funcresolve -raiseallocs -simplifycfg -mem2reg -globalopt -globaldce -ipconstprop -deadargelim -instcombine -simplifycfg -prune-eh -inline -simplify-libcalls -argpromotion -raise -tailduplicate -simplifycfg -scalarrepl -instcombine -predsimplify -condprop -tailcallelim -simplifycfg -reassociate -licm -loop-unswitch -instcombine -indvars -loop-unroll -instcombine -load-vn -gcse -sccp -instcombine -condprop -dse -dce -simplifycfg -deadtypeelim -constmerge -funcresolve -internalize -ipsccp -globalopt -constmerge -deadargelim -inline -prune-eh -globalopt -globaldce -argpromotion -instcombine -predsimplify -scalarrepl -globalsmodref-aa -licm -load-vn -gcse -dse -instcombine -simplifycfg -verify"
73
74 function tryit {
75 switches_to_use="$1"
76 cd $dir1
77 $opt1 $switches_to_use "$bcfile" -o - | $dis1 | $filt1 > "$optll"
78 cd $dir2
79 $opt2 $switches_to_use "$bcfile" -o - | $dis2 | $filt2 > "$optll"
80 diff "$dir1/$optll" "$dir2/$optll" > /dev/null
81 if [ $? -ne 0 ] ; then
82 echo
83 echo "Diff fails with these switches:"
84 echo $switches
85 echo "Differences:"
86 diff "$dir1/$optll" "$dir2/$optll" | head
87 exit 1
88 fi
89 return 1
90 }
91
92 for sw in $all_switches ; do
93 echo -n " $sw"
94 switches="$switches $sw"
95 if tryit "$switches" ; then
96 break;
97 fi
98 done