From 639f7cfd2d91d5b9cdd92228bfbf875bf72ccb70 Mon Sep 17 00:00:00 2001 From: MerryMage Date: Mon, 27 Nov 2017 19:41:22 +0000 Subject: [PATCH] reg_alloc: Add IsLastUse optimization for UseScratch --- src/backend_x64/reg_alloc.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/backend_x64/reg_alloc.cpp b/src/backend_x64/reg_alloc.cpp index 6edb7d73..75906d14 100644 --- a/src/backend_x64/reg_alloc.cpp +++ b/src/backend_x64/reg_alloc.cpp @@ -81,7 +81,7 @@ bool HostLocInfo::IsEmpty() const { } bool HostLocInfo::IsLastUse() const { - return !is_being_used && current_references == 1; + return !is_being_used && current_references == 1 && accumulated_uses + 1 == total_uses; } bool HostLocInfo::ContainsValue(const IR::Inst* inst) const { @@ -283,7 +283,9 @@ HostLoc RegAlloc::UseScratchImpl(IR::Value use_value, HostLocList desired_locati const bool can_use_current_location = std::find(desired_locations.begin(), desired_locations.end(), current_location) != desired_locations.end(); if (can_use_current_location && !LocInfo(current_location).IsLocked()) { - MoveOutOfTheWay(current_location); + if (!LocInfo(current_location).IsLastUse()) { + MoveOutOfTheWay(current_location); + } LocInfo(current_location).WriteLock(); return current_location; }