[llvm-bugs] [Bug 43785] New: Code sinking pessimizes common GPU code patterns

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Oct 24 06:43:11 PDT 2019


https://bugs.llvm.org/show_bug.cgi?id=43785

            Bug ID: 43785
           Summary: Code sinking pessimizes common GPU code patterns
           Product: new-bugs
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: cwabbott0 at gmail.com
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org

In GPU shaders used by games, it's pretty common to average a bunch of texture
samples in a loop in the fragment shader, e.g. for blurring an image:

vec4 sample = vec4(0);
for (int i = 0; i < NUM_SAMPLES; i++)
    sample += texture(...);

...
... = sample;

The problem happens after we unroll this loop, especially when doing very
aggressive unrolling (as is usually beneficial on GPU's) and NUM_SAMPLES is
very large (say, 8 to 16). If there's any intervening control flow, then LLVM's
code sinking pass will try to pull the entire unrolled loop downwards, but
since texture() is convergent, it can't, so it leaves just the texture
operations:

sample1 = texture(...);
sample2 = texture(...);
...
sampleN = texture(...);
...
... = sample1 + sample2 + ... + sampleN;

And now all of the samples are live at the same time, which results in a huge
increase in register pressure. We noticed this when changing RadeonSI to use
NIR, since this resulted in a few shaders in Civilization: Beyond Earth
spilling after unrolling started happening before LLVM.

I'm not entirely sure what to do here. Code sinking can definitely be
beneficial in some cases for register pressure, and disabling it is largely a
wash. We could just disable it in LLVM for AMDGPU/Mesa and do something much
less aggressive in our stack, although this is a problem that likely affects
other non-Mesa GPU stacks using LLVM.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20191024/1c3ba61f/attachment.html>


More information about the llvm-bugs mailing list