From 746dfbeb4909850ddb8ad71c3571bb41fedd6d06 Mon Sep 17 00:00:00 2001
From: whh8b <whh8b@git.zephyr-software.com>
Date: Sat, 13 Feb 2016 06:56:57 +0000
Subject: [PATCH] Fallthrough coalesce calculations were not correct.

---
 src/zipr.cpp | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/zipr.cpp b/src/zipr.cpp
index 744f942..2a11c05 100644
--- a/src/zipr.cpp
+++ b/src/zipr.cpp
@@ -1575,6 +1575,7 @@ void ZiprImpl_t::PlaceDollops()
 
 			if ((fallthrough = to_place->FallthroughDollop()) != NULL)
 			{
+				size_t fallthrough_wcds = fallthrough->GetSize();
 				size_t fallthrough_wcis = _DetermineWorstCaseInsnSize(fallthrough->
 				                                                      front()->
 																															Instruction());
@@ -1582,8 +1583,9 @@ void ZiprImpl_t::PlaceDollops()
 				if (m_verbose)
 					cout << "Determining whether to coalesce: "
 					     << "Remaining: " << std::dec << remaining_size
-							 << " vs Needed: " << std::dec << fallthrough_wcis << endl;
-				if (remaining_size < fallthrough_wcis || fallthrough->IsPlaced())
+							 << " vs Needed: " << std::dec << std::min(fallthrough_wcis,fallthrough_wcds) << endl;
+				if ((remaining_size < fallthrough_wcis || fallthrough->IsPlaced()) &&
+				    !(remaining_size<=fallthrough_wcds))
 				{
 
 					string patch_jump_string;
-- 
GitLab