On Tue, 1 Nov 2016, Marc Glisse wrote: > On Mon, 31 Oct 2016, Richard Biener wrote: > > > On Fri, 28 Oct 2016, Marc Glisse wrote: > > > > > On Wed, 28 Sep 2016, Richard Biener wrote: > > > > > > > The following patch implements patterns to catch x / abs (x) > > > > and x / -x, taking advantage of undefinedness at x == 0 as > > > > opposed to the PR having testcases with explicit != 0 checks. > > > > > > > > Bootstrap / regtest pending on x86_64-unknown-linux-gnu. > > > > > > > > Richard. > > > > > > > > 2016-09-28 Richard Biener <rguent...@suse.de> > > > > > > > > PR middle-end/77407 > > > > * match.pd: Add X / abs (X) -> X < 0 ? -1 : 1 and > > > > X / -X -> -1 simplifications. > > > > > > I notice that we still have the following comment a few lines above: > > > > > > /* Make sure to preserve divisions by zero. This is the reason why > > > we don't simplify x / x to 1 or 0 / x to 0. */ > > > > > > Did we give up on preserving divisions by 0? Can we now do the 2 > > > simplifications listed by the comment? > > > > At some point there was at least diagnostics fallout when doing them. > > There may be also undefined sanitizer fallout depending on when we > > instrument for that. > > > > But in general yes, we do want to do the two simplifications. Maybe > > we can compromise (in case of early fallout) to do them on GIMPLE > > only. > > > > We could at least add them with a proper nonzero_p predicate. > > (for div (trunc_div ceil_div floor_div round_div exact_div) > + (simplify (div @0 @0) { build_one_cst (type); }) > + (simplify (div integer_zerop@0 @1) @0) > > causes no regression on powerpc64le-unknown-linux-gnu with > --enable-languages=all,obj-c++,go.
Good. I probably tried last before the C++ early folding changes. If you'd formally post a patch adding the above (and adjusting the comment) I'll approve that. This eventually means we can remove the if (integer_zerop ()) early out in fold_binary_loc as well. Richard.