On Thu, Dec 1, 2011 at 11:45 PM, Richard Guenther <richard.guent...@gmail.com> wrote:
> Well, it's not that easy if you still want to properly do redundant expression > removal on global registers. Yes, it might be complicate to make PRE fully aware of global register. I also found comments in is_gimple_reg which says gcc does not do much optimization with register variable at the tree level for now. Back to this issue, I think it can be fixed by following way without hurting redundancy elimination on global register variables: After insert() being called in pre, in function eliminate() we can check for single assignment statement from global register variable to ssa_name. If it is the case, we can just skip the elimination operation. In this way: 1, normal redundancy elimination on global registers will not be hurt, since sccvn and pre has already detected the true elimination chances and they will be eliminated afterward in function eliminate; 2, the inserted statements(including PHIs) for global register variables will not be marked as NECESSARY in function eliminate and will be deleted in remove_dead_inserted_code; I attached an example which can illustrates that the normal redundancy does get eliminated. I will send a patch for review if it worth a discuss. So what do you think? Thanks -- Best Regards.
/* { dg-do compile } */ /* { dg-options "-O2 -fdump-tree-pre-stats" } */ register int data_0 asm("r4"); register int data_3 asm("r5"); int motion_test1(int data, int v) { int i; int t, u; if (data) i = data_0 + data_3; else { v = 2; i = 5; } t = data_0 + data_3; u = i; return v * t * u; } /* We should eliminate one computation of data_0 + data_3 along the main path. We cannot re-associate v * t * u due to undefined signed overflow so we do not eliminate one computation of v * i along the main path. */ /* { dg-final { scan-tree-dump-times "Eliminated: 2" 1 "pre" { xfail *-*-* } } } */ /* { dg-final { scan-tree-dump-times "Eliminated: 1" 1 "pre" } } */ /* { dg-final { cleanup-tree-dump "pre" } } */
ssa-pre-2.c.093t.crited
Description: Binary data
ssa-pre-2.c.094t.pre.orig
Description: Binary data
;; Function motion_test1 (motion_test1, funcdef_no=0, decl_uid=4055, cgraph_uid=0) Points-to analysis Constraints: ANYTHING = &ANYTHING READONLY = &READONLY ESCAPED = *ESCAPED ESCAPED = ESCAPED + UNKNOWN *ESCAPED = NONLOCAL NONLOCAL = &NONLOCAL NONLOCAL = &ESCAPED INTEGER = &ANYTHING data = &NONLOCAL v = &NONLOCAL *r4 = NONLOCAL data_0.0_4 = *r4 *r5 = NONLOCAL data_3.1_5 = *r5 i_6 = data_0.0_4 i_6 = data_3.1_5 v_1 = v v_1 = &NONLOCAL i_2 = i_6 i_2 = &NONLOCAL data_0.0_10 = *r4 data_3.1_11 = *r5 t_12 = data_0.0_10 t_12 = data_3.1_11 D.4935_14 = v_1 D.4935_14 = t_12 D.4934_15 = i_2 D.4934_15 = D.4935_14 ESCAPED = D.4934_15 Collapsing static cycles and doing variable substitution Building predecessor graph Detecting pointer and location equivalences Rewriting constraints and unifying variables Uniting pointer but not location equivalent variables Finding indirect cycles Solving graph Points-to sets ANYTHING = { ANYTHING } READONLY = { READONLY } ESCAPED = { ESCAPED NONLOCAL } NONLOCAL = { ESCAPED NONLOCAL } same as *r4 STOREDANYTHING = { } INTEGER = { ANYTHING } data = { NONLOCAL } v = { NONLOCAL } same as data data_0.0_4 = { ESCAPED NONLOCAL } same as *r4 *r4 = { ESCAPED NONLOCAL } data_3.1_5 = { ESCAPED NONLOCAL } same as *r4 *r5 = { ESCAPED NONLOCAL } same as *r4 i_6 = { ESCAPED NONLOCAL } same as *r4 v_1 = { NONLOCAL } same as data i_2 = { ESCAPED NONLOCAL } same as *r4 data_0.0_10 = { ESCAPED NONLOCAL } same as *r4 data_3.1_11 = { ESCAPED NONLOCAL } same as *r4 t_12 = { ESCAPED NONLOCAL } same as *r4 D.4935_14 = { ESCAPED NONLOCAL } same as *r4 D.4934_15 = { ESCAPED NONLOCAL } same as *r4 Alias information for motion_test1 Aliased symbols .MEM, UID D.4937, void, is global, default def: .MEM_16(D) data_0, UID D.4051, int, is global data_3, UID D.4052, int, is global Call clobber information ESCAPED, points-to non-local, points-to vars: { } Flow-insensitive points-to information ;; 1 loops found ;; ;; Loop 0 ;; header 0, latch 1 ;; depth 0, outer -1 ;; nodes: 0 1 2 5 3 4 ;; 2 succs { 3 5 } ;; 5 succs { 4 } ;; 3 succs { 4 } ;; 4 succs { 1 } Could not find SSA_NAME representative for expression:{mult_expr,i_6,2} Created SSA_NAME representative pretmp.5_17 for expression:{mult_expr,i_6,2} Could not find SSA_NAME representative for expression:{mult_expr,i_6,v_7(D)} Created SSA_NAME representative pretmp.5_18 for expression:{mult_expr,i_6,v_7(D)} Symbols to be put in SSA form { .MEM } Incremental SSA update started at block: 0 Number of blocks in CFG: 6 Number of blocks to update: 5 ( 83%) motion_test1 (int data, int v) { int prephitmp.6; int pretmp.5; int t; int i; int D.4935; int D.4934; int data_3.1; int data_0.0; <bb 2>: if (data_3(D) != 0) goto <bb 3>; else goto <bb 5>; <bb 5>: pretmp.5_19 = data_0; pretmp.5_21 = data_3; pretmp.5_23 = pretmp.5_19 + pretmp.5_21; goto <bb 4>; <bb 3>: data_0.0_4 = data_0; data_3.1_5 = data_3; i_6 = data_0.0_4 + data_3.1_5; <bb 4>: # v_1 = PHI <v_7(D)(3), 2(5)> # i_2 = PHI <i_6(3), 5(5)> # prephitmp.6_24 = PHI <i_6(3), pretmp.5_23(5)> data_0.0_10 = data_0; data_3.1_11 = data_3; t_12 = prephitmp.6_24; D.4935_14 = v_1 * t_12; D.4934_15 = i_2 * D.4935_14; return D.4934_15; }