Skip to content

nir: CF optimizations involving break statements

Daniel Schürmann requested to merge daniel-schuermann/mesa:nir_loop_break into main

The first optimization just removes loops which contain one break and no continue. While ACO doesn't emit additional control flow instructions in this case, it can still greatly improve scheduling or help to unroll outer loops.

The second optimization is merging of break statements. This helps in some cases for the first optimization (if the loop ends in if() { ..break; } else { ..break; }) or just reduces the number of branches.

I also tried to do the same for continue statements, but it interferes heavily with some other optimizations. So, I first need to figure what's going on :)

PERCENTAGE DELTAS                Shaders    SGPRs      VGPRs      SpillSGPRs CodeSize   MaxWaves   Instrs     Cycles     VMEM       SMEM       VClause    SClause    Copies     Branches   PreSGPRs   PreVGPRs   
 assassins_creed_origins          2114          .          .          .       -0.00%        .       -0.00%     -0.00%        .          .          .          .       -0.01%     -0.03%        .          .       
 battlefront2                     4568          .          .          .          .          .          .          .          .          .          .          .          .          .          .          .       
 britannia                        469           .          .          .          .          .          .          .          .          .          .          .          .          .          .          .       
 dark_souls_1_remastered          4249          .          .          .          .          .          .          .          .          .          .          .          .          .          .          .       
 dark_souls_2_sotfs               6876          .          .          .          .          .          .          .          .          .          .          .          .          .          .          .       
 dark_souls_3                     8935          .          .          .       -0.00%        .       -0.00%     -1.59%     -0.00%        .          .          .       -0.02%     -0.19%        .          .       
 death_stranding                  1467       -0.02%        .       -7.25%     -0.02%        .       -0.03%     -0.07%        .       -0.00%        .       +0.00%     -0.00%     -0.17%     -0.03%        .       
 detroit_become_human             19959      -1.73%     +0.10%     -49.21%    -0.28%     +0.06%     -0.36%     -81.65%    -0.16%     +5.77%     +3.14%     -1.03%     -7.46%     -6.73%     -1.88%     -0.12%     
 deus_ex_md                       8063          .          .          .          .          .          .          .          .          .          .          .          .          .          .          .       
 dirt4                            4078          .          .          .          .          .          .          .          .          .          .          .          .          .          .          .       
 doom_2016                        2963          .          .          .          .          .          .          .          .          .          .          .          .          .          .          .       
 doom_eternal                     1211          .          .          .          .          .          .          .          .          .          .          .          .          .          .          .       
 dota2                            1015       +0.20%     +0.04%        .       +0.02%     -0.02%     +0.02%     -1.18%     +0.92%     -0.06%     +0.10%     -0.03%     -0.09%     -5.82%     +0.03%     +0.01%     
 dow3                             282           .          .          .          .          .          .          .          .          .          .          .          .          .          .          .       
 evilwithin_demo                  742           .          .          .          .          .          .          .          .          .          .          .          .          .          .          .       
 f12017                           5503          .          .          .          .          .          .          .          .          .          .          .          .          .          .          .       
 gtav                             2991          .          .          .          .          .          .          .          .          .          .          .          .          .          .          .       
 hitman                           2785          .          .          .          .          .          .          .          .          .          .          .          .          .          .          .       
 madmax                           948           .          .          .          .          .          .          .          .          .          .          .          .          .          .          .       
 nier                             5492          .          .          .          .          .          .          .          .          .          .          .          .          .          .          .       
 parallel-rdp/small_subgroup      246           .          .          .          .          .          .          .          .          .          .          .          .          .          .          .       
 parallel-rdp/small_uber_subgroup 55            .          .          .          .          .          .          .          .          .          .          .          .          .          .          .       
 parallel-rdp/subgroup            327           .          .          .          .          .          .          .          .          .          .          .          .          .          .          .       
 parallel-rdp/uber_subgroup       55            .          .          .          .          .          .          .          .          .          .          .          .          .          .          .       
 rdr2                             3888       +0.10%     -0.06%     +0.60%     -0.26%     +0.00%     -0.34%     -45.50%    -0.24%     +0.04%     -0.04%     -0.03%     -1.24%     -3.70%     -0.15%     -0.06%     
 redout                           2520          .          .          .          .          .          .          .          .          .          .          .          .          .          .          .       
 rottr                            8130          .          .          .          .          .          .          .          .          .          .          .          .          .          .          .       
 sottr_demo                       5711          .          .          .          .          .          .          .          .          .          .          .          .          .          .          .       
 strange_brigade                  1417          .          .          .          .          .          .          .          .          .          .          .          .          .          .          .       
 talos                            794           .          .          .          .          .          .          .          .          .          .          .          .          .          .          .       
 thewitness                       3151          .          .          .          .          .          .          .          .          .          .          .          .          .          .          .       
 threekingdoms                    847           .          .          .          .          .          .          .          .          .          .          .          .          .          .          .       
 tomb_raider                      16232         .          .          .          .          .          .          .          .          .          .          .          .          .          .          .       
 warhammer2                       1803          .          .          .          .          .          .          .          .          .          .          .          .          .          .          .       
 wolfenstein2_fp16                1012          .          .          .          .          .          .          .          .          .          .          .          .          .          .          .       
 worldofwarships                  5590          .          .          .          .          .          .          .          .          .          .          .          .          .          .          .       
 youngblood                       843           .          .          .          .          .          .          .          .          .          .          .          .          .          .          .       
 youngblood_fp16                  682           .          .          .          .          .          .          .          .          .          .          .          .          .          .          .       
 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 All affected                     6914       -3.06%     +0.13%     -49.14%    -0.35%     +0.40%     -0.44%     -82.18%    -1.03%     +13.53%    +3.41%     -1.25%     -7.94%     -6.82%     -2.75%     -0.18%     
 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Total                            138013     -0.33%     +0.01%     -45.37%    -0.09%     +0.01%     -0.11%     -67.53%    -0.02%     +0.66%     +0.66%     -0.25%     -2.54%     -3.67%     -0.47%     -0.02%     
Edited by Daniel Schürmann

Merge request reports