Index: src/GenPoly/Lvalue.cc
===================================================================
--- src/GenPoly/Lvalue.cc	(revision da7fe3906c96450ab7bb9652fd41097ef1096f9e)
+++ src/GenPoly/Lvalue.cc	(revision 9d5fb67025ec52a84362a28c45f4506dd325a92c)
@@ -17,5 +17,4 @@
 #include <string>                        // for string
 
-#include "Common/Debug.h"
 #include "Common/PassVisitor.h"
 #include "GenPoly.h"                     // for isPolyType
@@ -129,19 +128,11 @@
 		PassVisitor<AddrRef> addrRef;
 		PassVisitor<FixIntrinsicResult> intrinsicResults;
-		Debug::codeGen( translationUnit, "begin" );
 		mutateAll( translationUnit, intrinsicResults );
-		Debug::codeGen( translationUnit, "intrinsicResults" );
 		mutateAll( translationUnit, addrRef );
-		Debug::codeGen( translationUnit, "addrRef" );
 		mutateAll( translationUnit, refCvt );
-		Debug::codeGen( translationUnit, "refCvt" );
 		mutateAll( translationUnit, fixer );
-		Debug::codeGen( translationUnit, "fixer" );
 		mutateAll( translationUnit, collapser );
-		Debug::codeGen( translationUnit, "collapser" );
 		mutateAll( translationUnit, genLval );
-		Debug::codeGen( translationUnit, "genLval" );
 		mutateAll( translationUnit, elim );  // last because other passes need reference types to work
-		Debug::codeGen( translationUnit, "elim" );
 
 		// from this point forward, no other pass should create reference types.
@@ -310,6 +301,12 @@
 				}
 
-				if ( addCast ) {
-					PRINT( std::cerr << "adding cast..." << std::endl; )
+				// if addrExpr depth is 0, then the result is a pointer because the arg was depth 1 and not lvalue.
+				// This means the dereference result is not a reference, is lvalue, and one less pointer depth than
+				// the addrExpr. Thus the cast is meaningless.
+				// TODO: One thing to double check is whether it is possible for the types to differ outside of the single
+				// pointer level (i.e. can the base type of addrExpr differ from the type of addrExpr-arg?).
+				// If so then the cast might need to be added, conditional on a more sophisticated check.
+				if ( addCast && addrExpr->result->referenceDepth() != 0 ) {
+					PRINT( std::cerr << "adding cast to " << addrExpr->result << std::endl; )
 					return new CastExpr( ret, addrExpr->result->clone() );
 				}
