Commit e11094b
committed
Fix MachBuffer branch optimization.
This patch fixes a subtle bug that occurred in the MachBuffer branch
optimization: in tracking labels at the current buffer tail using a
sorted-by-offset array, the code did not update this array properly when
redirecting labels. As a result, the dead-branch removal was unsafe,
because not every label pointing to a branch is guaranteed to be
redirected properly first.
Discovered while doing performance testing: bz2 silently took a wrong
branch and exited compression early. (Eek!)
To address this problem, this patch adopts a slightly simpler data
structure: we only track the labels *at the current buffer tail*, and
*at the start of each branch*, and we're careful to update these
appropriately to maintain the invariants. I'm pretty confident that this
is correct now, but we should (still) fuzz it a bunch, because wrong
control flow scares me a nonzero amount. I should probably also actually
write out a formal proof that these data-structure updates are correct.
The optimizations are important for performance (removing useless empty
blocks, and taking advantage of any fallthrough opportunities at all),
so I don't think we would want to drop them entirely.1 parent 5c39b74 commit e11094b
3 files changed
+103
-71
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1163 | 1163 | | |
1164 | 1164 | | |
1165 | 1165 | | |
1166 | | - | |
1167 | | - | |
1168 | | - | |
1169 | | - | |
1170 | | - | |
1171 | | - | |
| 1166 | + | |
1172 | 1167 | | |
1173 | 1168 | | |
1174 | | - | |
1175 | | - | |
| 1169 | + | |
1176 | 1170 | | |
| 1171 | + | |
| 1172 | + | |
1177 | 1173 | | |
1178 | 1174 | | |
1179 | 1175 | | |
| |||
1208 | 1204 | | |
1209 | 1205 | | |
1210 | 1206 | | |
1211 | | - | |
1212 | 1207 | | |
1213 | 1208 | | |
1214 | | - | |
1215 | 1209 | | |
1216 | | - | |
| 1210 | + | |
1217 | 1211 | | |
1218 | | - | |
| 1212 | + | |
| 1213 | + | |
| 1214 | + | |
1219 | 1215 | | |
1220 | | - | |
1221 | 1216 | | |
1222 | 1217 | | |
1223 | | - | |
1224 | | - | |
| 1218 | + | |
1225 | 1219 | | |
| 1220 | + | |
1226 | 1221 | | |
1227 | 1222 | | |
1228 | 1223 | | |
1229 | | - | |
1230 | 1224 | | |
1231 | 1225 | | |
1232 | 1226 | | |
| 1227 | + | |
1233 | 1228 | | |
1234 | 1229 | | |
1235 | 1230 | | |
| |||
1307 | 1302 | | |
1308 | 1303 | | |
1309 | 1304 | | |
1310 | | - | |
1311 | 1305 | | |
1312 | 1306 | | |
1313 | 1307 | | |
1314 | 1308 | | |
1315 | 1309 | | |
| 1310 | + | |
1316 | 1311 | | |
1317 | 1312 | | |
1318 | 1313 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
812 | 812 | | |
813 | 813 | | |
814 | 814 | | |
815 | | - | |
816 | | - | |
817 | | - | |
818 | | - | |
| 815 | + | |
| 816 | + | |
819 | 817 | | |
820 | 818 | | |
821 | 819 | | |
822 | 820 | | |
| 821 | + | |
| 822 | + | |
823 | 823 | | |
824 | 824 | | |
825 | 825 | | |
| |||
835 | 835 | | |
836 | 836 | | |
837 | 837 | | |
838 | | - | |
839 | | - | |
840 | | - | |
841 | | - | |
842 | | - | |
| 838 | + | |
| 839 | + | |
843 | 840 | | |
844 | 841 | | |
845 | 842 | | |
846 | 843 | | |
847 | 844 | | |
848 | 845 | | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
849 | 849 | | |
850 | 850 | | |
851 | 851 | | |
852 | 852 | | |
853 | 853 | | |
854 | 854 | | |
855 | | - | |
856 | | - | |
857 | | - | |
858 | | - | |
| 855 | + | |
| 856 | + | |
859 | 857 | | |
860 | 858 | | |
861 | 859 | | |
862 | 860 | | |
| 861 | + | |
| 862 | + | |
863 | 863 | | |
864 | 864 | | |
865 | 865 | | |
| |||
0 commit comments