• Timothy Arceri's avatar
    nir: evaluate loop terminator ior use when false · a610ba21
    Timothy Arceri authored
    This allows some loops to unroll were they are guaranteed to
    exit after the first iteration. For example:
    
    	loop {
    		block block_1:
    		/* preds: block_0 block_13 */
    		vec1 32 ssa_85 = load_const (0x00000002 /* 0.000000 */)
    		vec1 32 ssa_86 = ieq ssa_48, ssa_85
    		vec1 32 ssa_87 = load_const (0x00000001 /* 0.000000 */)
    		vec1 32 ssa_88 = ieq ssa_48, ssa_87
    		vec1 32 ssa_89 = ior ssa_86, ssa_88
    		vec1 32 ssa_90 = ieq ssa_48, ssa_0
    		vec1 32 ssa_91 = ior ssa_89, ssa_90
    
    		/* succs: block_2 block_3 */
    		if ssa_86 {
    			block block_2:
    			/* preds: block_1 */
    			 ...
    			break
    			/* succs: block_14 */
    		} else {
    			block block_3:
    			/* preds: block_1 */
    			/* succs: block_4 */
    		}
    		block block_4:
    		/* preds: block_3 */
    		/* succs: block_5 block_6 */
    		if ssa_88 {
    			block block_5:
    			/* preds: block_4 */
    			 ...
    			break
    			/* succs: block_14 */
    		} else {
    			block block_6:
    			/* preds: block_4 */
    			/* succs: block_7 */
    		}
    		block block_7:
    		/* preds: block_6 */
    		/* succs: block_8 block_9 */
    		if ssa_90 {
    			block block_8:
    			/* preds: block_7 */
    			 ...
    			break
    			/* succs: block_14 */
    		} else {
    			block block_9:
    			/* preds: block_7 */
    			/* succs: block_10 */
    		}
    		block block_10:
    		/* preds: block_9 */
    		vec1 32 ssa_107 = inot ssa_91
    		/* succs: block_11 block_12 */
    		if ssa_107 {
    			block block_11:
    			/* preds: block_10 */
    			break
    			/* succs: block_14 */
    		} else {
    			block block_12:
    			/* preds: block_10 */
    			/* succs: block_13 */
    		}
    	}
    
    These loops have been seen in Bethesda games running over
    DXVK. There is a slight increase in VGPR use but removing
    the loops allows us to further optimise the code in
    future. For example many of the unrolled if-statements
    could now be merged as they apear in the shaders multiple
    times.
    
    vkpipeline results RADV (from a db of only 3 games):
    
    Totals from affected shaders:
    SGPRS: 10920 -> 10440 (-4.40 %)
    VGPRS: 6120 -> 6264 (2.35 %)
    Spilled SGPRs: 0 -> 0 (0.00 %)
    Spilled VGPRs: 0 -> 0 (0.00 %)
    Private memory VGPRs: 0 -> 0 (0.00 %)
    Scratch size: 0 -> 0 (0.00 %) dwords per thread
    Code Size: 369952 -> 356608 (-3.61 %) bytes
    LDS: 0 -> 0 (0.00 %) blocks
    Max Waves: 2040 -> 2040 (0.00 %)
    Wait states: 0 -> 0 (0.00 %)
    a610ba21
Name
Last commit
Last update
bin Loading commit data...
build-support Loading commit data...
docs Loading commit data...
doxygen Loading commit data...
include Loading commit data...
m4 Loading commit data...
scons Loading commit data...
scripts Loading commit data...
src Loading commit data...
.dir-locals.el Loading commit data...
.editorconfig Loading commit data...
.gitattributes Loading commit data...
.gitignore Loading commit data...
.mailmap Loading commit data...
.travis.yml Loading commit data...
Android.common.mk Loading commit data...
Android.mk Loading commit data...
CleanSpec.mk Loading commit data...
Makefile.am Loading commit data...
README.rst Loading commit data...
REVIEWERS Loading commit data...
SConstruct Loading commit data...
VERSION Loading commit data...
appveyor.yml Loading commit data...
autogen.sh Loading commit data...
common.py Loading commit data...
configure.ac Loading commit data...
install-gallium-links.mk Loading commit data...
install-lib-links.mk Loading commit data...
meson.build Loading commit data...
meson_options.txt Loading commit data...