diff --git a/src/compiler/main.lisp b/src/compiler/main.lisp
index 5c5386dd829b723f16ade88b3ea975061008564a..58ab89c352382944437c878b5e1257870f62667f 100644
--- a/src/compiler/main.lisp
+++ b/src/compiler/main.lisp
@@ -2045,7 +2045,7 @@
 			  (function-lambda-expression definition)
 			(if (and exp (not lexenv))
 			    `#',exp
-			    `',definition)))))
+			    definition)))))
 	     (*source-info* (make-lisp-source-info form))
 	     (*top-level-lambdas* ())
 	     (*converting-for-interpreter* nil)
@@ -2069,6 +2069,14 @@
 	     (*gensym-counter* 0)
 	     (*current-function-names* (list name))
 	     (intl::*default-domain* intl::*default-domain*))
+	;; As mentioned above, we can return the same function if the
+	;; function was already compiled.  We do this when FORM is EQ
+	;; to DEFINITION (which happens above if we have a compiled
+	;; function that we don't have the source for or was defined
+	;; in a non-null environment.
+	(when (and name (eq form definition))
+	  (return-from compile
+	    (values name nil nil)))
 	(with-debug-counters
 	  (clear-stuff)
 	  (find-source-paths form 0)