X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fcompiler%2Fglsl%2Fopt_constant_folding.cpp;h=97dcc7e1acb60b038b2df33f754e78aeb0442907;hb=f9ab60202d48c72afa6a6f2a8c27db1e0777ed16;hp=ee67420adf851fb4d152e0c127983f3a90871a00;hpb=db8fcbbaf940cdf690878f204f17d8bc90a6768e;p=mesa.git diff --git a/src/compiler/glsl/opt_constant_folding.cpp b/src/compiler/glsl/opt_constant_folding.cpp index ee67420adf8..97dcc7e1acb 100644 --- a/src/compiler/glsl/opt_constant_folding.cpp +++ b/src/compiler/glsl/opt_constant_folding.cpp @@ -91,6 +91,15 @@ ir_constant_fold(ir_rvalue **rvalue) !array_ref->array_index->as_constant())) return false; + /* No constant folding can be performed on variable dereferences. We need + * to explicitly avoid them, as calling constant_expression_value() on a + * variable dereference will return a clone of var->constant_value. This + * would make us propagate the value into the tree, which isn't our job. + */ + ir_dereference_variable *var_ref = (*rvalue)->as_dereference_variable(); + if (var_ref) + return false; + ir_constant *constant = (*rvalue)->constant_expression_value(); if (constant) { *rvalue = constant;