Bugzilla – Bug 315243
[PATCH] -O=loop sometimes adds padding in wrong places
Last modified: 2007-09-15 21:24:46 UTC
---- Reported by bmaurer@users.sf.net 2004-06-23 21:29:32 MST ---- Consider this code: using System; class T { static void Main () { int i = Environment.TickCount; new T ().X (); Console.WriteLine (Environment.TickCount - i); } void X () { int i = 0; while ( i < 50000000 && i < 50000000 && i < 50000000 && i < 50000000 && i < 50000000 && i < 50000000 && i < 50000000 && i < 50000000 && i < 50000000 && i < 50000000 && i < 50000000 && i < 50000000 && i < 50000000 && i < 50000000 && i < 50000000 && i < 50000000 && i < 50000000 && i < 50000000 && i < 50000000 && i < 50000000 && i < 50000000 && i < 50000000) i ++; } } We generate assembly like: 11: 81 ff 80 f0 fa 02 cmp edi,0x2faf080 17: 0f 8d 27 01 00 00 jge 144 <T_X+0x144> 1d: 8d 6d 00 lea ebp,[ebp] 20: 81 ff 80 f0 fa 02 cmp edi,0x2faf080 26: 0f 8d 18 01 00 00 jge 144 <T_X+0x144> 2c: 8d 64 24 00 lea esp,[esp] 30: 81 ff 80 f0 fa 02 cmp edi,0x2faf080 the lea instructions are padding, which are trying to align loops. However, alignment should not be added. ---- Additional Comments From bmaurer@users.sf.net 2004-06-24 14:49:12 MST ---- Created an attachment (id=166332) patch ---- Additional Comments From bmaurer@users.sf.net 2004-06-24 14:51:07 MST ---- Before, the runtime would insert padding for any block in a loop with only one in block. However, what really should be done is that a block that is the head of a loop should get padding. This gives us a pretty large boost in some benchmarks: [benm@164-99-120-44 benchmark]$ /usr/bin/time mono zipmark.exe /usr/share/dict/words 100 0.02user 0.00system 0:46.17elapsed 0%CPU (0avgtext+0avgdata 0maxresident)k 0inputs+0outputs (1major+897minor)pagefaults 0swaps [benm@164-99-120-44 benchmark]$ /usr/bin/time ../mini/mono zipmark.exe /usr/share/dict/words 100 0.02user 0.00system 0:28.37elapsed 0%CPU (0avgtext+0avgdata 0maxresident)k 0inputs+0outputs (1major+2588minor)pagefaults 0swaps ---- Additional Comments From bmaurer@users.sf.net 2004-06-24 17:16:31 MST ---- It turns out a large part of this benefit for ziplib requires another patch i have on my tree. However, you can see the improvement in first case test case with just my patch. ---- Additional Comments From vargaz@freemail.hu 2004-07-08 15:41:47 MST ---- This patch looks ok to me. Especially since 'loop' is not in the default optimization set. ---- Additional Comments From lupus@ximian.com 2004-08-10 13:40:52 MST ---- The patch is incorrect, since it aligns the wrong basic block (and slowed down 50% simple loops). I committed a fix to deal with fall-through checks in the condition. Imported an attachment (id=166332) Unknown operating system unknown. Setting to default OS "Other".