value numbering and cast_to_unsigned (fwd)

Fergus Henderson fjh at cs.mu.oz.au
Sat Feb 22 05:55:18 AEDT 1997


Hi Zoltan,

The changes I made to support 8 bit characters happened to trigger
instances of a bug I reported a couple of months ago, so the compiler
no longer bootstraps at `-O4'.  Can you please fix this one?

> From fjh at murlibobo.cs.mu.OZ.AU Fri Dec  6 07:56:48 1996
> From: Fergus Henderson <fjh at cs.mu.oz.au>
> Message-Id: <199612052056.HAA20501 at murlibobo.cs.mu.OZ.AU>
> Subject: value numbering and cast_to_unsigned
> To: mercury-bugs at cs.mu.oz.au
> Date: Fri, 6 Dec 1996 07:56:47 +1100 (EST)
> X-Mailer: ELM [version 2.4 PL24]
> Content-Type: text
> 
> Hi,
> 
> Value numbering is doing CSE on cast_to_unsigned operators,
> which (due to the unfortunate semantics of cast_to_unsigned)
> is not valid.  This causes it to generate incorrect code for
> lookup switches.  For example (from library/string.c):
> 
> 	{
> 	Word tempr1, tempr2, tempr3;
> 	tempr1 = (Unsigned)((Integer) r2);
> 	{
> 	static const Word mercury_const_1[] = {
> 		((Integer) 287948901175001088),
> 		((Integer) 134217726)
> 	};
> 	r1 = (Integer) field(mktag(0), mkword(mktag(0), mercury_const_1), ((Integer) tempr1 / ((Integer) 64)));
> 	}
> 	if (!(((((Integer) 1) << ((Integer) tempr1 % ((Integer) 64))) & (Integer) r1)))
> 		GOTO_LABEL(mercury__string__base_string_to_int_2_4_0_i1);

The compiler dies in stage3, but a diff of the .c files from stage1 and
stage2 reveals the problem to be the same as the one above.

--- library/char.c	Sat Feb 22 05:34:38 1997
+++ stage2/library/char.c	Sat Feb 22 02:29:55 1997
@@ -605,12 +605,10 @@
 	Integer f1;
 	Integer f2;
 	Integer f3;
-	Integer f4;
 } mercury_const_3 = {
-	(Integer) 0,
-	(Integer) 67043328,
-	(Integer) -2013265922,
-	(Integer) 134217726
+	(Integer) -130049,
+	(Integer) -96257,
+	(Integer) 2047
 };
 
 BEGIN_MODULE(mercury__char_module15)
@@ -620,7 +618,11 @@
 
 /* code for predicate 'char__is_alnum_or_underscore'/1 in mode 0 */
 Define_entry(mercury__char__is_alnum_or_underscore_1_0);
-	if (!((((Integer) 1 << ((Unsigned)(r1) % (Integer) 32)) & (Integer) const_field(mktag(0), (const Word *) mkword(mktag(0), &mercury_const_3), ((Unsigned)(r1) / (Integer) 32)))))
+	r2 = (Unsigned)(((Integer) r1 + (Integer) -48));
+	if (((Integer) r2 > (Integer) 74))
+		GOTO_LABEL(mercury__char__is_alnum_or_underscore_1_0_i1);
+	r3 = const_field(mktag(0), (const Word *) mkword(mktag(0), &mercury_const_3), ((Integer) r2 / (Integer) 32));
+	if (!((((Integer) 1 << ((Integer) r2 % (Integer) 32)) & (Integer) r3)))
 		GOTO_LABEL(mercury__char__is_alnum_or_underscore_1_0_i1);
 	r1 = TRUE;
 	proceed();

-- 
Fergus Henderson <fjh at cs.mu.oz.au>   |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3         |     -- the last words of T. S. Garp.



More information about the developers mailing list