diff --git a/ghc/compiler/codeGen/CgBindery.lhs b/ghc/compiler/codeGen/CgBindery.lhs
index ff4d4c8c1a3d92bbe25a6332302879c2354ab763..459938ddf785c79f903b9e0088d157bf95f6cab7 100644
--- a/ghc/compiler/codeGen/CgBindery.lhs
+++ b/ghc/compiler/codeGen/CgBindery.lhs
@@ -467,8 +467,9 @@ buildLivenessMask uniq sp info_down
 	  ]
 
 	-- flatten this list into a list of unboxed stack slots
-	flatten_slots = foldr (\(ofs,size) r -> [ofs-size+1 .. ofs] ++ r) []
-			   unboxed_slots
+	flatten_slots = sortLt (<) 
+		(foldr (\(ofs,size) r -> [ofs-size+1 .. ofs] ++ r) []
+		      unboxed_slots)
 
 	-- merge in the free slots
 	all_slots = addFreeSlots flatten_slots free ++