From 1e5c784e48929c0da7e287fbc233a7d49391d619 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Thu, 3 Mar 2011 14:46:46 -0800 Subject: [PATCH] mesa: Extend variable lifetimes to the start of the loop containing a def Consider the following situation: 1. The variable is defined in a loop. 2. The variable has no other use inside the loop. 3. The definition inside the loop is reachable outside the loop. The problem is that the register allocator only marks the live range for the variable as extending from the definition inside the loop to the use outside the loop. The live interval should extend from the beginning of the loop to the use outside the loop. This patch extends the liveness interval back to the start of the loop containing the definition. This fixes the test case at hand, but may still fail with nested loops where only the innermost loop contains a definition, and that definition is reachable outside all the loops. Moreover, this results in unnecessarily large liveness intervals for values only reachable inside the loop. The proper fix would likely require significant work. --- src/mesa/program/prog_optimize.c | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-) diff --git a/src/mesa/program/prog_optimize.c b/src/mesa/program/prog_optimize.c index 96971f2..33eddcc 100644 --- a/src/mesa/program/prog_optimize.c +++ b/src/mesa/program/prog_optimize.c @@ -956,6 +956,16 @@ update_interval(GLint intBegin[], GLint intEnd[], else { intEnd[index] = ic; } + + /* Extend the liveness interval to at least the beginning of the loop + * containing this usage. This seems to fix problems encountered when a + * variable is defined (but not otherwise used) inside a loop, and that + * definition is used outside the loop. + */ + if (loopStackDepth > 0 + && intBegin[index] > loopStack[loopStackDepth - 1].Start) { + intBegin[index] = loopStack[loopStackDepth - 1].Start; + } } -- 1.7.4