From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12850 invoked by alias); 11 Aug 2010 08:50:12 -0000 Received: (qmail 12835 invoked by uid 22791); 11 Aug 2010 08:50:10 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE X-Spam-Check-By: sourceware.org Received: from mail-qy0-f182.google.com (HELO mail-qy0-f182.google.com) (209.85.216.182) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 11 Aug 2010 08:50:06 +0000 Received: by qyk32 with SMTP id 32so12227957qyk.20 for ; Wed, 11 Aug 2010 01:50:04 -0700 (PDT) MIME-Version: 1.0 Received: by 10.224.104.153 with SMTP id p25mr10681381qao.98.1281516602843; Wed, 11 Aug 2010 01:50:02 -0700 (PDT) Received: by 10.224.28.67 with HTTP; Wed, 11 Aug 2010 01:50:02 -0700 (PDT) In-Reply-To: <8940219999767457518@unknownmsgid> References: <8940219999767457518@unknownmsgid> Date: Wed, 11 Aug 2010 13:49:00 -0000 Message-ID: Subject: Re: Question about tree-switch-conversion.c From: Richard Guenther To: Ian Bolton Cc: gcc@gcc.gnu.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org X-SW-Source: 2010-08/txt/msg00186.txt.bz2 On Tue, Aug 10, 2010 at 6:48 PM, Ian Bolton wrote: > I am in the process of fixing PR44328 > (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D44328) > > The problem is that gen_inbound_check in tree-switch-conversion.c subtrac= ts > info.range_min from info.index_expr, which can cause the MIN and MAX valu= es > for info.index_expr to become invalid. > > For example: > > > typedef enum { > =A0FIRST =3D 0, > =A0SECOND, > =A0THIRD, > =A0FOURTH > } ExampleEnum; > > int dummy (const ExampleEnum e) > { > =A0int mode =3D 0; > =A0switch (e) > =A0{ > =A0 =A0case SECOND: mode =3D 20; break; > =A0 =A0case THIRD: mode =3D 30; break; > =A0 =A0case FOURTH: mode =3D 40; break; > =A0} > =A0return mode; > } > > > tree-switch-conversion would like to create a lookup table for this, so > that SECOND maps to entry 0, THIRD maps to entry 1 and FOURTH maps to > entry 2. =A0It achieves this by subtracting SECOND from index_expr. =A0The > problem is that after the subtraction, the type of the result can have a > value outside the range 0-3. > > Later, when tree-vrp.c sees the inbound check as being <=3D 2 with a poss= ible > range for the type as 0-3, it converts the <=3D2 into a !=3D 3, which is > totally wrong. =A0If e=3D=3DFIRST, then we can end up looking for entry 2= 55 in > the lookup table! > > I think the solution is to update the type of the result of the subtracti= on > to show that it is no longer in the range 0-3, but I have had trouble > implementing this. =A0The attached patch (based off 4.5 branch) shows my > current approach, but I ran into LTO issues: > > lto1: internal compiler error: in lto_get_pickled_tree, at lto-streamer-i= n.c > > I am guessing this is because the debug info for the type does not match > the new range I have set for it. > > Is there a *right* way to update the range such that LTO doesn't get > unhappy? =A0(Maybe a cast with fold_convert_loc would be right?) The fix is to always use a standard unsigned integer type for the new index value. lang_hooks.types.type_for_mode (TYPE_MODE (old-idx-type), 1) would give you one. Richard.