Hi, For this small test case,
int *l, *r; int test_func(void) { int i; int direction; static int pos; pos = 0; direction = 1; for ( i = 0; i <= 400; i++ ) { if ( direction == 0 ) pos = l[pos]; else pos = r[pos]; if ( pos == -1 ) { pos = 0; direction = !direction; } } return i; } In middle end, I don't see pos is sunk out of loop by loop store motion. Any idea? The dump after lim is like below, and I expect a SSA symbole xxx_lsm could be created with this pass. ;; Function test_func (test_func, funcdef_no=0, decl_uid=4057, cgraph_uid=0) Symbols to be put in SSA form { .MEM } Incremental SSA update started at block: 0 Number of blocks in CFG: 12 Number of blocks to update: 11 ( 92%) test_func () { int pretmp.14; unsigned int pretmp.13; int prephitmp.12; int pretmp.11; unsigned int pretmp.10; int pretmp.9; int D.4088; static int pos; int direction; int i; _Bool D.4082; int pos.5; int * D.4078; int * r.4; int pos.3; int * D.4074; unsigned int D.4073; unsigned int pos.2; int pos.1; int * l.0; <bb 2>: pos = 0; l.0_6 = l; r.4_12 = r; <bb 3>: # i_32 = PHI <i_21(11), 0(2)> # direction_37 = PHI <direction_2(11), 1(2)> # prephitmp.12_35 = PHI <pretmp.11_1(11), 0(2)> if (direction_37 == 0) goto <bb 4>; else goto <bb 5>; <bb 4>: pos.1_7 = prephitmp.12_35; pos.2_8 = (unsigned int) pos.1_7; D.4073_9 = pos.2_8 * 4; D.4074_10 = l.0_6 + D.4073_9; pos.3_11 = *D.4074_10; pos = pos.3_11; goto <bb 6>; <bb 5>: pos.1_13 = prephitmp.12_35; pos.2_14 = (unsigned int) pos.1_13; D.4073_15 = pos.2_14 * 4; D.4078_16 = r.4_12 + D.4073_15; pos.5_17 = *D.4078_16; pos = pos.5_17; <bb 6>: # prephitmp.12_31 = PHI <pos.3_11(4), pos.5_17(5)> pos.1_18 = prephitmp.12_31; if (pos.1_18 == -1) goto <bb 7>; else goto <bb 10>; <bb 10>: goto <bb 8>; <bb 7>: pos = 0; D.4088_36 = direction_37 ^ 1; direction_20 = D.4088_36 & 1; <bb 8>: # direction_2 = PHI <direction_37(10), direction_20(7)> i_21 = i_32 + 1; if (i_21 != 401) goto <bb 11>; else goto <bb 9>; <bb 11>: pretmp.11_1 = pos; goto <bb 3>; <bb 9>: return 401; } Thanks, -Jiangning