On 03/14/2011 01:55 PM, Zdenek Dvorak wrote: > Hi, > >>>> it is trying to allow for >>>> >>>> do >>>> { >>>> *p = '\0'; >>>> i++; /* use_uses_inced_iv == true */ >>>> p++; /* use_after_cand_inc == true */ >>>> if (!(i < n)) >>>> break; >>>> } >>>> while (1); >>>> >>>> and for >>>> >>>> do >>>> { >>>> *p = '\0'; >>>> if (!(i < n)) >>>> break; >>>> i++; /* use_uses_inced_iv == false */ >>>> p++; /* use_after_cand_inc == false */ >>>> } >>>> while (1); >>>> >>>> but not for >>>> >>>> do >>>> { >>>> *p = '\0'; >>>> i++; /* use_uses_inced_iv == true */ >>>> if (!(i < n)) >>>> break; >>>> p++; /* use_after_cand_inc == false */ >>>> } >>>> while (1); >>>> >>>> and not for >>>> >>>> do >>>> { >>>> *p = '\0'; >>>> p++; /* use_after_cand_inc == true */ >>>> if (!(i < n)) >>>> break; >>>> i++; /* use_uses_inced_iv == false */ >>>> } >>>> while (1); >>>> >>>> In the latter 2 cases, I cannot simply replace i < n with p < base + n. >>> >>> Why not (other than that the value to compare with varies in these cases, >>> but >>> it always is "the value of p in the last iteration of the loop")? >> >> In the 2 latter cases, the value to compare with will be either base + n >> + 1 or base + n - 1. The code does not handle these cases yet. > > well, if not, then it certainly handles one of the first two cases incorrectly
The ivopts code for the first example is: <bb 2>: p_5 = p_3(D) + i_4(D); D.2698_12 = p_3(D) + n_8(D); <bb 3>: # p_1 = PHI <p_5(2), p_7(4)> *p_1 = 0; p_7 = p_1 + 1; if (p_7 >= D.2698_12) goto <bb 5>; else goto <bb 4>; <bb 4>: goto <bb 3>; <bb 5>: return; and for the second example is: <bb 2>: p_5 = p_3(D) + i_4(D); D.2704_13 = p_3(D) + n_6(D); <bb 3>: # p_1 = PHI <p_5(2), p_8(4)> *p_1 = 0; if (p_1 >= D.2704_13) goto <bb 5>; else goto <bb 4>; <bb 4>: p_8 = p_1 + 1; goto <bb 3>; <bb 5>: return; both seem correct to me. > (since the use_uses_inced_iv test is meaningless). To me it seems use_uses_inced_iv has meaning: - it models something: it states whether the comparison is using the iv increment result or the iv phi result. - it is used to detect cases were we would generate incorrect code. >>> One more thing: what is fold_walk_def_plus for? >> >> It tries to fold a plus, and if not successful, finds ssa vars in >> operands of the plus, substitutes the defining statements of ssa vars >> for those ssa vars and retries folding. > > Sorry for not being more clear; I meant, why is it used? > In the following code <bb 2>: p_5 = p_3(D) + i_4(D); <bb 3>: # p_1 = PHI <p_5(2), p_7(4)> # i_2 = PHI <i_4(D)(2), i_6(4)> *p_1 = 0; i_6 = i_2 + 1; p_7 = p_1 + 1; if (i_6 >= n_8(D)) goto <bb 5>; else goto <bb 4>; <bb 4>: goto <bb 3>; <bb 5>: return; I'm trying to prove that p_5 == x + i_4 where x is an ssa_name. I can't do that without going through the defining statement of p_5. > Zdenek