On Sun, 24 Jul 2011, Sebastian Pop wrote: > On Sun, Jul 24, 2011 at 05:59, Richard Guenther > <richard.guent...@gmail.com> wrote: > > For two IVs with the same precision, one signed and one unsigned you choose > > signedness of the canonical IV based on the random order of PHIs - that > > doesn't > > look correct. > > > > I think what you should do here is use an unsigned type if any of the IVs > > with > > the current max precision is unsigned. > > Attached is the updated patch. Bootstrapped and tested on amd64-linux. > Ok for trunk?
for (psi = gsi_start_phis (loop->header); !gsi_end_p (psi); gsi_next (&psi)) @@ -1207,11 +1209,25 @@ canonicalize_loop_ivs (struct loop *loop, tree *nit, bool bump_in_latch) gimple phi = gsi_stmt (psi); tree res = PHI_RESULT (phi); - if (is_gimple_reg (res) && TYPE_PRECISION (TREE_TYPE (res)) > precision) - precision = TYPE_PRECISION (TREE_TYPE (res)); + if (!is_gimple_reg (res)) + continue; + + type = TREE_TYPE (res); + if (TYPE_PRECISION (type) > precision) + { + precision = TYPE_PRECISION (type); + unsigned_p = TYPE_UNSIGNED (type); + continue; + } + + if (TYPE_PRECISION (type) == precision + && TYPE_UNSIGNED (type)) + unsigned_p = true; } I think we also need to care for non-integral PHIs where TYPE_PRECISION and TYPE_UNSIGNED are not applicable (seems the original code is also buggy here?). So, sth like type = TREE_TYPE (res); if (!is_gimple_reg (res) || !INTEGRAL_TYPE_P (type) || TYPE_PRECISION (type) < precision) continue; precision = TYPE_PRECISION (type); unsigned_p |= TYPE_UNSIGNED (type); } would be ok. Ok with that change. Thanks, Richard. > > Thanks, > Sebastian > -- Richard Guenther <rguent...@suse.de> Novell / SUSE Labs SUSE LINUX Products GmbH - Nuernberg - AG Nuernberg - HRB 16746 GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer