Unnecessary duplication of work

Simon Peyton-Jones simonpj@microsoft.com
Tue, 20 Mar 2001 06:38:57 -0800


Good point.  My recent commit fixes this, by making us less
keen to duplicate primops.  Let's see if this makes anything
worse.

Simon

| -----Original Message-----
| From: Marcin 'Qrczak' Kowalczyk [mailto:qrczak@knm.org.pl]
| Sent: 18 March 2001 21:11
| To: cvs-ghc@haskell.org
| Subject: Unnecessary duplication of work
|=20
|=20
| Consider the following definition.
|=20
| --------------------------------------------------------------
| -----------
| module Cast where
|=20
| import CTypes
| import Char
| import Word
|=20
| cast:: CChar -> Char
| cast ch =3D chr (fromIntegral (fromIntegral ch :: Word8))
| --------------------------------------------------------------
| -----------
|=20
| If chr is replaced by PrelBase.unsafeChr, it generates optimal code
| given ghc's primops (at last!). Manuel: this (with unsafeChr) is the
| preferred implementation of castCCharToChar for c2hs under=20
| ghc >=3D 4.11.
|=20
| But with the above, when chr does bounds checking, the int2Word# ->
| wordToWord8# -> word2Int# computation is unnecessarily done three
| times. I think it would be good if such cases were improved:
|=20
| =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D STG =
syntax: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
| srt: (0,1)
| Cast.cast =3D
|     \r [ch]
| 	case ch of wild {
| 	  PrelInt.I8# x# ->
| 	      case int2Word# [x#] of sat_s47A {
| 		DEFAULT ->
| 		    case wordToWord8# [sat_s47A] of sat_s47D {
| 		      DEFAULT ->
| 			  case word2Int# [sat_s47D] of sat_s47G {
| 			    DEFAULT ->
| 				case >=3D# [sat_s47G 0] of wild1 {
| 				  PrelBase.False ->=20
| PrelErr.error PrelBase.lvl;
| 				  PrelBase.True ->
| 				      case int2Word# [x#] of sat_s47L {
| 					DEFAULT ->
| 					    case wordToWord8#=20
| [sat_s47L] of sat_s47O {
| 					      DEFAULT ->
| 						  case=20
| word2Int# [sat_s47O] of sat_s47R {
| 						    DEFAULT ->
| 							case=20
| <=3D# [sat_s47R 1114111] of wild2 {
| 							 =20
| PrelBase.True ->
| 							     =20
| case int2Word# [x#] of sat_s47W {
| 							=09
| DEFAULT ->
| 								    case
| 							=09
| 	wordToWord8# [sat_s47W]
| 								    of
| 							=09
|     sat_s47Z
| 							=09
|     { DEFAULT ->
| 							=09
| 	  case
| 							=09
| 	      word2Int# [sat_s47Z]
| 							=09
| 	  of
| 							=09
| 	  sat_s482
| 							=09
| 	  { DEFAULT ->
| 							=09
| 		case
| 							=09
| 		    chr# [sat_s482]
| 							=09
| 		of
| 							=09
| 		a
| 							=09
| 		{ DEFAULT ->
| 							=09
| 		      PrelBase.C# [a]
| 							=09
| 		}
| 							=09
| 	  }
| 								    }
| 							      };
| 							 =20
| PrelBase.False ->
| 							     =20
| PrelErr.error PrelBase.lvl;
| 							}
| 						  }
| 					    }
| 				      };
| 				}
| 			  }
| 		    }
| 	      };
| 	};
| SRT: [PrelBase.lvl]
|=20
| --=20
|  __("<  Marcin Kowalczyk * qrczak@knm.org.pl http://qrczak.ids.net.pl/
|  \__/
|   ^^                      SYGNATURA ZAST=CAPCZA
| QRCZAK
|=20
|=20
| _______________________________________________
| Cvs-ghc mailing list
| Cvs-ghc@haskell.org
| http://www.haskell.org/mailman/listinfo/cvs-ghc
|=20
|=20