@@ -714,39 +714,31 @@ which causes the miscompile.
714
714
Currently there is no tool to automatically identify the bad optimization, but
715
715
it's quite easy to do this manually:
716
716
717
- 1 . Find the offending optimization with bisecting:
718
-
719
- a. Add the compiler option ` -Xllvm -sil-opt-pass-count=<n> ` , where ` <n> `
720
- is the number of optimizations to run.
721
-
722
- b. Bisect: find n where the executable crashes, but does not crash
723
- with n-1. First just try n = 10, 100, 1000, 10000, etc. to find
724
- an upper bound). Then can either bisect the invocation by hand or
725
- place the invocation into a script and use
726
- ` ./llvm-project/llvm/utils/bisect ` to automatically bisect
727
- based on the scripts error code. Example invocation:
728
-
729
- bisect --start=0 --end=10000 ./invoke_swift_passing_N.sh "%(count)s"
730
-
731
- c. Once one finds ` n ` , Add another option ` -Xllvm -sil-print-pass-name ` . The output can be
732
- large, so it's best to redirect stderr to a file (` 2> output ` ).
733
- In the output search for the last pass before ` stage Address Lowering ` .
734
- It should be the ` Run #<n-1> ` . This line tells you the name of the bad
735
- optimization pass and on which function it run.
736
-
737
- 2 . Get the SIL before and after the bad optimization.
738
-
739
- a. Add the compiler option
740
- ` -Xllvm -sil-print-function='<function>' `
741
- where ` <function> ` is the function name (including the preceding ` $ ` ).
742
- For example:
743
- ` -Xllvm -sil-print-function='$s4test6testityS2iF' ` .
744
- Again, the output can be large, so it's best to redirect stderr to a file.
745
- b. From the output, copy the SIL of the function * before* the bad
746
- run into a separate file and the SIL * after* the bad run into a file.
747
- c. Compare both SIL files and try to figure out what the optimization pass
748
- did wrong. To simplify the comparison, it's sometimes helpful to replace
749
- all SIL values (e.g. ` %27 ` ) with a constant string (e.g. ` %x ` ).
717
+ 1 . Add the compiler option ` -Xllvm -sil-opt-pass-count=<n> ` , where ` <n> `
718
+ is the number of optimizations to run.
719
+
720
+ 2 . Bisect: find n where the executable crashes, but does not crash
721
+ with n-1. First just try n = 10, 100, 1000, 10000, etc. to find
722
+ an upper bound). Then can either bisect the invocation by hand or
723
+ place the invocation into a script and use
724
+ ` ./llvm-project/llvm/utils/bisect ` to automatically bisect
725
+ based on the scripts error code. Example invocation:
726
+
727
+ bisect --start=0 --end=10000 ./invoke_swift_passing_N.sh "%(count)s"
728
+
729
+ 3 . Add another option ` -Xllvm -sil-print-last ` . The output can be
730
+ large, so it's best to redirect stderr to a file (` 2> output ` ).
731
+ The output contains the SIL before and after the bad optimization.
732
+
733
+ 4 . Copy the two functions from the output into separate files and
734
+ compare both files. Try to figure out what the optimization pass
735
+ did wrong. To simplify the comparison, it's sometimes helpful to replace
736
+ all SIL values (e.g. ` %27 ` ) with a constant string (e.g. ` %x ` ).
737
+
738
+ 5 . If the bad optimization is SILCombine or SimplifyCFG (which do a lot of
739
+ transformations in a single run) it's helpful to continue bisecting on
740
+ the sub-pass number. The option ` -Xllvm -sil-opt-pass-count=<n>.<m> `
741
+ can be used for that, where ` m ` is the sub-pass number.
750
742
751
743
### Using git-bisect in the presence of branch forwarding/feature branches
752
744
0 commit comments