Mesa (master): r300/compiler: Add peephole optimization for the 'sub' presubtract operation

Tom Stellard tstellar at kemper.freedesktop.org
Sat Sep 11 02:54:09 UTC 2010


Module: Mesa
Branch: master
Commit: 564653b9f196b9bf91fe772fd1ca1e131ff33774
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=564653b9f196b9bf91fe772fd1ca1e131ff33774

Author: Tom Stellard <tstellar at gmail.com>
Date:   Mon Sep  6 10:57:20 2010 -0700

r300/compiler: Add peephole optimization for the 'sub' presubtract operation

---

 .../drivers/dri/r300/compiler/radeon_optimize.c    |   25 +++++++++++++------
 1 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/src/mesa/drivers/dri/r300/compiler/radeon_optimize.c b/src/mesa/drivers/dri/r300/compiler/radeon_optimize.c
index 3ff07d6..2bed2dd 100644
--- a/src/mesa/drivers/dri/r300/compiler/radeon_optimize.c
+++ b/src/mesa/drivers/dri/r300/compiler/radeon_optimize.c
@@ -597,19 +597,32 @@ static int presub_helper(
 	return can_remove;
 }
 
+/* This function assumes that s->Inst->U.I.SrcReg[0] and
+ * s->Inst->U.I.SrcReg[1] aren't both negative. */
 static void presub_replace_add(struct peephole_state *s,
 						struct rc_instruction * inst,
 						unsigned int src_index)
 {
-	inst->U.I.PreSub.SrcReg[0] = s->Inst->U.I.SrcReg[0];
-	inst->U.I.PreSub.SrcReg[1] = s->Inst->U.I.SrcReg[1];
+	rc_presubtract_op presub_opcode;
+	if (s->Inst->U.I.SrcReg[1].Negate || s->Inst->U.I.SrcReg[0].Negate)
+		presub_opcode = RC_PRESUB_SUB;
+	else
+		presub_opcode = RC_PRESUB_ADD;
+
+	if (s->Inst->U.I.SrcReg[1].Negate) {
+		inst->U.I.PreSub.SrcReg[0] = s->Inst->U.I.SrcReg[1];
+		inst->U.I.PreSub.SrcReg[1] = s->Inst->U.I.SrcReg[0];
+	} else {
+		inst->U.I.PreSub.SrcReg[0] = s->Inst->U.I.SrcReg[0];
+		inst->U.I.PreSub.SrcReg[1] = s->Inst->U.I.SrcReg[1];
+	}
 	inst->U.I.PreSub.SrcReg[0].Negate = 0;
 	inst->U.I.PreSub.SrcReg[1].Negate = 0;
-	inst->U.I.PreSub.Opcode = RC_PRESUB_ADD;
+	inst->U.I.PreSub.Opcode = presub_opcode;
 	inst->U.I.SrcReg[src_index] = chain_srcregs(inst->U.I.SrcReg[src_index],
 						inst->U.I.PreSub.SrcReg[0]);
 	inst->U.I.SrcReg[src_index].File = RC_FILE_PRESUB;
-	inst->U.I.SrcReg[src_index].Index = RC_PRESUB_ADD;
+	inst->U.I.SrcReg[src_index].Index = presub_opcode;
 }
 
 static int peephole_add_presub_add(
@@ -648,10 +661,6 @@ static int peephole_add_presub_add(
 	if (!src1)
 		return 0;
 
-	/* XXX Only do add for now. */
-	if (src0->Negate)
-		return 0;
-
 	s.Inst = inst_add;
 	s.WriteMask = inst_add->U.I.DstReg.WriteMask;
 	if (presub_helper(c, &s, RC_PRESUB_ADD, presub_replace_add)) {




More information about the mesa-commit mailing list