<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jul 13, 2016, at 12:36, Marek Olšák <<a href="mailto:maraeo@gmail.com" class="">maraeo@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">On Wed, Jul 13, 2016 at 9:25 PM, Tom Stellard <</span><a href="mailto:tom@stellard.net" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">tom@stellard.net</a><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">> wrote:</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">On Wed, Jul 13, 2016 at 03:20:55PM -0400, Tom Stellard wrote:<br class=""><blockquote type="cite" class="">On Tue, Jul 12, 2016 at 10:52:35PM +0200, Marek Olšák wrote:<br class=""><blockquote type="cite" class="">From: Marek Olšák <<a href="mailto:marek.olsak@amd.com" class="">marek.olsak@amd.com</a>><br class=""><br class="">This allows moving the loads arbitrarily in the Sinking pass.<br class=""><br class="">26002 shaders in 14643 tests<br class="">Totals:<br class="">SGPRS: 2080160 -> 2080160 (0.00 %)<br class="">VGPRS: 798875 -> 797826 (-0.13 %)<br class="">Spilled SGPRs: 108485 -> 79165 (-27.03 %)<br class="">Spilled VGPRs: 327 -> 327 (0.00 %)<br class="">Scratch VGPRs: 1656 -> 1652 (-0.24 %) dwords per thread<br class="">Code Size: 36127192 -> 35559780 (-1.57 %) bytes<br class="">LDS: 767 -> 767 (0.00 %) blocks<br class="">Max Waves: 212464 -> 212672 (0.10 %)<br class="">Wait states: 0 -> 0 (0.00 %)<br class=""><br class="">PERCENTAGES / App Shaders SGPRs VGPRs SpillSGPR SpillVGPR Scratch CodeSize MaxWaves Waits<br class="">(unknown) 4 . . . . . . . .<br class="">0ad 6 . . . . . . . .<br class="">alien_isolation 2938 . 0.04 % -8.53 % . . -0.71 % -0.06 % .<br class="">anholt 10 . . . . . . . .<br class="">batman_arkham_origins 589 . -0.58 % -79.54 % . . -6.72 % 0.57 % .<br class="">bioshock-infinite 1769 . -0.65 % -89.32 % . . -4.73 % 0.48 % .<br class="">borderlands2 3968 . -0.31 % -51.21 % . . -4.09 % 0.22 % .<br class="">brutal-legend 338 . -0.03 % -2.95 % . . -0.06 % . .<br class="">civilization_beyond.. 116 . . -14.17 % . . -0.88 % . .<br class="">counter_strike_glob.. 1142 . . . . . . . .<br class="">dirt-showdown 541 . -0.56 % -40.14 % . -3.45 % -1.82 % 0.35 % .<br class="">dolphin 22 . . . . . 0.16 % . .<br class="">dota2 1747 . . . . . 0.01 % . .<br class="">europa_universalis_4 76 . -0.23 % -42.11 % . . -0.96 % . .<br class="">f1-2015 774 . -0.09 % -28.89 % . . -2.60 % 0.09 % .<br class="">furmark-0.7.0 4 . . . . . . . .<br class="">gimark-0.7.0 10 . . . . . . . .<br class="">glamor 16 . . . . . . . .<br class="">humus-celshading 4 . . . . . . . .<br class="">humus-domino 6 . . . . . . . .<br class="">humus-dynamicbranching 24 . 0.71 % . . . 0.29 % -0.45 % .<br class="">humus-hdr 10 . . . . . . . .<br class="">humus-portals 2 . . . . . . . .<br class="">humus-volumetricfog.. 6 . . . . . . . .<br class="">left_4_dead_2 1762 . . . . . . . .<br class="">metro_2033_redux 2670 . -0.10 % -7.15 % . . -0.03 % . .<br class="">nexuiz 80 . . . . . . . .<br class="">pixmark-julia-fp32 2 . . . . . . . .<br class="">pixmark-julia-fp64 2 . . . . . . . .<br class="">pixmark-piano-0.7.0 2 . . . . . . . .<br class="">pixmark-volplosion-.. 2 . . . . . . . .<br class="">plot3d-0.7.0 8 . . . . . . . .<br class="">portal 474 . . . . . . . .<br class="">sauerbraten 7 . . . . . . . .<br class="">serious_sam_3_bfe 392 . . -13.20 % . . -1.81 % . .<br class="">supertuxkart 4 . . . . . . . .<br class="">talos_principle 324 . -0.21 % -18.39 % . . -2.73 % 0.14 % .<br class="">team_fortress_2 808 . . . . . . . .<br class="">tesseract 430 . 0.08 % -68.57 % . . -0.45 % . .<br class="">tessmark-0.7.0 6 . . . . . . . .<br class="">thea 172 . . . . . 0.03 % . .<br class="">ue4_effects_cave 299 . -0.04 % -10.15 % . . -0.25 % 0.04 % .<br class="">ue4_elemental 586 . -0.02 % -13.93 % . . -0.13 % 0.02 % .<br class="">ue4_lightroom_inter.. 74 . -0.17 % -70.00 % . . -1.27 % . .<br class="">ue4_realistic_rende.. 92 . . -32.58 % . . -0.35 % . .<br class="">unigine_heaven 322 . 0.12 % -54.17 % . . -1.42 % -0.12 % .<br class="">unigine_sanctuary 264 . . . . . . . .<br class="">unigine_tropics 210 . . . . . . . .<br class="">unigine_valley 278 . -0.15 % -40.74 % . . -2.00 % 0.09 % .<br class="">unity 72 . . . . . 0.03 % . .<br class="">warsow 176 . . . . . . . .<br class="">warzone2100 4 . . . . . 0.13 % . .<br class="">witcher2 1040 . -0.03 % -86.28 % . . -0.28 % 0.01 % .<br class="">xcom_enemy_within 1236 . -0.24 % -63.54 % . . -0.93 % 0.18 % .<br class="">yofrankie 82 . -0.61 % -100.00 % . . -0.83 % 0.41 % .<br class="">-----------------------------------------------------------------------------------------------------------<br class="">Total 26002 . -0.13 % -27.03 % . -0.24 % -1.57 % 0.10 % .<br class="">---<br class="">src/gallium/drivers/radeonsi/si_shader.c | 15 +++++++++++----<br class="">1 file changed, 11 insertions(+), 4 deletions(-)<br class=""><br class="">diff --git a/src/gallium/drivers/radeonsi/si_shader.c b/src/gallium/drivers/radeonsi/si_shader.c<br class="">index 31140b1..b23c7c6 100644<br class="">--- a/src/gallium/drivers/radeonsi/si_shader.c<br class="">+++ b/src/gallium/drivers/radeonsi/si_shader.c<br class="">@@ -33,6 +33,7 @@<br class="">#include "gallivm/lp_bld_arit.h"<br class="">#include "gallivm/lp_bld_bitarit.h"<br class="">#include "gallivm/lp_bld_flow.h"<br class="">+#include "gallivm/lp_bld_misc.h"<br class="">#include "radeon/r600_cs.h"<br class="">#include "radeon/radeon_llvm.h"<br class="">#include "radeon/radeon_elf_util.h"<br class="">@@ -5311,11 +5312,17 @@ static void si_create_function(struct si_shader_context *ctx,<br class=""> for (i = 0; i <= last_sgpr; ++i) {<br class=""> LLVMValueRef P = LLVMGetParam(ctx->radeon_bld.main_fn, i);<br class=""><br class="">- /* We tell llvm that array inputs are passed by value to allow Sinking pass<br class="">- * to move load. Inputs are constant so this is fine. */<br class="">- if (i <= last_array_pointer)<br class="">+ /* The combination of:<br class="">+ * - ByVal<br class="">+ * - dereferenceable<br class="">+ * - tbaa<br class="">+ * allows the optimization passes to move loads and reduces<br class="">+ * SGPR spilling significantly.<br class="">+ */<br class="">+ if (i <= last_array_pointer) {<br class=""> LLVMAddAttribute(P, LLVMByValAttribute);<br class="">- else<br class="">+ lp_add_attr_dereferenceable(P, UINT64_MAX);<br class=""></blockquote><br class="">I'm not sure if anything bad will happen passing UINT64_MAX here, but<br class="">is there any way we can get the buffer size here, so we can<br class="">pass a more accurate value?<br class=""><br class=""></blockquote><br class="">Actually, these are all array pointers, so we should be able to get the<br class="">size pretty easily.<br class=""></blockquote><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Matt on IRC suggested -1 (the unsigned maximum). I don't know if</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">indirect indexing will fail the isDereferenceable test with the real</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">size. Is there a reason to use the real size other than "so it doesn't</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">look silly in the printed IR"? In my opinion, we should set</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">dereferenceable(UINT64_MAX) on all pointers, because the GPU doesn't</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">terminate the program on bad pointer dereference like CPUs do.</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Marek</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""></div></blockquote><br class=""></div><div>-1 is usually used in places that need an unknown size, e.g. lifetime intrinsics</div><br class=""></body></html>