------- Comment #2 from carrot at google dot com 2009-05-31 02:51 ------- There are a lot of such opportunities in mcf from SPEC CPU 2006.
One possible implementation is to add a pass before cse. In the new pass it should detect insn patterns like: (set r200 400) # 400 is offset of field1 (set r201 (mem (plus r100 r200))) # r100 contains struct base ... (set r300 404) # 404 is offset of field2 (set r301 (mem (plus r100 r300))) # r100 contains struct base And rewrite them as: (set r200 400) # keep the original insn (set r250 (plus r100 400)) # r250 is new base (set r201 (mem (plus r250 0))) ... (set r300 404) (set r251 (plus r100 400)) # r251 contains same value as r250 (set r301 (mem (plus r251 4))) We can let dce and cse remove the redundant code, the final result should look like: (set r101 (plus r100 400)) (set r201 (mem (plus r101 0))) ... (set r301 (mem (plus r101 4))) -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40314