From: Mikko Rasa Date: Mon, 8 Nov 2021 00:09:11 +0000 (+0200) Subject: Block further inlining of a variable after component assignment X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=31f76e306f8e01884fa464ac6e09e8b48af5f79b;p=libs%2Fgl.git Block further inlining of a variable after component assignment --- diff --git a/source/glsl/optimize.cpp b/source/glsl/optimize.cpp index a7f29a16..c9d3c33a 100644 --- a/source/glsl/optimize.cpp +++ b/source/glsl/optimize.cpp @@ -356,7 +356,7 @@ void ExpressionInliner::visit(RefPtr &expr) ExpressionUse use; use.reference = &expr; use.ref_scope = current_block; - use.blocked = access_write; + use.blocked = access_write || r_ref_info->blocked; if(iteration_body && !r_ref_info->trivial) { @@ -428,10 +428,10 @@ void ExpressionInliner::visit(Assignment &assign) r_trivial = true; visit(assign.right); - auto i = assignments.find(assign.target); + auto i = assignments.find(assign.target.declaration); if(i!=assignments.end()) { - if(iteration_body && i->second->expression) + if(iteration_body && i->second && i->second->expression) { /* Block inlining into previous references within the iteration statement. On iterations after the first they would refer to the @@ -441,6 +441,10 @@ void ExpressionInliner::visit(Assignment &assign) u.blocked = (k==iteration_body); } + for(; (i!=assignments.end() && i->first.declaration==assign.target.declaration); ++i) + if(targets_overlap(i->first, assign.target)) + i->second->blocked = true; + expressions.push_back(ExpressionInfo()); ExpressionInfo &info = expressions.back(); info.target = assign.target; @@ -450,7 +454,7 @@ void ExpressionInliner::visit(Assignment &assign) info.assign_scope = current_block; info.trivial = r_trivial; - i->second = &info; + assignments[assign.target] = &info; } r_trivial = false; diff --git a/source/glsl/optimize.h b/source/glsl/optimize.h index 9b7b7aff..82fc78cc 100644 --- a/source/glsl/optimize.h +++ b/source/glsl/optimize.h @@ -122,6 +122,7 @@ private: Block *assign_scope = 0; std::vector uses; bool trivial = false; + bool blocked = false; }; std::list expressions; diff --git a/tests/glsl/member_assignment.glsl b/tests/glsl/member_assignment.glsl index 8444cfca..77451db0 100644 --- a/tests/glsl/member_assignment.glsl +++ b/tests/glsl/member_assignment.glsl @@ -1,9 +1,8 @@ #pragma MSP stage(vertex) void main() { - vec4 p; + vec4 p = vec4(0.0); p.x = 1.0; - p.y = 0.0; p.z = 2.0; p.w = 1.0; gl_Position = p; @@ -12,9 +11,8 @@ void main() /* Expected output: vertex void main() { - vec4 p; + vec4 p = vec4(0.0); p.x = 1.0; - p.y = 0.0; p.z = 2.0; p.w = 1.0; gl_Position = p;