diff --git a/CHANGES b/CHANGES
index 2ef647fd73761e5c24ed33c200b55305b44198c3..541ba1a72080b97550da33306538f18e5a0a79bd 100644
--- a/CHANGES
+++ b/CHANGES
@@ -91,6 +91,10 @@ o Compiler
   - Fixed some corner cases where file names where missing from
     backtraces.
 
+  - Check the proper flag to determine if a local variable may be used
+    before optimizing away certain assignments if the assignment is
+    immediately followed by a return of the variable in question.
+
 Crypto.ECC
 
   Now works against Nettle 3.5.
diff --git a/src/peep.in b/src/peep.in
index bb7e5d754e9191edd8bb7c84282012beff910991..7c27227e49ed13abf107bc4e55d66afd2a383532 100644
--- a/src/peep.in
+++ b/src/peep.in
@@ -216,8 +216,8 @@ ASSIGN_GLOBAL_AND_POP GLOBAL_LVALUE($1a) DEC_AND_POP : ADD_NEG_INT(1) ASSIGN_GLO
 GLOBAL_LVALUE INC_AND_POP GLOBAL($1a) : GLOBAL_LVALUE($1a) INC
 GLOBAL_LVALUE DEC_AND_POP GLOBAL($1a) : GLOBAL_LVALUE($1a) DEC
 
-ASSIGN_LOCAL RETURN [!(Pike_compiler->compiler_frame->lexical_scope & SCOPE_SCOPED)]: RETURN
-ASSIGN_LOCAL VOLATILE_RETURN [!(Pike_compiler->compiler_frame->lexical_scope & SCOPE_SCOPED)]: VOLATILE_RETURN
+ASSIGN_LOCAL RETURN [!(Pike_compiler->compiler_frame->lexical_scope & SCOPE_SCOPE_USED)]: RETURN
+ASSIGN_LOCAL VOLATILE_RETURN [!(Pike_compiler->compiler_frame->lexical_scope & SCOPE_SCOPE_USED)]: VOLATILE_RETURN
 
 ASSIGN_LOCAL BRANCH_WHEN_ZERO LOCAL($1a) RETURN LABEL($2a): ASSIGN_LOCAL($1a) RETURN_IF_TRUE LABEL($2a)
 ASSIGN_LOCAL BRANCH_WHEN_ZERO LOCAL($1a) VOLATILE_RETURN LABEL($2a): ASSIGN_LOCAL($1a) RETURN_IF_TRUE LABEL($2a)