<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Mar 29, 2016 at 2:50 PM, Ian Romanick <span dir="ltr"><<a href="mailto:idr@freedesktop.org" target="_blank">idr@freedesktop.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Does this fix any test cases?  Either way, this series is<br></blockquote><div><br></div><div>No know test cases.  It does mean that we now correctly implement the semantics required for SPIR-V<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Reviewed-by: Ian Romanick <<a href="mailto:ian.d.romanick@intel.com">ian.d.romanick@intel.com</a>><br>
<div class="HOEnZb"><div class="h5"><br>
On 03/28/2016 04:54 PM, Jason Ekstrand wrote:<br>
> In the first pass of implementing exact handling, I made a mistake with<br>
> search-and-replace.  In particular, we only reallly handled exact/inexact<br>
> on the root of the tree.  Instead, we need to check every node in the tree<br>
> for an exact/inexact match.  As an example of this, consider the following<br>
> GLSL code<br>
><br>
> precise float a = b + c;<br>
> if (a < 0) {<br>
>    do_stuff();<br>
> }<br>
><br>
> In that case, only the add will be declared "exact" and an expression that<br>
> looks for "b + c < 0" will still match and replace it with "b < -c" which<br>
> may yield different results.  The solution is to simply bail if any of the<br>
> values are exact when matching an inexact expression.<br>
> ---<br>
>  src/compiler/nir/nir_search.c | 23 ++++++++++++++++++-----<br>
>  1 file changed, 18 insertions(+), 5 deletions(-)<br>
><br>
> diff --git a/src/compiler/nir/nir_search.c b/src/compiler/nir/nir_search.c<br>
> index 6e63063..b915101 100644<br>
> --- a/src/compiler/nir/nir_search.c<br>
> +++ b/src/compiler/nir/nir_search.c<br>
> @@ -28,6 +28,8 @@<br>
>  #include "nir_search.h"<br>
><br>
>  struct match_state {<br>
> +   bool inexact_match;<br>
> +   bool has_exact_alu;<br>
>     unsigned variables_seen;<br>
>     nir_alu_src variables[NIR_SEARCH_MAX_VARIABLES];<br>
>  };<br>
> @@ -239,7 +241,10 @@ match_expression(const nir_search_expression *expr, nir_alu_instr *instr,<br>
>        return false;<br>
><br>
>     assert(instr->dest.dest.is_ssa);<br>
> -   if (expr->inexact && instr->exact)<br>
> +<br>
> +   state->inexact_match = expr->inexact || state->inexact_match;<br>
> +   state->has_exact_alu = instr->exact || state->has_exact_alu;<br>
> +   if (state->inexact_match && state->has_exact_alu)<br>
>        return false;<br>
><br>
>     assert(!instr->dest.saturate);<br>
> @@ -410,7 +415,7 @@ bitsize_tree_filter_down(bitsize_tree *tree, unsigned size)<br>
><br>
>  static nir_alu_src<br>
>  construct_value(const nir_search_value *value,<br>
> -                unsigned num_components, bitsize_tree *bitsize, bool exact,<br>
> +                unsigned num_components, bitsize_tree *bitsize,<br>
>                  struct match_state *state,<br>
>                  nir_instr *instr, void *mem_ctx)<br>
>  {<br>
> @@ -424,10 +429,16 @@ construct_value(const nir_search_value *value,<br>
>        nir_alu_instr *alu = nir_alu_instr_create(mem_ctx, expr->opcode);<br>
>        nir_ssa_dest_init(&alu->instr, &alu->dest.dest, num_components,<br>
>                          bitsize->dest_size, NULL);<br>
> -      alu->exact = exact;<br>
>        alu->dest.write_mask = (1 << num_components) - 1;<br>
>        alu->dest.saturate = false;<br>
><br>
> +      /* We have no way of knowing what values in a given search expression<br>
> +       * map to a particular replacement value.  Therefore, if the<br>
> +       * expression we are replacing has any exact values, the entire<br>
> +       * replacement should be exact.<br>
> +       */<br>
> +      alu->exact = state->has_exact_alu;<br>
> +<br>
>        for (unsigned i = 0; i < nir_op_infos[expr->opcode].num_inputs; i++) {<br>
>           /* If the source is an explicitly sized source, then we need to reset<br>
>            * the number of components to match.<br>
> @@ -436,7 +447,7 @@ construct_value(const nir_search_value *value,<br>
>              num_components = nir_op_infos[alu->op].input_sizes[i];<br>
><br>
>           alu->src[i] = construct_value(expr->srcs[i],<br>
> -                                       num_components, bitsize->srcs[i], exact,<br>
> +                                       num_components, bitsize->srcs[i],<br>
>                                         state, instr, mem_ctx);<br>
>        }<br>
><br>
> @@ -546,6 +557,8 @@ nir_replace_instr(nir_alu_instr *instr, const nir_search_expression *search,<br>
>     assert(instr->dest.dest.is_ssa);<br>
><br>
>     struct match_state state;<br>
> +   state.inexact_match = false;<br>
> +   state.has_exact_alu = false;<br>
>     state.variables_seen = 0;<br>
><br>
>     if (!match_expression(search, instr, instr->dest.dest.ssa.num_components,<br>
> @@ -569,7 +582,7 @@ nir_replace_instr(nir_alu_instr *instr, const nir_search_expression *search,<br>
><br>
>     mov->src[0] = construct_value(replace,<br>
>                                   instr->dest.dest.ssa.num_components, tree,<br>
> -                                 instr->exact, &state, &instr->instr, mem_ctx);<br>
> +                                 &state, &instr->instr, mem_ctx);<br>
>     nir_instr_insert_before(&instr->instr, &mov->instr);<br>
><br>
>     nir_ssa_def_rewrite_uses(&instr->dest.dest.ssa,<br>
><br>
<br>
</div></div></blockquote></div><br></div></div>