[Mesa-dev] [PATCH 10/23] glsl: Optimize certain if-statements to ir_triop_csel
Ian Romanick
idr at freedesktop.org
Fri Mar 20 13:58:10 PDT 2015
From: Ian Romanick <ian.d.romanick at intel.com>
Some shaders end up with code that looks something like:
if (condition)
result = <constant A>;
else
result = <constant B>;
This pass converts those if-statements to
result = mix(<constant A>, <constant B>, condition);
Quite a few of the helped shaders are vertex shaders, mostly from Warsow
and Tesseract. Also, the "instructions in affected programs" percentage
is a bit skewed by a single shader that is really, really helped (FS
SIMD16: 906 -> 634 (-30.02%), FS SIMD8: 871 -> 595 (-31.69%)).
Shader-db results:
GM45 (0x2A42):
total instructions in shared programs: 3545804 -> 3545604 (-0.01%)
instructions in affected programs: 95801 -> 95601 (-0.21%)
helped: 167
HURT: 93
Iron Lake (0x0046):
total instructions in shared programs: 4975982 -> 4975777 (-0.00%)
instructions in affected programs: 94739 -> 94534 (-0.22%)
helped: 171
HURT: 95
GAINED: 2
Sandy Bridge (0x0116):
total instructions in shared programs: 6803487 -> 6803299 (-0.00%)
instructions in affected programs: 244015 -> 243827 (-0.08%)
helped: 163
HURT: 794
Sandy Bridge (0x0116) NIR:
total instructions in shared programs: 6811992 -> 6811661 (-0.00%)
instructions in affected programs: 10946 -> 10615 (-3.02%)
helped: 61
HURT: 10
Ivy Bridge (0x0166):
total instructions in shared programs: 6279862 -> 6279602 (-0.00%)
instructions in affected programs: 209475 -> 209215 (-0.12%)
helped: 149
HURT: 733
Ivy Bridge (0x0166) NIR:
total instructions in shared programs: 6319460 -> 6319127 (-0.01%)
instructions in affected programs: 10377 -> 10044 (-3.21%)
helped: 63
HURT: 10
Haswell (0x0426):
total instructions in shared programs: 5764623 -> 5764382 (-0.00%)
instructions in affected programs: 188540 -> 188299 (-0.13%)
helped: 149
HURT: 737
Haswell (0x0426) NIR:
total instructions in shared programs: 5794483 -> 5794178 (-0.01%)
instructions in affected programs: 10296 -> 9991 (-2.96%)
helped: 58
HURT: 14
Broadwell (0x162E):
total instructions in shared programs: 6811377 -> 6811611 (0.00%)
instructions in affected programs: 195190 -> 195424 (0.12%)
helped: 91
HURT: 806
GAINED: 2
Broadwell (0x162E) NIR:
total instructions in shared programs: 7008297 -> 7008390 (0.00%)
instructions in affected programs: 8508 -> 8601 (1.09%)
helped: 2
HURT: 30
LOST: 12
Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
---
src/glsl/opt_if_to_bool_cast.cpp | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/src/glsl/opt_if_to_bool_cast.cpp b/src/glsl/opt_if_to_bool_cast.cpp
index 20a27e3..aba9f9e 100644
--- a/src/glsl/opt_if_to_bool_cast.cpp
+++ b/src/glsl/opt_if_to_bool_cast.cpp
@@ -172,6 +172,12 @@ ir_if_to_bool_cast_visitor::visit_leave(ir_if *ir)
a = emit_0_or_1_assigment(then_assign->lhs, then_assign->write_mask,
ir->condition,
then_rhs, else_rhs);
+ } else {
+ const unsigned size = _mesa_bitcount(then_assign->write_mask);
+
+ a = assign(then_assign->lhs,
+ csel(swizzle(ir->condition, SWIZZLE_XXXX, size),
+ then_rhs, else_rhs));
}
if (a != NULL) {
--
2.1.0
More information about the mesa-dev
mailing list