[Mesa-dev] r300/compiler: Peephole optimizer.

Tom Stellard tstellar at gmail.com
Tue May 11 09:45:32 PDT 2010


I have been testing the peephole optimizer from Nicolai's r300g-glsl
branch.  There is a bug in it that breaks two of the piglit test cases:
glsl-fs-fragcoord and glsl-orangebook-ch06-bump.  Here is an example of
the bug from glsl-fs-fragcoord:

0: RCP temp[3].w, input[0].w___;
1: MUL temp[3].xy, input[0].xy__, temp[3].ww__;
2: MAD temp[3].xy, temp[3].xy__, const[3].xy__, const[4].xy__;
3: ADD temp[0].y, const[1]._y__, -temp[3]._y__;
4: RCP temp[1].w, const[2].x___;
5: MUL temp[1].y, temp[3]._x__, temp[1]._w__;
6: MOV temp[1].x, temp[1].y___;
7: RCP temp[2].x, const[2].x___;
8: MUL temp[1].z, temp[0].__y_, temp[2].__x_;
9: MOV temp[1].y, temp[1]._z__;
10: MOV temp[1].z, const[2].__y_;
11: MOV output[0].x, temp[1].x___;
12: MOV output[0].y, temp[1]._y__;
13: MOV output[0].z, temp[1].__z_;
14: MOV output[0].w, const[2].___y;

In this case the peephole optimizer looks at instruction 6, and then
replace all occurrences of temp[1].x with temp[1].y.  This affects
instruction 11:
11: MOV output[0].x, temp[1].x___; -> 11: MOV output[0].x, temp[1].y___;

This is a problem because temp[1].y is written to in instruction 9,
so it will no longer have the same value as temp[1].x when instruction
11 is executed.

I have attached a patch that appears to fix the problem.
In order to apply this patch, you will first need to
cherry-pick commit a5e64199f8359cbff589acc9581b264226c41335 from
git://anongit.freedesktop.org/~nh/mesa into master.

With this patch, the peephole optimizer passes all the GLSL
piglit tests that are currently passed by mesa's master
branch.  Here are the piglit results for master, master +
peephole optimizer, and master + peephole optimizier + patch.
http://ix.cs.uoregon.edu/~tstellar/piglit/peephole/index.html

-Tom

-------------- next part --------------
diff --git a/src/mesa/drivers/dri/r300/compiler/radeon_optimize.c b/src/mesa/drivers/dri/r300/compiler/radeon_optimize.c
index 80e3eea..73ece66 100644
--- a/src/mesa/drivers/dri/r300/compiler/radeon_optimize.c
+++ b/src/mesa/drivers/dri/r300/compiler/radeon_optimize.c
@@ -109,7 +109,8 @@ static void peephole_scan_write(void * data, struct rc_instruction * inst,
 			s->DefinedMask |= mask;
 		else
 			s->DefinedMask &= ~mask;
-	} else if (file == s->Mov->U.I.SrcReg[0].File && index == s->Mov->U.I.SrcReg[0].Index) {
+	}
+	if (file == s->Mov->U.I.SrcReg[0].File && index == s->Mov->U.I.SrcReg[0].Index) {
 		if (mask & s->SourcedMask)
 			s->SourceClobbered = 1;
 	} else if (s->Mov->U.I.SrcReg[0].RelAddr && file == RC_FILE_ADDRESS) {


More information about the mesa-dev mailing list