Bug 107090

Summary: nir: problem case for loop unrolling
Product: Mesa Reporter: Caio Marcelo de Oliveira Filho <caio.oliveira>
Component: Mesa coreAssignee: mesa-dev
Status: RESOLVED FIXED QA Contact: mesa-dev
Severity: normal    
Priority: medium    
Version: git   
Hardware: Other   
OS: All   
Whiteboard:
i915 platform: i915 features:
Attachments: Failing test case

Description Caio Marcelo de Oliveira Filho 2018-07-02 17:44:22 UTC
Created attachment 140437 [details]
Failing test case

The following

  int i = 0;
  do {
      if (i == 1) {
	colour.g = 1.0;
	break;
      }
      i++;
  } while (i < 2);

doesn't get unrolled properly and the green value is never written. If "i++" is moved before the "if (...)" block, then things work.

This is a reduction for a problem reported last week by Karol Herbst. It is also the root cause for Piglit test tests/spec/glsl-1.10/execution/vs-loop-simple-unroll-induction-variable-inside-if-branch.shader_test to fail.

Attached is a failing test case. From looking last week it seems there's something missing in the logic for counting the number of iterations (hence picking the right terminator for a loop).
Comment 1 Timothy Arceri 2018-07-03 00:38:03 UTC
Was this fixed by the following commit?

author	Timothy Arceri <tarceri@itsqueeze.com>
commit	463f849097193ad20e7622ddd740fd15b96f4277

nir: fix selection of loop terminator when two or more have the same limit
We need to add loop terminators to the list in the order we come
across them otherwise if two or more have the same exit condition
we will select that last one rather than the first one even though
its unreachable.

This fix is for simple unrolls where we only have a single exit
point. When unrolling these type of loops the unreachable
terminators and their unreachable branch are removed prior to
unrolling. Because of the logic change we also switch some
list access in the complex unrolling logic to avoid breakage.

Fixes: 6772a17acc8e ("nir: Add a loop analysis pass")

Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Comment 2 Caio Marcelo de Oliveira Filho 2018-07-03 19:56:05 UTC
(In reply to Timothy Arceri from comment #1)
> Was this fixed by the following commit?
> 
> author	Timothy Arceri <tarceri@itsqueeze.com>
> commit	463f849097193ad20e7622ddd740fd15b96f4277
> 
> nir: fix selection of loop terminator when two or more have the same limit

Yes. Thanks!

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.