This is the mail archive of the
mailing list for the GCC project.
Re: [PATCH] Fix optimize_range_tests_diff
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Jeff Law <law at redhat dot com>
- Cc: Richard Biener <rguenther at suse dot de>, gcc-patches at gcc dot gnu dot org
- Date: Tue, 14 Oct 2014 19:40:02 +0200
- Subject: Re: [PATCH] Fix optimize_range_tests_diff
- Authentication-results: sourceware.org; auth=none
- References: <20141014160219 dot GF10376 at tucnak dot redhat dot com> <543D5C0A dot 1070103 at redhat dot com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Tue, Oct 14, 2014 at 11:23:22AM -0600, Jeff Law wrote:
> On 10/14/14 10:02, Jakub Jelinek wrote:
> >When hacking on range reassoc opt, I've noticed we can emit
> >code with undefined behavior even when there wasn't one originally,
> >in particular for:
> > (X - 43U) <= 3U || (X - 75U) <= 3U
> > and this loop can transform that into
> > ((X - 43U) & ~(75U - 43U)) <= 3U. */
> >we actually don't transform it to what the comment says, but
> > ((X - 43) & ~(75U - 43U)) <= 3U
> >i.e. the initial subtraction can be performed in signed type,
> >if in here X is e.g. INT_MIN or INT_MIN + 42, the subtraction
> >at gimple level would be UB (not caught by -fsanitize=undefined,
> >because that is handled much earlier).
> >Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
> >2014-10-14 Jakub Jelinek <firstname.lastname@example.org>
> > * tree-ssa-reassoc.c (optimize_range_tests_diff): Perform
> > MINUS_EXPR in unsigned type to avoid undefined behavior.
> Any chance this fixes:
No. For that I have right now:
- if (tree_log2 (lowxor) < 0)
+ if (wi::popcount (wi::to_widest (lowxor)) != 1)
in my tree, though supposedly:
if (wi::popcount (wi::zext (wi::to_widest (lowxor), TYPE_PRECISION (TREE_TYPE (lowxor)))) != 1)
might be better, as without zext it will supposedly
not say popcount is 1 for smaller precision signed minimum values.
My wide-int-fu is limited, so if there is a better way to do this, I'm all