[BUG] Compiler issues internal error: "IF statement nested too deeply"

Bug report and files:

https://github.com/mc-imperial/shader-compiler-bugs/issues/16

Fragment shader: the associated fragment shader is large, so I won’t paste it, but it can be found here:

https://github.com/mc-imperial/shader-compiler-bugs/blob/master/NVIDIA-770-Windows10/compile_fail/large-v440-4076f33cb4383b7e_inv_variant_1/shader.frag

This is accepted by glslangValidator and by a recent Intel driver, but the NVIDIA compiler gives an internal error, a snippet of which is:

Internal error: assembly compile error for fragment shader at offset 5906:
-- error message --
line 309, column 7:  error: IF statement nested too deeply.
line 347, column 6:  error: ENDIF without matching IF.
-- internal assembly text --
!!NVfp5.0
OPTION NV_bindless_texture;
# cgc version 3.4.0001, build date Oct  1 2016
# command line args:
#vendor NVIDIA Corporation
#version 3.4.0.1 COP Build Date Oct  1 2016
#profile gp5fp
#program main
#semantic injectionSwitch
#var float2 injectionSwitch :  : c[0] : -1 : 1
PARAM c[1] = { program.local[0] };
TEMP R0;
TEMP RC, HC;
SGT.F R0.y, c[0].x, {1, 0, 0, 0}.x;
TRUNC.U.CC HC.x, R0.y;
MOV.U R0.x, {1, 0, 0, 0};
IF    NE.x;
MOV.U R0.x, {0, 0, 0, 0};
ENDIF;
MOV.U.CC RC.x, R0;
IF    NE.x;
SGT.F R0.y, {1, 0, 0, 0}.x, c[0];
TRUNC.U.CC HC.x, R0.y;
IF    NE.x;
SGT.F R0.y, c[0].x, {1, 0, 0, 0}.x;
TRUNC.U.CC HC.x, R0.y;
IF    NE.x;
MOV.U R0.x, {0, 0, 0, 0};
...

It’s a very large shader and I doubt anyone would write a shader with so many conditionals in practice, so perhaps it’s OK for the compiler to reject this. But the error message is an internal error, with lots of low-level code output; it would be more graceful to complain about nesting depth at the source level.

In fact, although there are a lot of conditionals, the nesting is not deep.

  1. Operating system version.

Windows 10

  1. Graphics hardware.

GeForce GTX 770. Driver: 373.06

  1. Reproducer project.
    We have provided the fragment shader at the above link.

  2. Description of single steps to reproduce the problem.
    Compile and link the fragment shader.

  3. Description of the expected result.
    No link error.