From 796e15ad277b33e4405c1146b06413d57f478c70 Mon Sep 17 00:00:00 2001 From: GregF Date: Tue, 5 Jan 2016 13:00:04 -0700 Subject: [PATCH] spirv-remap: inhibit loadstore opt if variable ref'd by other instructions --- SPIRV/SPVRemapper.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/SPIRV/SPVRemapper.cpp b/SPIRV/SPVRemapper.cpp index 2d42f44..3fa233c 100755 --- a/SPIRV/SPVRemapper.cpp +++ b/SPIRV/SPVRemapper.cpp @@ -727,13 +727,16 @@ namespace spv { const int wordCount = asWordCount(start); // Add local variables to the map - if ((opCode == spv::OpVariable && spv[start+3] == spv::StorageClassFunction && asWordCount(start) == 4)) + if ((opCode == spv::OpVariable && spv[start+3] == spv::StorageClassFunction && asWordCount(start) == 4)) { fnLocalVars.insert(asId(start+2)); + return true; + } // Ignore process vars referenced via access chain if ((opCode == spv::OpAccessChain || opCode == spv::OpInBoundsAccessChain) && fnLocalVars.count(asId(start+3)) > 0) { fnLocalVars.erase(asId(start+3)); idMap.erase(asId(start+3)); + return true; } if (opCode == spv::OpLoad && fnLocalVars.count(asId(start+3)) > 0) { @@ -748,6 +751,7 @@ namespace spv { fnLocalVars.erase(asId(start+3)); idMap.erase(asId(start+3)); } + return true; } if (opCode == spv::OpStore && fnLocalVars.count(asId(start+1)) > 0) { @@ -764,11 +768,20 @@ namespace spv { fnLocalVars.erase(asId(start+3)); idMap.erase(asId(start+3)); } + return true; } - return true; + return false; }, - op_fn_nop); + + // If local var id used anywhere else, don't eliminate + [&](spv::Id& id) { + if (fnLocalVars.count(id) > 0) { + fnLocalVars.erase(id); + idMap.erase(id); + } + } + ); process( [&](spv::Op opCode, unsigned start) { -- 2.7.4