r300: remove most of backend contant folding
authorPavel Ondračka <pavel.ondracka@gmail.com>
Thu, 15 Jun 2023 11:29:50 +0000 (13:29 +0200)
committerMarge Bot <emma+marge@anholt.net>
Wed, 5 Jul 2023 18:34:37 +0000 (18:34 +0000)
This is now done in NIR. The remaining one for ADD + 0 to MOV is kept
until we move some remaining part of FS lowering to NIR.

There single regressions is in one d3d->glsl shader from Wine.
Wine sets invariant for glPosition which translates to exact bit for all
calculations leading to it (or the TGSI PRECISE flag). r300 backend
ignores is completelly, so removing the backend optimizations should
even make us more correct in this regards.

RV530:
total instructions in shared programs: 130705 -> 130706 (<.01%)
instructions in affected programs: 16 -> 17 (6.25%)
helped: 0
HURT: 1

RV370: no change

Reviewed-by: Filip Gawin <filip.gawin@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23927>

src/gallium/drivers/r300/compiler/radeon_optimize.c

index aeda6db..d6a911d 100644 (file)
@@ -242,82 +242,6 @@ static int is_src_uniform_constant(struct rc_src_register src,
        return 1;
 }
 
-static void constant_folding_mad(struct rc_instruction * inst)
-{
-       rc_swizzle swz = 0;
-       unsigned int negate= 0;
-
-       if (is_src_uniform_constant(inst->U.I.SrcReg[2], &swz, &negate)) {
-               if (swz == RC_SWIZZLE_ZERO) {
-                       inst->U.I.Opcode = RC_OPCODE_MUL;
-                       return;
-               }
-       }
-
-       if (is_src_uniform_constant(inst->U.I.SrcReg[1], &swz, &negate)) {
-               if (swz == RC_SWIZZLE_ONE) {
-                       inst->U.I.Opcode = RC_OPCODE_ADD;
-                       if (negate)
-                               inst->U.I.SrcReg[0].Negate ^= RC_MASK_XYZW;
-                       inst->U.I.SrcReg[1] = inst->U.I.SrcReg[2];
-                       return;
-               } else if (swz == RC_SWIZZLE_ZERO) {
-                       inst->U.I.Opcode = RC_OPCODE_MOV;
-                       inst->U.I.SrcReg[0] = inst->U.I.SrcReg[2];
-                       return;
-               }
-       }
-
-       if (is_src_uniform_constant(inst->U.I.SrcReg[0], &swz, &negate)) {
-               if (swz == RC_SWIZZLE_ONE) {
-                       inst->U.I.Opcode = RC_OPCODE_ADD;
-                       if (negate)
-                               inst->U.I.SrcReg[1].Negate ^= RC_MASK_XYZW;
-                       inst->U.I.SrcReg[0] = inst->U.I.SrcReg[2];
-                       return;
-               } else if (swz == RC_SWIZZLE_ZERO) {
-                       inst->U.I.Opcode = RC_OPCODE_MOV;
-                       inst->U.I.SrcReg[0] = inst->U.I.SrcReg[2];
-                       return;
-               }
-       }
-}
-
-static void constant_folding_mul(struct rc_instruction * inst)
-{
-       rc_swizzle swz = 0;
-       unsigned int negate = 0;
-
-       if (is_src_uniform_constant(inst->U.I.SrcReg[0], &swz, &negate)) {
-               if (swz == RC_SWIZZLE_ONE) {
-                       inst->U.I.Opcode = RC_OPCODE_MOV;
-                       inst->U.I.SrcReg[0] = inst->U.I.SrcReg[1];
-                       if (negate)
-                               inst->U.I.SrcReg[0].Negate ^= RC_MASK_XYZW;
-                       return;
-               } else if (swz == RC_SWIZZLE_ZERO) {
-                       inst->U.I.Opcode = RC_OPCODE_MOV;
-                       inst->U.I.SrcReg[0].Swizzle = RC_SWIZZLE_0000;
-                       inst->U.I.SrcReg[0].File = RC_FILE_NONE;
-                       return;
-               }
-       }
-
-       if (is_src_uniform_constant(inst->U.I.SrcReg[1], &swz, &negate)) {
-               if (swz == RC_SWIZZLE_ONE) {
-                       inst->U.I.Opcode = RC_OPCODE_MOV;
-                       if (negate)
-                               inst->U.I.SrcReg[0].Negate ^= RC_MASK_XYZW;
-                       return;
-               } else if (swz == RC_SWIZZLE_ZERO) {
-                       inst->U.I.Opcode = RC_OPCODE_MOV;
-                       inst->U.I.SrcReg[0].Swizzle = RC_SWIZZLE_0000;
-                       inst->U.I.SrcReg[0].File = RC_FILE_NONE;
-                       return;
-               }
-       }
-}
-
 static void constant_folding_add(struct rc_instruction * inst)
 {
        rc_swizzle swz = 0;
@@ -420,14 +344,8 @@ static void constant_folding(struct radeon_compiler * c, struct rc_instruction *
                inst->U.I.SrcReg[src] = newsrc;
        }
 
-       /* Simplify instructions based on constants */
-       if (inst->U.I.Opcode == RC_OPCODE_MAD)
-               constant_folding_mad(inst);
-
-       /* note: MAD can simplify to MUL or ADD */
-       if (inst->U.I.Opcode == RC_OPCODE_MUL)
-               constant_folding_mul(inst);
-       else if (inst->U.I.Opcode == RC_OPCODE_ADD)
+       if (c->type == RC_FRAGMENT_PROGRAM &&
+               inst->U.I.Opcode == RC_OPCODE_ADD)
                constant_folding_add(inst);
 
        /* In case this instruction has been converted, make sure all of the