aboutsummaryrefslogtreecommitdiffstats
path: root/src/mesa/state_tracker
diff options
context:
space:
mode:
authorGert Wollny <[email protected]>2018-06-05 22:26:37 +0200
committerGert Wollny <[email protected]>2018-08-11 12:32:42 +0200
commitf40c9d02254cd26d2ff92e3f42825fcd7badad92 (patch)
tree22191ec1a26b5c31d49fb95ab447a7a8cccee1e7 /src/mesa/state_tracker
parent568bda2f2d3a3c1bef172563941d36d35a91b5b7 (diff)
mesa/st/glsl_to_tgsi: Properly resolve life times simple if/else + use constructs
in constructs like below, currently the live range estimation extends the live range of t unecessarily to the whole loop because it was not detected that t is unconditional written and later read only in the "if (a)" scope. while (foo) { ... if (a) { ... if (b) t = ... else t = ... x = t; ... } ... } This patch adds a unit test for this case and corrects the minimal live range estimation accordingly. v4: update comments Signed-off-by: Gert Wollny <[email protected]> Acked-by: Dave Airlie <[email protected]>
Diffstat (limited to 'src/mesa/state_tracker')
-rw-r--r--src/mesa/state_tracker/st_glsl_to_tgsi_temprename.cpp14
-rw-r--r--src/mesa/state_tracker/tests/test_glsl_to_tgsi_lifetime.cpp25
2 files changed, 39 insertions, 0 deletions
diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi_temprename.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi_temprename.cpp
index 6921a643b74..8f572ecd2d2 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi_temprename.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi_temprename.cpp
@@ -741,6 +741,20 @@ void temp_comp_access::record_else_write(const prog_scope& scope)
} else {
current_unpaired_if_write_scope = nullptr;
}
+ /* Promote the first write scope to the enclosing scope because
+ * the current IF/ELSE pair is now irrelevant for the analysis.
+ * This is also required to evaluate the minimum life time for t in
+ * {
+ * var t;
+ * if (a)
+ * t = ...
+ * else
+ * t = ...
+ * x = t;
+ * ...
+ * }
+ */
+ first_write_scope = scope.parent();
/* If some parent is IF/ELSE and in a loop then propagate the
* write to that scope. Otherwise the write is unconditional
diff --git a/src/mesa/state_tracker/tests/test_glsl_to_tgsi_lifetime.cpp b/src/mesa/state_tracker/tests/test_glsl_to_tgsi_lifetime.cpp
index acebfb82935..fcd5fda14eb 100644
--- a/src/mesa/state_tracker/tests/test_glsl_to_tgsi_lifetime.cpp
+++ b/src/mesa/state_tracker/tests/test_glsl_to_tgsi_lifetime.cpp
@@ -794,6 +794,31 @@ TEST_F(LifetimeEvaluatorExactTest, WriteInIfElseBranchSecondIfInLoop)
run (code, temp_lt_expect({{-1,-1}, {2,9}}));
}
+/* Within an IF clause within a loop test that if a write occured in both
+ * branches of a nested IF/ELSE clause, followed by the last read within the
+ * enclosing IF or ELSE clause, the combined read is registered as unconditional,
+ * i.e.that it doesn't extend its live range beyond that enclosing IF or ELSE
+ * clause.
+ */
+TEST_F(LifetimeEvaluatorExactTest, DeeplyNestedinLoop)
+{
+ const vector<FakeCodeline> code = {
+ { TGSI_OPCODE_BGNLOOP },
+ { TGSI_OPCODE_UIF, {}, {in0}, {}},
+ { TGSI_OPCODE_FSEQ, {1}, {in1,in2}, {}},
+ { TGSI_OPCODE_UIF, {}, {1}, {}},
+ { TGSI_OPCODE_MOV, {2}, {in1}, {}},
+ { TGSI_OPCODE_ELSE },
+ { TGSI_OPCODE_MOV, {2}, {in2}, {}},
+ { TGSI_OPCODE_ENDIF },
+ { TGSI_OPCODE_MOV, {3}, {2}, {}},
+ { TGSI_OPCODE_ENDIF },
+ { TGSI_OPCODE_ADD, {out0}, {3, in1}, {}},
+ { TGSI_OPCODE_ENDLOOP }
+ };
+ run (code, temp_lt_expect({{-1,-1}, {2,3}, {4, 8}, {0,11}}));
+}
+
/** Regression test for bug #104803,
* Read and write in if/else path outside loop and later read in conditional
* within a loop. The first write is to be considered the dominant write.