summaryrefslogtreecommitdiffstats
path: root/src/glsl/opt_algebraic.cpp
diff options
context:
space:
mode:
authorEric Anholt <eric@anholt.net>2013-10-21 17:01:49 -0700
committerEric Anholt <eric@anholt.net>2013-10-28 14:07:31 -0700
commit08bf52712e9dbd32ea3e4855c3446eba624fc890 (patch)
tree7c30380a6b9becc9c3977629a4c5edbe5044d1e9 /src/glsl/opt_algebraic.cpp
parent3a0fdf2ab6ab9c66c50645409d8f79bcd6f8ed1b (diff)
downloadexternal_mesa3d-08bf52712e9dbd32ea3e4855c3446eba624fc890.zip
external_mesa3d-08bf52712e9dbd32ea3e4855c3446eba624fc890.tar.gz
external_mesa3d-08bf52712e9dbd32ea3e4855c3446eba624fc890.tar.bz2
glsl: Drop no-op shifts involving 0.
I noticed this in a shader in Unigine Heaven that was spilling. While it doesn't really reduce register pressure, it shaves a few instructions anyway (7955 -> 7882). v2: Fix turning "0 >> x" into "x" instead of "0" (caught by Erik Faye-Lund). Reviewed-by: Kenneth Graunke <kenneth@whitecape.org> Reviewed-by: Matt Turner <mattst88@gmail.com>
Diffstat (limited to 'src/glsl/opt_algebraic.cpp')
-rw-r--r--src/glsl/opt_algebraic.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/glsl/opt_algebraic.cpp b/src/glsl/opt_algebraic.cpp
index 2e33dfe..a07e153 100644
--- a/src/glsl/opt_algebraic.cpp
+++ b/src/glsl/opt_algebraic.cpp
@@ -346,6 +346,16 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
}
break;
+ case ir_binop_rshift:
+ case ir_binop_lshift:
+ /* 0 >> x == 0 */
+ if (is_vec_zero(op_const[0]))
+ return ir->operands[0];
+ /* x >> 0 == x */
+ if (is_vec_zero(op_const[1]))
+ return ir->operands[0];
+ break;
+
case ir_binop_logic_and:
/* FINISHME: Also simplify (a && a) to (a). */
if (is_vec_one(op_const[0])) {