local_ssa_elim_test.cpp 196 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470
  1. // Copyright (c) 2017 Valve Corporation
  2. // Copyright (c) 2017 LunarG Inc.
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. #include <memory>
  16. #include <string>
  17. #include "test/opt/pass_fixture.h"
  18. #include "test/opt/pass_utils.h"
  19. namespace spvtools {
  20. namespace opt {
  21. namespace {
  22. using LocalSSAElimTest = PassTest<::testing::Test>;
  23. TEST_F(LocalSSAElimTest, ForLoop) {
  24. // #version 140
  25. //
  26. // in vec4 BC;
  27. // out float fo;
  28. //
  29. // void main()
  30. // {
  31. // float f = 0.0;
  32. // for (int i=0; i<4; i++) {
  33. // f = f + BC[i];
  34. // }
  35. // fo = f;
  36. // }
  37. const std::string predefs =
  38. R"(OpCapability Shader
  39. %1 = OpExtInstImport "GLSL.std.450"
  40. OpMemoryModel Logical GLSL450
  41. OpEntryPoint Fragment %main "main" %BC %fo
  42. OpExecutionMode %main OriginUpperLeft
  43. OpSource GLSL 140
  44. OpName %main "main"
  45. OpName %f "f"
  46. OpName %i "i"
  47. OpName %BC "BC"
  48. OpName %fo "fo"
  49. %void = OpTypeVoid
  50. %8 = OpTypeFunction %void
  51. %float = OpTypeFloat 32
  52. %_ptr_Function_float = OpTypePointer Function %float
  53. %float_0 = OpConstant %float 0
  54. %int = OpTypeInt 32 1
  55. %_ptr_Function_int = OpTypePointer Function %int
  56. %int_0 = OpConstant %int 0
  57. %int_4 = OpConstant %int 4
  58. %bool = OpTypeBool
  59. %v4float = OpTypeVector %float 4
  60. %_ptr_Input_v4float = OpTypePointer Input %v4float
  61. %BC = OpVariable %_ptr_Input_v4float Input
  62. %_ptr_Input_float = OpTypePointer Input %float
  63. %int_1 = OpConstant %int 1
  64. %_ptr_Output_float = OpTypePointer Output %float
  65. %fo = OpVariable %_ptr_Output_float Output
  66. )";
  67. const std::string before =
  68. R"(%main = OpFunction %void None %8
  69. %22 = OpLabel
  70. %f = OpVariable %_ptr_Function_float Function
  71. %i = OpVariable %_ptr_Function_int Function
  72. OpStore %f %float_0
  73. OpStore %i %int_0
  74. OpBranch %23
  75. %23 = OpLabel
  76. OpLoopMerge %24 %25 None
  77. OpBranch %26
  78. %26 = OpLabel
  79. %27 = OpLoad %int %i
  80. %28 = OpSLessThan %bool %27 %int_4
  81. OpBranchConditional %28 %29 %24
  82. %29 = OpLabel
  83. %30 = OpLoad %float %f
  84. %31 = OpLoad %int %i
  85. %32 = OpAccessChain %_ptr_Input_float %BC %31
  86. %33 = OpLoad %float %32
  87. %34 = OpFAdd %float %30 %33
  88. OpStore %f %34
  89. OpBranch %25
  90. %25 = OpLabel
  91. %35 = OpLoad %int %i
  92. %36 = OpIAdd %int %35 %int_1
  93. OpStore %i %36
  94. OpBranch %23
  95. %24 = OpLabel
  96. %37 = OpLoad %float %f
  97. OpStore %fo %37
  98. OpReturn
  99. OpFunctionEnd
  100. )";
  101. const std::string after =
  102. R"(%main = OpFunction %void None %8
  103. %22 = OpLabel
  104. %f = OpVariable %_ptr_Function_float Function
  105. %i = OpVariable %_ptr_Function_int Function
  106. OpStore %f %float_0
  107. OpStore %i %int_0
  108. OpBranch %23
  109. %23 = OpLabel
  110. %39 = OpPhi %float %float_0 %22 %34 %25
  111. %38 = OpPhi %int %int_0 %22 %36 %25
  112. OpLoopMerge %24 %25 None
  113. OpBranch %26
  114. %26 = OpLabel
  115. %28 = OpSLessThan %bool %38 %int_4
  116. OpBranchConditional %28 %29 %24
  117. %29 = OpLabel
  118. %32 = OpAccessChain %_ptr_Input_float %BC %38
  119. %33 = OpLoad %float %32
  120. %34 = OpFAdd %float %39 %33
  121. OpStore %f %34
  122. OpBranch %25
  123. %25 = OpLabel
  124. %36 = OpIAdd %int %38 %int_1
  125. OpStore %i %36
  126. OpBranch %23
  127. %24 = OpLabel
  128. OpStore %fo %39
  129. OpReturn
  130. OpFunctionEnd
  131. )";
  132. SinglePassRunAndCheck<SSARewritePass>(predefs + before, predefs + after, true,
  133. true);
  134. }
  135. TEST_F(LocalSSAElimTest, NestedForLoop) {
  136. // #version 450
  137. //
  138. // layout (location=0) in mat4 BC;
  139. // layout (location=0) out float fo;
  140. //
  141. // void main()
  142. // {
  143. // float f = 0.0;
  144. // for (int i=0; i<4; i++)
  145. // for (int j=0; j<4; j++)
  146. // f = f + BC[i][j];
  147. // fo = f;
  148. // }
  149. const std::string predefs =
  150. R"(OpCapability Shader
  151. %1 = OpExtInstImport "GLSL.std.450"
  152. OpMemoryModel Logical GLSL450
  153. OpEntryPoint Fragment %main "main" %BC %fo
  154. OpExecutionMode %main OriginUpperLeft
  155. OpSource GLSL 450
  156. OpName %main "main"
  157. OpName %f "f"
  158. OpName %i "i"
  159. OpName %j "j"
  160. OpName %BC "BC"
  161. OpName %fo "fo"
  162. OpDecorate %BC Location 0
  163. OpDecorate %fo Location 0
  164. %void = OpTypeVoid
  165. %9 = OpTypeFunction %void
  166. %float = OpTypeFloat 32
  167. %_ptr_Function_float = OpTypePointer Function %float
  168. %float_0 = OpConstant %float 0
  169. %int = OpTypeInt 32 1
  170. %_ptr_Function_int = OpTypePointer Function %int
  171. %int_0 = OpConstant %int 0
  172. %int_4 = OpConstant %int 4
  173. %bool = OpTypeBool
  174. %v4float = OpTypeVector %float 4
  175. %mat4v4float = OpTypeMatrix %v4float 4
  176. %_ptr_Input_mat4v4float = OpTypePointer Input %mat4v4float
  177. %BC = OpVariable %_ptr_Input_mat4v4float Input
  178. %_ptr_Input_float = OpTypePointer Input %float
  179. %int_1 = OpConstant %int 1
  180. %_ptr_Output_float = OpTypePointer Output %float
  181. %fo = OpVariable %_ptr_Output_float Output
  182. )";
  183. const std::string before =
  184. R"(
  185. ; CHECK: = OpFunction
  186. ; CHECK-NEXT: [[entry:%\w+]] = OpLabel
  187. ; CHECK: [[outer_header:%\w+]] = OpLabel
  188. ; CHECK-NEXT: [[outer_f:%\w+]] = OpPhi %float %float_0 [[entry]] [[inner_f:%\w+]] [[outer_be:%\w+]]
  189. ; CHECK-NEXT: [[i:%\w+]] = OpPhi %int %int_0 [[entry]] [[i_next:%\w+]] [[outer_be]]
  190. ; CHECK-NEXT: OpSLessThan {{%\w+}} [[i]]
  191. ; CHECK: [[inner_pre_header:%\w+]] = OpLabel
  192. ; CHECK: [[inner_header:%\w+]] = OpLabel
  193. ; CHECK-NEXT: [[inner_f]] = OpPhi %float [[outer_f]] [[inner_pre_header]] [[f_next:%\w+]] [[inner_be:%\w+]]
  194. ; CHECK-NEXT: [[j:%\w+]] = OpPhi %int %int_0 [[inner_pre_header]] [[j_next:%\w+]] [[inner_be]]
  195. ; CHECK: [[inner_be]] = OpLabel
  196. ; CHECK: [[f_next]] = OpFAdd %float [[inner_f]]
  197. ; CHECK: [[j_next]] = OpIAdd %int [[j]] %int_1
  198. ; CHECK: [[outer_be]] = OpLabel
  199. ; CHECK: [[i_next]] = OpIAdd
  200. ; CHECK: OpStore %fo [[outer_f]]
  201. %main = OpFunction %void None %9
  202. %24 = OpLabel
  203. %f = OpVariable %_ptr_Function_float Function
  204. %i = OpVariable %_ptr_Function_int Function
  205. %j = OpVariable %_ptr_Function_int Function
  206. OpStore %f %float_0
  207. OpStore %i %int_0
  208. OpBranch %25
  209. %25 = OpLabel
  210. %26 = OpLoad %int %i
  211. %27 = OpSLessThan %bool %26 %int_4
  212. OpLoopMerge %28 %29 None
  213. OpBranchConditional %27 %30 %28
  214. %30 = OpLabel
  215. OpStore %j %int_0
  216. OpBranch %31
  217. %31 = OpLabel
  218. %32 = OpLoad %int %j
  219. %33 = OpSLessThan %bool %32 %int_4
  220. OpLoopMerge %50 %34 None
  221. OpBranchConditional %33 %34 %50
  222. %34 = OpLabel
  223. %35 = OpLoad %float %f
  224. %36 = OpLoad %int %i
  225. %37 = OpLoad %int %j
  226. %38 = OpAccessChain %_ptr_Input_float %BC %36 %37
  227. %39 = OpLoad %float %38
  228. %40 = OpFAdd %float %35 %39
  229. OpStore %f %40
  230. %41 = OpLoad %int %j
  231. %42 = OpIAdd %int %41 %int_1
  232. OpStore %j %42
  233. OpBranch %31
  234. %50 = OpLabel
  235. OpBranch %29
  236. %29 = OpLabel
  237. %43 = OpLoad %int %i
  238. %44 = OpIAdd %int %43 %int_1
  239. OpStore %i %44
  240. OpBranch %25
  241. %28 = OpLabel
  242. %45 = OpLoad %float %f
  243. OpStore %fo %45
  244. OpReturn
  245. OpFunctionEnd
  246. )";
  247. SinglePassRunAndMatch<SSARewritePass>(predefs + before, true);
  248. }
  249. TEST_F(LocalSSAElimTest, ForLoopWithContinue) {
  250. // #version 140
  251. //
  252. // in vec4 BC;
  253. // out float fo;
  254. //
  255. // void main()
  256. // {
  257. // float f = 0.0;
  258. // for (int i=0; i<4; i++) {
  259. // float t = BC[i];
  260. // if (t < 0.0)
  261. // continue;
  262. // f = f + t;
  263. // }
  264. // fo = f;
  265. // }
  266. const std::string predefs =
  267. R"(OpCapability Shader
  268. %1 = OpExtInstImport "GLSL.std.450"
  269. OpMemoryModel Logical GLSL450
  270. OpEntryPoint Fragment %main "main" %BC %fo
  271. OpExecutionMode %main OriginUpperLeft
  272. OpSource GLSL 140
  273. )";
  274. const std::string names =
  275. R"(OpName %main "main"
  276. OpName %f "f"
  277. OpName %i "i"
  278. OpName %t "t"
  279. OpName %BC "BC"
  280. OpName %fo "fo"
  281. )";
  282. const std::string predefs2 =
  283. R"(%void = OpTypeVoid
  284. %9 = OpTypeFunction %void
  285. %float = OpTypeFloat 32
  286. %_ptr_Function_float = OpTypePointer Function %float
  287. %float_0 = OpConstant %float 0
  288. %int = OpTypeInt 32 1
  289. %_ptr_Function_int = OpTypePointer Function %int
  290. %int_0 = OpConstant %int 0
  291. %int_4 = OpConstant %int 4
  292. %bool = OpTypeBool
  293. %v4float = OpTypeVector %float 4
  294. %_ptr_Input_v4float = OpTypePointer Input %v4float
  295. %BC = OpVariable %_ptr_Input_v4float Input
  296. %_ptr_Input_float = OpTypePointer Input %float
  297. %int_1 = OpConstant %int 1
  298. %_ptr_Output_float = OpTypePointer Output %float
  299. %fo = OpVariable %_ptr_Output_float Output
  300. )";
  301. const std::string before =
  302. R"(%main = OpFunction %void None %9
  303. %23 = OpLabel
  304. %f = OpVariable %_ptr_Function_float Function
  305. %i = OpVariable %_ptr_Function_int Function
  306. %t = OpVariable %_ptr_Function_float Function
  307. OpStore %f %float_0
  308. OpStore %i %int_0
  309. OpBranch %24
  310. %24 = OpLabel
  311. OpLoopMerge %25 %26 None
  312. OpBranch %27
  313. %27 = OpLabel
  314. %28 = OpLoad %int %i
  315. %29 = OpSLessThan %bool %28 %int_4
  316. OpBranchConditional %29 %30 %25
  317. %30 = OpLabel
  318. %31 = OpLoad %int %i
  319. %32 = OpAccessChain %_ptr_Input_float %BC %31
  320. %33 = OpLoad %float %32
  321. OpStore %t %33
  322. %34 = OpLoad %float %t
  323. %35 = OpFOrdLessThan %bool %34 %float_0
  324. OpSelectionMerge %36 None
  325. OpBranchConditional %35 %37 %36
  326. %37 = OpLabel
  327. OpBranch %26
  328. %36 = OpLabel
  329. %38 = OpLoad %float %f
  330. %39 = OpLoad %float %t
  331. %40 = OpFAdd %float %38 %39
  332. OpStore %f %40
  333. OpBranch %26
  334. %26 = OpLabel
  335. %41 = OpLoad %int %i
  336. %42 = OpIAdd %int %41 %int_1
  337. OpStore %i %42
  338. OpBranch %24
  339. %25 = OpLabel
  340. %43 = OpLoad %float %f
  341. OpStore %fo %43
  342. OpReturn
  343. OpFunctionEnd
  344. )";
  345. const std::string after =
  346. R"(%main = OpFunction %void None %9
  347. %23 = OpLabel
  348. %f = OpVariable %_ptr_Function_float Function
  349. %i = OpVariable %_ptr_Function_int Function
  350. %t = OpVariable %_ptr_Function_float Function
  351. OpStore %f %float_0
  352. OpStore %i %int_0
  353. OpBranch %24
  354. %24 = OpLabel
  355. %45 = OpPhi %float %float_0 %23 %47 %26
  356. %44 = OpPhi %int %int_0 %23 %42 %26
  357. OpLoopMerge %25 %26 None
  358. OpBranch %27
  359. %27 = OpLabel
  360. %29 = OpSLessThan %bool %44 %int_4
  361. OpBranchConditional %29 %30 %25
  362. %30 = OpLabel
  363. %32 = OpAccessChain %_ptr_Input_float %BC %44
  364. %33 = OpLoad %float %32
  365. OpStore %t %33
  366. %35 = OpFOrdLessThan %bool %33 %float_0
  367. OpSelectionMerge %36 None
  368. OpBranchConditional %35 %37 %36
  369. %37 = OpLabel
  370. OpBranch %26
  371. %36 = OpLabel
  372. %40 = OpFAdd %float %45 %33
  373. OpStore %f %40
  374. OpBranch %26
  375. %26 = OpLabel
  376. %47 = OpPhi %float %45 %37 %40 %36
  377. %42 = OpIAdd %int %44 %int_1
  378. OpStore %i %42
  379. OpBranch %24
  380. %25 = OpLabel
  381. OpStore %fo %45
  382. OpReturn
  383. OpFunctionEnd
  384. )";
  385. SinglePassRunAndCheck<SSARewritePass>(predefs + names + predefs2 + before,
  386. predefs + names + predefs2 + after,
  387. true, true);
  388. }
  389. TEST_F(LocalSSAElimTest, ForLoopWithBreak) {
  390. // #version 140
  391. //
  392. // in vec4 BC;
  393. // out float fo;
  394. //
  395. // void main()
  396. // {
  397. // float f = 0.0;
  398. // for (int i=0; i<4; i++) {
  399. // float t = f + BC[i];
  400. // if (t > 1.0)
  401. // break;
  402. // f = t;
  403. // }
  404. // fo = f;
  405. // }
  406. const std::string predefs =
  407. R"(OpCapability Shader
  408. %1 = OpExtInstImport "GLSL.std.450"
  409. OpMemoryModel Logical GLSL450
  410. OpEntryPoint Fragment %main "main" %BC %fo
  411. OpExecutionMode %main OriginUpperLeft
  412. OpSource GLSL 140
  413. OpName %main "main"
  414. OpName %f "f"
  415. OpName %i "i"
  416. OpName %t "t"
  417. OpName %BC "BC"
  418. OpName %fo "fo"
  419. %void = OpTypeVoid
  420. %9 = OpTypeFunction %void
  421. %float = OpTypeFloat 32
  422. %_ptr_Function_float = OpTypePointer Function %float
  423. %float_0 = OpConstant %float 0
  424. %int = OpTypeInt 32 1
  425. %_ptr_Function_int = OpTypePointer Function %int
  426. %int_0 = OpConstant %int 0
  427. %int_4 = OpConstant %int 4
  428. %bool = OpTypeBool
  429. %v4float = OpTypeVector %float 4
  430. %_ptr_Input_v4float = OpTypePointer Input %v4float
  431. %BC = OpVariable %_ptr_Input_v4float Input
  432. %_ptr_Input_float = OpTypePointer Input %float
  433. %float_1 = OpConstant %float 1
  434. %int_1 = OpConstant %int 1
  435. %_ptr_Output_float = OpTypePointer Output %float
  436. %fo = OpVariable %_ptr_Output_float Output
  437. )";
  438. const std::string before =
  439. R"(%main = OpFunction %void None %9
  440. %24 = OpLabel
  441. %f = OpVariable %_ptr_Function_float Function
  442. %i = OpVariable %_ptr_Function_int Function
  443. %t = OpVariable %_ptr_Function_float Function
  444. OpStore %f %float_0
  445. OpStore %i %int_0
  446. OpBranch %25
  447. %25 = OpLabel
  448. OpLoopMerge %26 %27 None
  449. OpBranch %28
  450. %28 = OpLabel
  451. %29 = OpLoad %int %i
  452. %30 = OpSLessThan %bool %29 %int_4
  453. OpBranchConditional %30 %31 %26
  454. %31 = OpLabel
  455. %32 = OpLoad %float %f
  456. %33 = OpLoad %int %i
  457. %34 = OpAccessChain %_ptr_Input_float %BC %33
  458. %35 = OpLoad %float %34
  459. %36 = OpFAdd %float %32 %35
  460. OpStore %t %36
  461. %37 = OpLoad %float %t
  462. %38 = OpFOrdGreaterThan %bool %37 %float_1
  463. OpSelectionMerge %39 None
  464. OpBranchConditional %38 %40 %39
  465. %40 = OpLabel
  466. OpBranch %26
  467. %39 = OpLabel
  468. %41 = OpLoad %float %t
  469. OpStore %f %41
  470. OpBranch %27
  471. %27 = OpLabel
  472. %42 = OpLoad %int %i
  473. %43 = OpIAdd %int %42 %int_1
  474. OpStore %i %43
  475. OpBranch %25
  476. %26 = OpLabel
  477. %44 = OpLoad %float %f
  478. OpStore %fo %44
  479. OpReturn
  480. OpFunctionEnd
  481. )";
  482. const std::string after =
  483. R"(%main = OpFunction %void None %9
  484. %24 = OpLabel
  485. %f = OpVariable %_ptr_Function_float Function
  486. %i = OpVariable %_ptr_Function_int Function
  487. %t = OpVariable %_ptr_Function_float Function
  488. OpStore %f %float_0
  489. OpStore %i %int_0
  490. OpBranch %25
  491. %25 = OpLabel
  492. %46 = OpPhi %float %float_0 %24 %36 %27
  493. %45 = OpPhi %int %int_0 %24 %43 %27
  494. OpLoopMerge %26 %27 None
  495. OpBranch %28
  496. %28 = OpLabel
  497. %30 = OpSLessThan %bool %45 %int_4
  498. OpBranchConditional %30 %31 %26
  499. %31 = OpLabel
  500. %34 = OpAccessChain %_ptr_Input_float %BC %45
  501. %35 = OpLoad %float %34
  502. %36 = OpFAdd %float %46 %35
  503. OpStore %t %36
  504. %38 = OpFOrdGreaterThan %bool %36 %float_1
  505. OpSelectionMerge %39 None
  506. OpBranchConditional %38 %40 %39
  507. %40 = OpLabel
  508. OpBranch %26
  509. %39 = OpLabel
  510. OpStore %f %36
  511. OpBranch %27
  512. %27 = OpLabel
  513. %43 = OpIAdd %int %45 %int_1
  514. OpStore %i %43
  515. OpBranch %25
  516. %26 = OpLabel
  517. OpStore %fo %46
  518. OpReturn
  519. OpFunctionEnd
  520. )";
  521. SinglePassRunAndCheck<SSARewritePass>(predefs + before, predefs + after, true,
  522. true);
  523. }
  524. TEST_F(LocalSSAElimTest, SwapProblem) {
  525. // #version 140
  526. //
  527. // in float fe;
  528. // out float fo;
  529. //
  530. // void main()
  531. // {
  532. // float f1 = 0.0;
  533. // float f2 = 1.0;
  534. // int ie = int(fe);
  535. // for (int i=0; i<ie; i++) {
  536. // float t = f1;
  537. // f1 = f2;
  538. // f2 = t;
  539. // }
  540. // fo = f1;
  541. // }
  542. const std::string predefs =
  543. R"(OpCapability Shader
  544. %1 = OpExtInstImport "GLSL.std.450"
  545. OpMemoryModel Logical GLSL450
  546. OpEntryPoint Fragment %main "main" %fe %fo
  547. OpExecutionMode %main OriginUpperLeft
  548. OpSource GLSL 140
  549. OpName %main "main"
  550. OpName %f1 "f1"
  551. OpName %f2 "f2"
  552. OpName %ie "ie"
  553. OpName %fe "fe"
  554. OpName %i "i"
  555. OpName %t "t"
  556. OpName %fo "fo"
  557. %void = OpTypeVoid
  558. %11 = OpTypeFunction %void
  559. %float = OpTypeFloat 32
  560. %_ptr_Function_float = OpTypePointer Function %float
  561. %float_0 = OpConstant %float 0
  562. %float_1 = OpConstant %float 1
  563. %int = OpTypeInt 32 1
  564. %_ptr_Function_int = OpTypePointer Function %int
  565. %_ptr_Input_float = OpTypePointer Input %float
  566. %fe = OpVariable %_ptr_Input_float Input
  567. %int_0 = OpConstant %int 0
  568. %bool = OpTypeBool
  569. %int_1 = OpConstant %int 1
  570. %_ptr_Output_float = OpTypePointer Output %float
  571. %fo = OpVariable %_ptr_Output_float Output
  572. )";
  573. const std::string before =
  574. R"(%main = OpFunction %void None %11
  575. %23 = OpLabel
  576. %f1 = OpVariable %_ptr_Function_float Function
  577. %f2 = OpVariable %_ptr_Function_float Function
  578. %ie = OpVariable %_ptr_Function_int Function
  579. %i = OpVariable %_ptr_Function_int Function
  580. %t = OpVariable %_ptr_Function_float Function
  581. OpStore %f1 %float_0
  582. OpStore %f2 %float_1
  583. %24 = OpLoad %float %fe
  584. %25 = OpConvertFToS %int %24
  585. OpStore %ie %25
  586. OpStore %i %int_0
  587. OpBranch %26
  588. %26 = OpLabel
  589. OpLoopMerge %27 %28 None
  590. OpBranch %29
  591. %29 = OpLabel
  592. %30 = OpLoad %int %i
  593. %31 = OpLoad %int %ie
  594. %32 = OpSLessThan %bool %30 %31
  595. OpBranchConditional %32 %33 %27
  596. %33 = OpLabel
  597. %34 = OpLoad %float %f1
  598. OpStore %t %34
  599. %35 = OpLoad %float %f2
  600. OpStore %f1 %35
  601. %36 = OpLoad %float %t
  602. OpStore %f2 %36
  603. OpBranch %28
  604. %28 = OpLabel
  605. %37 = OpLoad %int %i
  606. %38 = OpIAdd %int %37 %int_1
  607. OpStore %i %38
  608. OpBranch %26
  609. %27 = OpLabel
  610. %39 = OpLoad %float %f1
  611. OpStore %fo %39
  612. OpReturn
  613. OpFunctionEnd
  614. )";
  615. const std::string after =
  616. R"(%main = OpFunction %void None %11
  617. %23 = OpLabel
  618. %f1 = OpVariable %_ptr_Function_float Function
  619. %f2 = OpVariable %_ptr_Function_float Function
  620. %ie = OpVariable %_ptr_Function_int Function
  621. %i = OpVariable %_ptr_Function_int Function
  622. %t = OpVariable %_ptr_Function_float Function
  623. OpStore %f1 %float_0
  624. OpStore %f2 %float_1
  625. %24 = OpLoad %float %fe
  626. %25 = OpConvertFToS %int %24
  627. OpStore %ie %25
  628. OpStore %i %int_0
  629. OpBranch %26
  630. %26 = OpLabel
  631. %43 = OpPhi %float %float_1 %23 %42 %28
  632. %42 = OpPhi %float %float_0 %23 %43 %28
  633. %40 = OpPhi %int %int_0 %23 %38 %28
  634. OpLoopMerge %27 %28 None
  635. OpBranch %29
  636. %29 = OpLabel
  637. %32 = OpSLessThan %bool %40 %25
  638. OpBranchConditional %32 %33 %27
  639. %33 = OpLabel
  640. OpStore %t %42
  641. OpStore %f1 %43
  642. OpStore %f2 %42
  643. OpBranch %28
  644. %28 = OpLabel
  645. %38 = OpIAdd %int %40 %int_1
  646. OpStore %i %38
  647. OpBranch %26
  648. %27 = OpLabel
  649. OpStore %fo %42
  650. OpReturn
  651. OpFunctionEnd
  652. )";
  653. SinglePassRunAndCheck<SSARewritePass>(predefs + before, predefs + after, true,
  654. true);
  655. }
  656. TEST_F(LocalSSAElimTest, LostCopyProblem) {
  657. // #version 140
  658. //
  659. // in vec4 BC;
  660. // out float fo;
  661. //
  662. // void main()
  663. // {
  664. // float f = 0.0;
  665. // float t;
  666. // for (int i=0; i<4; i++) {
  667. // t = f;
  668. // f = f + BC[i];
  669. // if (f > 1.0)
  670. // break;
  671. // }
  672. // fo = t;
  673. // }
  674. const std::string predefs =
  675. R"(OpCapability Shader
  676. %1 = OpExtInstImport "GLSL.std.450"
  677. OpMemoryModel Logical GLSL450
  678. OpEntryPoint Fragment %main "main" %BC %fo
  679. OpExecutionMode %main OriginUpperLeft
  680. OpSource GLSL 140
  681. OpName %main "main"
  682. OpName %f "f"
  683. OpName %i "i"
  684. OpName %t "t"
  685. OpName %BC "BC"
  686. OpName %fo "fo"
  687. %void = OpTypeVoid
  688. %9 = OpTypeFunction %void
  689. %float = OpTypeFloat 32
  690. %_ptr_Function_float = OpTypePointer Function %float
  691. %float_0 = OpConstant %float 0
  692. %int = OpTypeInt 32 1
  693. %_ptr_Function_int = OpTypePointer Function %int
  694. %int_0 = OpConstant %int 0
  695. %int_4 = OpConstant %int 4
  696. %bool = OpTypeBool
  697. %v4float = OpTypeVector %float 4
  698. %_ptr_Input_v4float = OpTypePointer Input %v4float
  699. %BC = OpVariable %_ptr_Input_v4float Input
  700. %_ptr_Input_float = OpTypePointer Input %float
  701. %float_1 = OpConstant %float 1
  702. %int_1 = OpConstant %int 1
  703. %_ptr_Output_float = OpTypePointer Output %float
  704. %fo = OpVariable %_ptr_Output_float Output
  705. )";
  706. const std::string before =
  707. R"(%main = OpFunction %void None %9
  708. %24 = OpLabel
  709. %f = OpVariable %_ptr_Function_float Function
  710. %i = OpVariable %_ptr_Function_int Function
  711. %t = OpVariable %_ptr_Function_float Function
  712. OpStore %f %float_0
  713. OpStore %i %int_0
  714. OpBranch %25
  715. %25 = OpLabel
  716. OpLoopMerge %26 %27 None
  717. OpBranch %28
  718. %28 = OpLabel
  719. %29 = OpLoad %int %i
  720. %30 = OpSLessThan %bool %29 %int_4
  721. OpBranchConditional %30 %31 %26
  722. %31 = OpLabel
  723. %32 = OpLoad %float %f
  724. OpStore %t %32
  725. %33 = OpLoad %float %f
  726. %34 = OpLoad %int %i
  727. %35 = OpAccessChain %_ptr_Input_float %BC %34
  728. %36 = OpLoad %float %35
  729. %37 = OpFAdd %float %33 %36
  730. OpStore %f %37
  731. %38 = OpLoad %float %f
  732. %39 = OpFOrdGreaterThan %bool %38 %float_1
  733. OpSelectionMerge %40 None
  734. OpBranchConditional %39 %41 %40
  735. %41 = OpLabel
  736. OpBranch %26
  737. %40 = OpLabel
  738. OpBranch %27
  739. %27 = OpLabel
  740. %42 = OpLoad %int %i
  741. %43 = OpIAdd %int %42 %int_1
  742. OpStore %i %43
  743. OpBranch %25
  744. %26 = OpLabel
  745. %44 = OpLoad %float %t
  746. OpStore %fo %44
  747. OpReturn
  748. OpFunctionEnd
  749. )";
  750. const std::string after =
  751. R"(%49 = OpUndef %float
  752. %main = OpFunction %void None %9
  753. %24 = OpLabel
  754. %f = OpVariable %_ptr_Function_float Function
  755. %i = OpVariable %_ptr_Function_int Function
  756. %t = OpVariable %_ptr_Function_float Function
  757. OpStore %f %float_0
  758. OpStore %i %int_0
  759. OpBranch %25
  760. %25 = OpLabel
  761. %46 = OpPhi %float %float_0 %24 %37 %27
  762. %45 = OpPhi %int %int_0 %24 %43 %27
  763. %48 = OpPhi %float %49 %24 %46 %27
  764. OpLoopMerge %26 %27 None
  765. OpBranch %28
  766. %28 = OpLabel
  767. %30 = OpSLessThan %bool %45 %int_4
  768. OpBranchConditional %30 %31 %26
  769. %31 = OpLabel
  770. OpStore %t %46
  771. %35 = OpAccessChain %_ptr_Input_float %BC %45
  772. %36 = OpLoad %float %35
  773. %37 = OpFAdd %float %46 %36
  774. OpStore %f %37
  775. %39 = OpFOrdGreaterThan %bool %37 %float_1
  776. OpSelectionMerge %40 None
  777. OpBranchConditional %39 %41 %40
  778. %41 = OpLabel
  779. OpBranch %26
  780. %40 = OpLabel
  781. OpBranch %27
  782. %27 = OpLabel
  783. %43 = OpIAdd %int %45 %int_1
  784. OpStore %i %43
  785. OpBranch %25
  786. %26 = OpLabel
  787. %47 = OpPhi %float %48 %28 %46 %41
  788. OpStore %fo %47
  789. OpReturn
  790. OpFunctionEnd
  791. )";
  792. SinglePassRunAndCheck<SSARewritePass>(predefs + before, predefs + after, true,
  793. true);
  794. }
  795. TEST_F(LocalSSAElimTest, IfThenElse) {
  796. // #version 140
  797. //
  798. // in vec4 BaseColor;
  799. // in float f;
  800. //
  801. // void main()
  802. // {
  803. // vec4 v;
  804. // if (f >= 0)
  805. // v = BaseColor * 0.5;
  806. // else
  807. // v = BaseColor + vec4(1.0,1.0,1.0,1.0);
  808. // gl_FragColor = v;
  809. // }
  810. const std::string predefs =
  811. R"(OpCapability Shader
  812. %1 = OpExtInstImport "GLSL.std.450"
  813. OpMemoryModel Logical GLSL450
  814. OpEntryPoint Fragment %main "main" %f %BaseColor %gl_FragColor
  815. OpExecutionMode %main OriginUpperLeft
  816. OpSource GLSL 140
  817. OpName %main "main"
  818. OpName %f "f"
  819. OpName %v "v"
  820. OpName %BaseColor "BaseColor"
  821. OpName %gl_FragColor "gl_FragColor"
  822. %void = OpTypeVoid
  823. %8 = OpTypeFunction %void
  824. %float = OpTypeFloat 32
  825. %_ptr_Input_float = OpTypePointer Input %float
  826. %f = OpVariable %_ptr_Input_float Input
  827. %float_0 = OpConstant %float 0
  828. %bool = OpTypeBool
  829. %v4float = OpTypeVector %float 4
  830. %_ptr_Function_v4float = OpTypePointer Function %v4float
  831. %_ptr_Input_v4float = OpTypePointer Input %v4float
  832. %BaseColor = OpVariable %_ptr_Input_v4float Input
  833. %float_0_5 = OpConstant %float 0.5
  834. %float_1 = OpConstant %float 1
  835. %18 = OpConstantComposite %v4float %float_1 %float_1 %float_1 %float_1
  836. %_ptr_Output_v4float = OpTypePointer Output %v4float
  837. %gl_FragColor = OpVariable %_ptr_Output_v4float Output
  838. )";
  839. const std::string before =
  840. R"(%main = OpFunction %void None %8
  841. %20 = OpLabel
  842. %v = OpVariable %_ptr_Function_v4float Function
  843. %21 = OpLoad %float %f
  844. %22 = OpFOrdGreaterThanEqual %bool %21 %float_0
  845. OpSelectionMerge %23 None
  846. OpBranchConditional %22 %24 %25
  847. %24 = OpLabel
  848. %26 = OpLoad %v4float %BaseColor
  849. %27 = OpVectorTimesScalar %v4float %26 %float_0_5
  850. OpStore %v %27
  851. OpBranch %23
  852. %25 = OpLabel
  853. %28 = OpLoad %v4float %BaseColor
  854. %29 = OpFAdd %v4float %28 %18
  855. OpStore %v %29
  856. OpBranch %23
  857. %23 = OpLabel
  858. %30 = OpLoad %v4float %v
  859. OpStore %gl_FragColor %30
  860. OpReturn
  861. OpFunctionEnd
  862. )";
  863. const std::string after =
  864. R"(%main = OpFunction %void None %8
  865. %20 = OpLabel
  866. %v = OpVariable %_ptr_Function_v4float Function
  867. %21 = OpLoad %float %f
  868. %22 = OpFOrdGreaterThanEqual %bool %21 %float_0
  869. OpSelectionMerge %23 None
  870. OpBranchConditional %22 %24 %25
  871. %24 = OpLabel
  872. %26 = OpLoad %v4float %BaseColor
  873. %27 = OpVectorTimesScalar %v4float %26 %float_0_5
  874. OpStore %v %27
  875. OpBranch %23
  876. %25 = OpLabel
  877. %28 = OpLoad %v4float %BaseColor
  878. %29 = OpFAdd %v4float %28 %18
  879. OpStore %v %29
  880. OpBranch %23
  881. %23 = OpLabel
  882. %31 = OpPhi %v4float %27 %24 %29 %25
  883. OpStore %gl_FragColor %31
  884. OpReturn
  885. OpFunctionEnd
  886. )";
  887. SinglePassRunAndCheck<SSARewritePass>(predefs + before, predefs + after, true,
  888. true);
  889. }
  890. TEST_F(LocalSSAElimTest, IfThen) {
  891. // #version 140
  892. //
  893. // in vec4 BaseColor;
  894. // in float f;
  895. //
  896. // void main()
  897. // {
  898. // vec4 v = BaseColor;
  899. // if (f <= 0)
  900. // v = v * 0.5;
  901. // gl_FragColor = v;
  902. // }
  903. const std::string predefs =
  904. R"(OpCapability Shader
  905. %1 = OpExtInstImport "GLSL.std.450"
  906. OpMemoryModel Logical GLSL450
  907. OpEntryPoint Fragment %main "main" %BaseColor %f %gl_FragColor
  908. OpExecutionMode %main OriginUpperLeft
  909. OpSource GLSL 140
  910. OpName %main "main"
  911. OpName %v "v"
  912. OpName %BaseColor "BaseColor"
  913. OpName %f "f"
  914. OpName %gl_FragColor "gl_FragColor"
  915. %void = OpTypeVoid
  916. %8 = OpTypeFunction %void
  917. %float = OpTypeFloat 32
  918. %v4float = OpTypeVector %float 4
  919. %_ptr_Function_v4float = OpTypePointer Function %v4float
  920. %_ptr_Input_v4float = OpTypePointer Input %v4float
  921. %BaseColor = OpVariable %_ptr_Input_v4float Input
  922. %_ptr_Input_float = OpTypePointer Input %float
  923. %f = OpVariable %_ptr_Input_float Input
  924. %float_0 = OpConstant %float 0
  925. %bool = OpTypeBool
  926. %float_0_5 = OpConstant %float 0.5
  927. %_ptr_Output_v4float = OpTypePointer Output %v4float
  928. %gl_FragColor = OpVariable %_ptr_Output_v4float Output
  929. )";
  930. const std::string before =
  931. R"(%main = OpFunction %void None %8
  932. %18 = OpLabel
  933. %v = OpVariable %_ptr_Function_v4float Function
  934. %19 = OpLoad %v4float %BaseColor
  935. OpStore %v %19
  936. %20 = OpLoad %float %f
  937. %21 = OpFOrdLessThanEqual %bool %20 %float_0
  938. OpSelectionMerge %22 None
  939. OpBranchConditional %21 %23 %22
  940. %23 = OpLabel
  941. %24 = OpLoad %v4float %v
  942. %25 = OpVectorTimesScalar %v4float %24 %float_0_5
  943. OpStore %v %25
  944. OpBranch %22
  945. %22 = OpLabel
  946. %26 = OpLoad %v4float %v
  947. OpStore %gl_FragColor %26
  948. OpReturn
  949. OpFunctionEnd
  950. )";
  951. const std::string after =
  952. R"(%main = OpFunction %void None %8
  953. %18 = OpLabel
  954. %v = OpVariable %_ptr_Function_v4float Function
  955. %19 = OpLoad %v4float %BaseColor
  956. OpStore %v %19
  957. %20 = OpLoad %float %f
  958. %21 = OpFOrdLessThanEqual %bool %20 %float_0
  959. OpSelectionMerge %22 None
  960. OpBranchConditional %21 %23 %22
  961. %23 = OpLabel
  962. %25 = OpVectorTimesScalar %v4float %19 %float_0_5
  963. OpStore %v %25
  964. OpBranch %22
  965. %22 = OpLabel
  966. %27 = OpPhi %v4float %19 %18 %25 %23
  967. OpStore %gl_FragColor %27
  968. OpReturn
  969. OpFunctionEnd
  970. )";
  971. SinglePassRunAndCheck<SSARewritePass>(predefs + before, predefs + after, true,
  972. true);
  973. }
  974. TEST_F(LocalSSAElimTest, Switch) {
  975. // #version 140
  976. //
  977. // in vec4 BaseColor;
  978. // in float f;
  979. //
  980. // void main()
  981. // {
  982. // vec4 v = BaseColor;
  983. // int i = int(f);
  984. // switch (i) {
  985. // case 0:
  986. // v = v * 0.25;
  987. // break;
  988. // case 1:
  989. // v = v * 0.625;
  990. // break;
  991. // case 2:
  992. // v = v * 0.75;
  993. // break;
  994. // default:
  995. // break;
  996. // }
  997. // gl_FragColor = v;
  998. // }
  999. const std::string predefs =
  1000. R"(OpCapability Shader
  1001. %1 = OpExtInstImport "GLSL.std.450"
  1002. OpMemoryModel Logical GLSL450
  1003. OpEntryPoint Fragment %main "main" %BaseColor %f %gl_FragColor
  1004. OpExecutionMode %main OriginUpperLeft
  1005. OpSource GLSL 140
  1006. OpName %main "main"
  1007. OpName %v "v"
  1008. OpName %BaseColor "BaseColor"
  1009. OpName %i "i"
  1010. OpName %f "f"
  1011. OpName %gl_FragColor "gl_FragColor"
  1012. %void = OpTypeVoid
  1013. %9 = OpTypeFunction %void
  1014. %float = OpTypeFloat 32
  1015. %v4float = OpTypeVector %float 4
  1016. %_ptr_Function_v4float = OpTypePointer Function %v4float
  1017. %_ptr_Input_v4float = OpTypePointer Input %v4float
  1018. %BaseColor = OpVariable %_ptr_Input_v4float Input
  1019. %int = OpTypeInt 32 1
  1020. %_ptr_Function_int = OpTypePointer Function %int
  1021. %_ptr_Input_float = OpTypePointer Input %float
  1022. %f = OpVariable %_ptr_Input_float Input
  1023. %float_0_25 = OpConstant %float 0.25
  1024. %float_0_625 = OpConstant %float 0.625
  1025. %float_0_75 = OpConstant %float 0.75
  1026. %_ptr_Output_v4float = OpTypePointer Output %v4float
  1027. %gl_FragColor = OpVariable %_ptr_Output_v4float Output
  1028. )";
  1029. const std::string before =
  1030. R"(%main = OpFunction %void None %9
  1031. %21 = OpLabel
  1032. %v = OpVariable %_ptr_Function_v4float Function
  1033. %i = OpVariable %_ptr_Function_int Function
  1034. %22 = OpLoad %v4float %BaseColor
  1035. OpStore %v %22
  1036. %23 = OpLoad %float %f
  1037. %24 = OpConvertFToS %int %23
  1038. OpStore %i %24
  1039. %25 = OpLoad %int %i
  1040. OpSelectionMerge %26 None
  1041. OpSwitch %25 %27 0 %28 1 %29 2 %30
  1042. %27 = OpLabel
  1043. OpBranch %26
  1044. %28 = OpLabel
  1045. %31 = OpLoad %v4float %v
  1046. %32 = OpVectorTimesScalar %v4float %31 %float_0_25
  1047. OpStore %v %32
  1048. OpBranch %26
  1049. %29 = OpLabel
  1050. %33 = OpLoad %v4float %v
  1051. %34 = OpVectorTimesScalar %v4float %33 %float_0_625
  1052. OpStore %v %34
  1053. OpBranch %26
  1054. %30 = OpLabel
  1055. %35 = OpLoad %v4float %v
  1056. %36 = OpVectorTimesScalar %v4float %35 %float_0_75
  1057. OpStore %v %36
  1058. OpBranch %26
  1059. %26 = OpLabel
  1060. %37 = OpLoad %v4float %v
  1061. OpStore %gl_FragColor %37
  1062. OpReturn
  1063. OpFunctionEnd
  1064. )";
  1065. const std::string after =
  1066. R"(%main = OpFunction %void None %9
  1067. %21 = OpLabel
  1068. %v = OpVariable %_ptr_Function_v4float Function
  1069. %i = OpVariable %_ptr_Function_int Function
  1070. %22 = OpLoad %v4float %BaseColor
  1071. OpStore %v %22
  1072. %23 = OpLoad %float %f
  1073. %24 = OpConvertFToS %int %23
  1074. OpStore %i %24
  1075. OpSelectionMerge %26 None
  1076. OpSwitch %24 %27 0 %28 1 %29 2 %30
  1077. %27 = OpLabel
  1078. OpBranch %26
  1079. %28 = OpLabel
  1080. %32 = OpVectorTimesScalar %v4float %22 %float_0_25
  1081. OpStore %v %32
  1082. OpBranch %26
  1083. %29 = OpLabel
  1084. %34 = OpVectorTimesScalar %v4float %22 %float_0_625
  1085. OpStore %v %34
  1086. OpBranch %26
  1087. %30 = OpLabel
  1088. %36 = OpVectorTimesScalar %v4float %22 %float_0_75
  1089. OpStore %v %36
  1090. OpBranch %26
  1091. %26 = OpLabel
  1092. %38 = OpPhi %v4float %22 %27 %32 %28 %34 %29 %36 %30
  1093. OpStore %gl_FragColor %38
  1094. OpReturn
  1095. OpFunctionEnd
  1096. )";
  1097. SinglePassRunAndCheck<SSARewritePass>(predefs + before, predefs + after, true,
  1098. true);
  1099. }
  1100. TEST_F(LocalSSAElimTest, SwitchWithFallThrough) {
  1101. // #version 140
  1102. //
  1103. // in vec4 BaseColor;
  1104. // in float f;
  1105. //
  1106. // void main()
  1107. // {
  1108. // vec4 v = BaseColor;
  1109. // int i = int(f);
  1110. // switch (i) {
  1111. // case 0:
  1112. // v = v * 0.25;
  1113. // break;
  1114. // case 1:
  1115. // v = v + 0.25;
  1116. // case 2:
  1117. // v = v * 0.75;
  1118. // break;
  1119. // default:
  1120. // break;
  1121. // }
  1122. // gl_FragColor = v;
  1123. // }
  1124. const std::string predefs =
  1125. R"(OpCapability Shader
  1126. %1 = OpExtInstImport "GLSL.std.450"
  1127. OpMemoryModel Logical GLSL450
  1128. OpEntryPoint Fragment %main "main" %BaseColor %f %gl_FragColor
  1129. OpExecutionMode %main OriginUpperLeft
  1130. OpSource GLSL 140
  1131. OpName %main "main"
  1132. OpName %v "v"
  1133. OpName %BaseColor "BaseColor"
  1134. OpName %i "i"
  1135. OpName %f "f"
  1136. OpName %gl_FragColor "gl_FragColor"
  1137. %void = OpTypeVoid
  1138. %9 = OpTypeFunction %void
  1139. %float = OpTypeFloat 32
  1140. %v4float = OpTypeVector %float 4
  1141. %_ptr_Function_v4float = OpTypePointer Function %v4float
  1142. %_ptr_Input_v4float = OpTypePointer Input %v4float
  1143. %BaseColor = OpVariable %_ptr_Input_v4float Input
  1144. %int = OpTypeInt 32 1
  1145. %_ptr_Function_int = OpTypePointer Function %int
  1146. %_ptr_Input_float = OpTypePointer Input %float
  1147. %f = OpVariable %_ptr_Input_float Input
  1148. %float_0_25 = OpConstant %float 0.25
  1149. %float_0_75 = OpConstant %float 0.75
  1150. %_ptr_Output_v4float = OpTypePointer Output %v4float
  1151. %gl_FragColor = OpVariable %_ptr_Output_v4float Output
  1152. )";
  1153. const std::string before =
  1154. R"(%main = OpFunction %void None %9
  1155. %20 = OpLabel
  1156. %v = OpVariable %_ptr_Function_v4float Function
  1157. %i = OpVariable %_ptr_Function_int Function
  1158. %21 = OpLoad %v4float %BaseColor
  1159. OpStore %v %21
  1160. %22 = OpLoad %float %f
  1161. %23 = OpConvertFToS %int %22
  1162. OpStore %i %23
  1163. %24 = OpLoad %int %i
  1164. OpSelectionMerge %25 None
  1165. OpSwitch %24 %26 0 %27 1 %28 2 %29
  1166. %26 = OpLabel
  1167. OpBranch %25
  1168. %27 = OpLabel
  1169. %30 = OpLoad %v4float %v
  1170. %31 = OpVectorTimesScalar %v4float %30 %float_0_25
  1171. OpStore %v %31
  1172. OpBranch %25
  1173. %28 = OpLabel
  1174. %32 = OpLoad %v4float %v
  1175. %33 = OpCompositeConstruct %v4float %float_0_25 %float_0_25 %float_0_25 %float_0_25
  1176. %34 = OpFAdd %v4float %32 %33
  1177. OpStore %v %34
  1178. OpBranch %29
  1179. %29 = OpLabel
  1180. %35 = OpLoad %v4float %v
  1181. %36 = OpVectorTimesScalar %v4float %35 %float_0_75
  1182. OpStore %v %36
  1183. OpBranch %25
  1184. %25 = OpLabel
  1185. %37 = OpLoad %v4float %v
  1186. OpStore %gl_FragColor %37
  1187. OpReturn
  1188. OpFunctionEnd
  1189. )";
  1190. const std::string after =
  1191. R"(%main = OpFunction %void None %9
  1192. %20 = OpLabel
  1193. %v = OpVariable %_ptr_Function_v4float Function
  1194. %i = OpVariable %_ptr_Function_int Function
  1195. %21 = OpLoad %v4float %BaseColor
  1196. OpStore %v %21
  1197. %22 = OpLoad %float %f
  1198. %23 = OpConvertFToS %int %22
  1199. OpStore %i %23
  1200. OpSelectionMerge %25 None
  1201. OpSwitch %23 %26 0 %27 1 %28 2 %29
  1202. %26 = OpLabel
  1203. OpBranch %25
  1204. %27 = OpLabel
  1205. %31 = OpVectorTimesScalar %v4float %21 %float_0_25
  1206. OpStore %v %31
  1207. OpBranch %25
  1208. %28 = OpLabel
  1209. %33 = OpCompositeConstruct %v4float %float_0_25 %float_0_25 %float_0_25 %float_0_25
  1210. %34 = OpFAdd %v4float %21 %33
  1211. OpStore %v %34
  1212. OpBranch %29
  1213. %29 = OpLabel
  1214. %38 = OpPhi %v4float %21 %20 %34 %28
  1215. %36 = OpVectorTimesScalar %v4float %38 %float_0_75
  1216. OpStore %v %36
  1217. OpBranch %25
  1218. %25 = OpLabel
  1219. %39 = OpPhi %v4float %21 %26 %31 %27 %36 %29
  1220. OpStore %gl_FragColor %39
  1221. OpReturn
  1222. OpFunctionEnd
  1223. )";
  1224. SinglePassRunAndCheck<SSARewritePass>(predefs + before, predefs + after, true,
  1225. true);
  1226. }
  1227. TEST_F(LocalSSAElimTest, DontPatchPhiInLoopHeaderThatIsNotAVar) {
  1228. // From https://github.com/KhronosGroup/SPIRV-Tools/issues/826
  1229. // Don't try patching the (%16 %7) value/predecessor pair in the OpPhi.
  1230. // That OpPhi is unrelated to this optimization: we did not set that up
  1231. // in the SSA initialization for the loop header block.
  1232. // The pass should be a no-op on this module.
  1233. const std::string before = R"(OpCapability Shader
  1234. OpMemoryModel Logical GLSL450
  1235. OpEntryPoint GLCompute %1 "main"
  1236. %void = OpTypeVoid
  1237. %3 = OpTypeFunction %void
  1238. %float = OpTypeFloat 32
  1239. %float_1 = OpConstant %float 1
  1240. %1 = OpFunction %void None %3
  1241. %6 = OpLabel
  1242. OpBranch %7
  1243. %7 = OpLabel
  1244. %8 = OpPhi %float %float_1 %6 %9 %7
  1245. %9 = OpFAdd %float %8 %float_1
  1246. OpLoopMerge %10 %7 None
  1247. OpBranch %7
  1248. %10 = OpLabel
  1249. OpReturn
  1250. OpFunctionEnd
  1251. )";
  1252. SinglePassRunAndCheck<SSARewritePass>(before, before, true, true);
  1253. }
  1254. TEST_F(LocalSSAElimTest, OptInitializedVariableLikeStore) {
  1255. // Note: SPIR-V edited to change store to v into variable initialization
  1256. //
  1257. // #version 450
  1258. //
  1259. // layout (location=0) in vec4 iColor;
  1260. // layout (location=1) in float fi;
  1261. // layout (location=0) out vec4 oColor;
  1262. //
  1263. // void main()
  1264. // {
  1265. // vec4 v = vec4(0.0);
  1266. // if (fi < 0.0)
  1267. // v.x = iColor.x;
  1268. // oColor = v;
  1269. // }
  1270. const std::string predefs =
  1271. R"(OpCapability Shader
  1272. %1 = OpExtInstImport "GLSL.std.450"
  1273. OpMemoryModel Logical GLSL450
  1274. OpEntryPoint Fragment %main "main" %fi %iColor %oColor
  1275. OpExecutionMode %main OriginUpperLeft
  1276. OpSource GLSL 450
  1277. OpName %main "main"
  1278. OpName %v "v"
  1279. OpName %fi "fi"
  1280. OpName %iColor "iColor"
  1281. OpName %oColor "oColor"
  1282. OpDecorate %fi Location 1
  1283. OpDecorate %iColor Location 0
  1284. OpDecorate %oColor Location 0
  1285. %void = OpTypeVoid
  1286. %8 = OpTypeFunction %void
  1287. %float = OpTypeFloat 32
  1288. %v4float = OpTypeVector %float 4
  1289. %_ptr_Function_v4float = OpTypePointer Function %v4float
  1290. %float_0 = OpConstant %float 0
  1291. %13 = OpConstantComposite %v4float %float_0 %float_0 %float_0 %float_0
  1292. %_ptr_Input_float = OpTypePointer Input %float
  1293. %fi = OpVariable %_ptr_Input_float Input
  1294. %bool = OpTypeBool
  1295. %_ptr_Input_v4float = OpTypePointer Input %v4float
  1296. %iColor = OpVariable %_ptr_Input_v4float Input
  1297. %uint = OpTypeInt 32 0
  1298. %uint_0 = OpConstant %uint 0
  1299. %_ptr_Function_float = OpTypePointer Function %float
  1300. %_ptr_Output_v4float = OpTypePointer Output %v4float
  1301. %oColor = OpVariable %_ptr_Output_v4float Output
  1302. )";
  1303. const std::string func_before =
  1304. R"(%main = OpFunction %void None %8
  1305. %21 = OpLabel
  1306. %v = OpVariable %_ptr_Function_v4float Function %13
  1307. %22 = OpLoad %float %fi
  1308. %23 = OpFOrdLessThan %bool %22 %float_0
  1309. OpSelectionMerge %24 None
  1310. OpBranchConditional %23 %25 %24
  1311. %25 = OpLabel
  1312. %26 = OpAccessChain %_ptr_Input_float %iColor %uint_0
  1313. %27 = OpLoad %float %26
  1314. %28 = OpLoad %v4float %v
  1315. %29 = OpCompositeInsert %v4float %27 %28 0
  1316. OpStore %v %29
  1317. OpBranch %24
  1318. %24 = OpLabel
  1319. %30 = OpLoad %v4float %v
  1320. OpStore %oColor %30
  1321. OpReturn
  1322. OpFunctionEnd
  1323. )";
  1324. const std::string func_after =
  1325. R"(%main = OpFunction %void None %8
  1326. %21 = OpLabel
  1327. %v = OpVariable %_ptr_Function_v4float Function %13
  1328. %22 = OpLoad %float %fi
  1329. %23 = OpFOrdLessThan %bool %22 %float_0
  1330. OpSelectionMerge %24 None
  1331. OpBranchConditional %23 %25 %24
  1332. %25 = OpLabel
  1333. %26 = OpAccessChain %_ptr_Input_float %iColor %uint_0
  1334. %27 = OpLoad %float %26
  1335. %29 = OpCompositeInsert %v4float %27 %13 0
  1336. OpStore %v %29
  1337. OpBranch %24
  1338. %24 = OpLabel
  1339. %31 = OpPhi %v4float %13 %21 %29 %25
  1340. OpStore %oColor %31
  1341. OpReturn
  1342. OpFunctionEnd
  1343. )";
  1344. SinglePassRunAndCheck<SSARewritePass>(predefs + func_before,
  1345. predefs + func_after, true, true);
  1346. }
  1347. TEST_F(LocalSSAElimTest, PointerVariable) {
  1348. // Test that checks if a pointer variable is removed.
  1349. const std::string before =
  1350. R"(OpCapability Shader
  1351. OpMemoryModel Logical GLSL450
  1352. OpEntryPoint Fragment %1 "main" %2
  1353. OpExecutionMode %1 OriginUpperLeft
  1354. OpMemberDecorate %_struct_3 0 Offset 0
  1355. OpDecorate %_runtimearr__struct_3 ArrayStride 16
  1356. OpMemberDecorate %_struct_5 0 Offset 0
  1357. OpDecorate %_struct_5 BufferBlock
  1358. OpMemberDecorate %_struct_6 0 Offset 0
  1359. OpDecorate %_struct_6 BufferBlock
  1360. OpDecorate %2 Location 0
  1361. OpDecorate %7 DescriptorSet 0
  1362. OpDecorate %7 Binding 0
  1363. %void = OpTypeVoid
  1364. %10 = OpTypeFunction %void
  1365. %int = OpTypeInt 32 1
  1366. %uint = OpTypeInt 32 0
  1367. %float = OpTypeFloat 32
  1368. %v4float = OpTypeVector %float 4
  1369. %_ptr_Output_v4float = OpTypePointer Output %v4float
  1370. %_ptr_Uniform_v4float = OpTypePointer Uniform %v4float
  1371. %_struct_3 = OpTypeStruct %v4float
  1372. %_runtimearr__struct_3 = OpTypeRuntimeArray %_struct_3
  1373. %_struct_5 = OpTypeStruct %_runtimearr__struct_3
  1374. %_ptr_Uniform__struct_5 = OpTypePointer Uniform %_struct_5
  1375. %_struct_6 = OpTypeStruct %int
  1376. %_ptr_Uniform__struct_6 = OpTypePointer Uniform %_struct_6
  1377. %_ptr_Function__ptr_Uniform__struct_5 = OpTypePointer Function %_ptr_Uniform__struct_5
  1378. %_ptr_Function__ptr_Uniform__struct_6 = OpTypePointer Function %_ptr_Uniform__struct_6
  1379. %int_0 = OpConstant %int 0
  1380. %uint_0 = OpConstant %uint 0
  1381. %2 = OpVariable %_ptr_Output_v4float Output
  1382. %7 = OpVariable %_ptr_Uniform__struct_5 Uniform
  1383. %1 = OpFunction %void None %10
  1384. %23 = OpLabel
  1385. %24 = OpVariable %_ptr_Function__ptr_Uniform__struct_5 Function
  1386. OpStore %24 %7
  1387. %26 = OpLoad %_ptr_Uniform__struct_5 %24
  1388. %27 = OpAccessChain %_ptr_Uniform_v4float %26 %int_0 %uint_0 %int_0
  1389. %28 = OpLoad %v4float %27
  1390. %29 = OpCopyObject %v4float %28
  1391. OpStore %2 %28
  1392. OpReturn
  1393. OpFunctionEnd
  1394. )";
  1395. const std::string after =
  1396. R"(OpCapability Shader
  1397. OpMemoryModel Logical GLSL450
  1398. OpEntryPoint Fragment %1 "main" %2
  1399. OpExecutionMode %1 OriginUpperLeft
  1400. OpMemberDecorate %_struct_3 0 Offset 0
  1401. OpDecorate %_runtimearr__struct_3 ArrayStride 16
  1402. OpMemberDecorate %_struct_5 0 Offset 0
  1403. OpDecorate %_struct_5 BufferBlock
  1404. OpMemberDecorate %_struct_6 0 Offset 0
  1405. OpDecorate %_struct_6 BufferBlock
  1406. OpDecorate %2 Location 0
  1407. OpDecorate %7 DescriptorSet 0
  1408. OpDecorate %7 Binding 0
  1409. %void = OpTypeVoid
  1410. %10 = OpTypeFunction %void
  1411. %int = OpTypeInt 32 1
  1412. %uint = OpTypeInt 32 0
  1413. %float = OpTypeFloat 32
  1414. %v4float = OpTypeVector %float 4
  1415. %_ptr_Output_v4float = OpTypePointer Output %v4float
  1416. %_ptr_Uniform_v4float = OpTypePointer Uniform %v4float
  1417. %_struct_3 = OpTypeStruct %v4float
  1418. %_runtimearr__struct_3 = OpTypeRuntimeArray %_struct_3
  1419. %_struct_5 = OpTypeStruct %_runtimearr__struct_3
  1420. %_ptr_Uniform__struct_5 = OpTypePointer Uniform %_struct_5
  1421. %_struct_6 = OpTypeStruct %int
  1422. %_ptr_Uniform__struct_6 = OpTypePointer Uniform %_struct_6
  1423. %_ptr_Function__ptr_Uniform__struct_5 = OpTypePointer Function %_ptr_Uniform__struct_5
  1424. %_ptr_Function__ptr_Uniform__struct_6 = OpTypePointer Function %_ptr_Uniform__struct_6
  1425. %int_0 = OpConstant %int 0
  1426. %uint_0 = OpConstant %uint 0
  1427. %2 = OpVariable %_ptr_Output_v4float Output
  1428. %7 = OpVariable %_ptr_Uniform__struct_5 Uniform
  1429. %1 = OpFunction %void None %10
  1430. %23 = OpLabel
  1431. %24 = OpVariable %_ptr_Function__ptr_Uniform__struct_5 Function
  1432. OpStore %24 %7
  1433. %27 = OpAccessChain %_ptr_Uniform_v4float %7 %int_0 %uint_0 %int_0
  1434. %28 = OpLoad %v4float %27
  1435. %29 = OpCopyObject %v4float %28
  1436. OpStore %2 %28
  1437. OpReturn
  1438. OpFunctionEnd
  1439. )";
  1440. // Relax logical pointers to allow pointer allocations.
  1441. SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  1442. ValidatorOptions()->relax_logical_pointer = true;
  1443. SinglePassRunAndCheck<SSARewritePass>(before, after, true, true);
  1444. }
  1445. TEST_F(LocalSSAElimTest, VerifyInstToBlockMap) {
  1446. // #version 140
  1447. //
  1448. // in vec4 BC;
  1449. // out float fo;
  1450. //
  1451. // void main()
  1452. // {
  1453. // float f = 0.0;
  1454. // for (int i=0; i<4; i++) {
  1455. // f = f + BC[i];
  1456. // }
  1457. // fo = f;
  1458. // }
  1459. const std::string text = R"(
  1460. OpCapability Shader
  1461. %1 = OpExtInstImport "GLSL.std.450"
  1462. OpMemoryModel Logical GLSL450
  1463. OpEntryPoint Fragment %main "main" %BC %fo
  1464. OpExecutionMode %main OriginUpperLeft
  1465. OpSource GLSL 140
  1466. OpName %main "main"
  1467. OpName %f "f"
  1468. OpName %i "i"
  1469. OpName %BC "BC"
  1470. OpName %fo "fo"
  1471. %void = OpTypeVoid
  1472. %8 = OpTypeFunction %void
  1473. %float = OpTypeFloat 32
  1474. %_ptr_Function_float = OpTypePointer Function %float
  1475. %float_0 = OpConstant %float 0
  1476. %int = OpTypeInt 32 1
  1477. %_ptr_Function_int = OpTypePointer Function %int
  1478. %int_0 = OpConstant %int 0
  1479. %int_4 = OpConstant %int 4
  1480. %bool = OpTypeBool
  1481. %v4float = OpTypeVector %float 4
  1482. %_ptr_Input_v4float = OpTypePointer Input %v4float
  1483. %BC = OpVariable %_ptr_Input_v4float Input
  1484. %_ptr_Input_float = OpTypePointer Input %float
  1485. %int_1 = OpConstant %int 1
  1486. %_ptr_Output_float = OpTypePointer Output %float
  1487. %fo = OpVariable %_ptr_Output_float Output
  1488. %main = OpFunction %void None %8
  1489. %22 = OpLabel
  1490. %f = OpVariable %_ptr_Function_float Function
  1491. %i = OpVariable %_ptr_Function_int Function
  1492. OpStore %f %float_0
  1493. OpStore %i %int_0
  1494. OpBranch %23
  1495. %23 = OpLabel
  1496. OpLoopMerge %24 %25 None
  1497. OpBranch %26
  1498. %26 = OpLabel
  1499. %27 = OpLoad %int %i
  1500. %28 = OpSLessThan %bool %27 %int_4
  1501. OpBranchConditional %28 %29 %24
  1502. %29 = OpLabel
  1503. %30 = OpLoad %float %f
  1504. %31 = OpLoad %int %i
  1505. %32 = OpAccessChain %_ptr_Input_float %BC %31
  1506. %33 = OpLoad %float %32
  1507. %34 = OpFAdd %float %30 %33
  1508. OpStore %f %34
  1509. OpBranch %25
  1510. %25 = OpLabel
  1511. %35 = OpLoad %int %i
  1512. %36 = OpIAdd %int %35 %int_1
  1513. OpStore %i %36
  1514. OpBranch %23
  1515. %24 = OpLabel
  1516. %37 = OpLoad %float %f
  1517. OpStore %fo %37
  1518. OpReturn
  1519. OpFunctionEnd
  1520. )";
  1521. std::unique_ptr<IRContext> context =
  1522. BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, text,
  1523. SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  1524. EXPECT_NE(nullptr, context);
  1525. // Force the instruction to block mapping to get built.
  1526. context->get_instr_block(27u);
  1527. auto pass = MakeUnique<SSARewritePass>();
  1528. pass->SetMessageConsumer(nullptr);
  1529. const auto status = pass->Run(context.get());
  1530. EXPECT_TRUE(status == Pass::Status::SuccessWithChange);
  1531. }
  1532. TEST_F(LocalSSAElimTest, CompositeExtractProblem) {
  1533. const std::string spv_asm = R"(
  1534. OpCapability Tessellation
  1535. %1 = OpExtInstImport "GLSL.std.450"
  1536. OpMemoryModel Logical GLSL450
  1537. OpEntryPoint TessellationControl %2 "main" %16 %17 %18 %20 %22 %26 %27 %30 %31
  1538. %void = OpTypeVoid
  1539. %4 = OpTypeFunction %void
  1540. %float = OpTypeFloat 32
  1541. %v4float = OpTypeVector %float 4
  1542. %uint = OpTypeInt 32 0
  1543. %uint_3 = OpConstant %uint 3
  1544. %v3float = OpTypeVector %float 3
  1545. %v2float = OpTypeVector %float 2
  1546. %_struct_11 = OpTypeStruct %v4float %v4float %v4float %v3float %v3float %v2float %v2float
  1547. %_arr__struct_11_uint_3 = OpTypeArray %_struct_11 %uint_3
  1548. %_ptr_Function__arr__struct_11_uint_3 = OpTypePointer Function %_arr__struct_11_uint_3
  1549. %_arr_v4float_uint_3 = OpTypeArray %v4float %uint_3
  1550. %_ptr_Input__arr_v4float_uint_3 = OpTypePointer Input %_arr_v4float_uint_3
  1551. %16 = OpVariable %_ptr_Input__arr_v4float_uint_3 Input
  1552. %17 = OpVariable %_ptr_Input__arr_v4float_uint_3 Input
  1553. %18 = OpVariable %_ptr_Input__arr_v4float_uint_3 Input
  1554. %_ptr_Input_uint = OpTypePointer Input %uint
  1555. %20 = OpVariable %_ptr_Input_uint Input
  1556. %_ptr_Output__arr_v4float_uint_3 = OpTypePointer Output %_arr_v4float_uint_3
  1557. %22 = OpVariable %_ptr_Output__arr_v4float_uint_3 Output
  1558. %_ptr_Output_v4float = OpTypePointer Output %v4float
  1559. %_arr_v3float_uint_3 = OpTypeArray %v3float %uint_3
  1560. %_ptr_Input__arr_v3float_uint_3 = OpTypePointer Input %_arr_v3float_uint_3
  1561. %26 = OpVariable %_ptr_Input__arr_v3float_uint_3 Input
  1562. %27 = OpVariable %_ptr_Input__arr_v3float_uint_3 Input
  1563. %_arr_v2float_uint_3 = OpTypeArray %v2float %uint_3
  1564. %_ptr_Input__arr_v2float_uint_3 = OpTypePointer Input %_arr_v2float_uint_3
  1565. %30 = OpVariable %_ptr_Input__arr_v2float_uint_3 Input
  1566. %31 = OpVariable %_ptr_Input__arr_v2float_uint_3 Input
  1567. %_ptr_Function__struct_11 = OpTypePointer Function %_struct_11
  1568. %2 = OpFunction %void None %4
  1569. %33 = OpLabel
  1570. %66 = OpVariable %_ptr_Function__arr__struct_11_uint_3 Function
  1571. %34 = OpLoad %_arr_v4float_uint_3 %16
  1572. %35 = OpLoad %_arr_v4float_uint_3 %17
  1573. %36 = OpLoad %_arr_v4float_uint_3 %18
  1574. %37 = OpLoad %_arr_v3float_uint_3 %26
  1575. %38 = OpLoad %_arr_v3float_uint_3 %27
  1576. %39 = OpLoad %_arr_v2float_uint_3 %30
  1577. %40 = OpLoad %_arr_v2float_uint_3 %31
  1578. %41 = OpCompositeExtract %v4float %34 0
  1579. %42 = OpCompositeExtract %v4float %35 0
  1580. %43 = OpCompositeExtract %v4float %36 0
  1581. %44 = OpCompositeExtract %v3float %37 0
  1582. %45 = OpCompositeExtract %v3float %38 0
  1583. %46 = OpCompositeExtract %v2float %39 0
  1584. %47 = OpCompositeExtract %v2float %40 0
  1585. %48 = OpCompositeConstruct %_struct_11 %41 %42 %43 %44 %45 %46 %47
  1586. %49 = OpCompositeExtract %v4float %34 1
  1587. %50 = OpCompositeExtract %v4float %35 1
  1588. %51 = OpCompositeExtract %v4float %36 1
  1589. %52 = OpCompositeExtract %v3float %37 1
  1590. %53 = OpCompositeExtract %v3float %38 1
  1591. %54 = OpCompositeExtract %v2float %39 1
  1592. %55 = OpCompositeExtract %v2float %40 1
  1593. %56 = OpCompositeConstruct %_struct_11 %49 %50 %51 %52 %53 %54 %55
  1594. %57 = OpCompositeExtract %v4float %34 2
  1595. %58 = OpCompositeExtract %v4float %35 2
  1596. %59 = OpCompositeExtract %v4float %36 2
  1597. %60 = OpCompositeExtract %v3float %37 2
  1598. %61 = OpCompositeExtract %v3float %38 2
  1599. %62 = OpCompositeExtract %v2float %39 2
  1600. %63 = OpCompositeExtract %v2float %40 2
  1601. %64 = OpCompositeConstruct %_struct_11 %57 %58 %59 %60 %61 %62 %63
  1602. %65 = OpCompositeConstruct %_arr__struct_11_uint_3 %48 %56 %64
  1603. %67 = OpLoad %uint %20
  1604. ; CHECK OpStore {{%\d+}} [[store_source:%\d+]]
  1605. OpStore %66 %65
  1606. %68 = OpAccessChain %_ptr_Function__struct_11 %66 %67
  1607. ; This load was being removed, because %_ptr_Function__struct_11 was being
  1608. ; wrongfully considered an SSA target.
  1609. ; CHECK OpLoad %_struct_11 %68
  1610. %69 = OpLoad %_struct_11 %68
  1611. ; Similarly, %69 cannot be replaced with %65.
  1612. ; CHECK-NOT: OpCompositeExtract %v4float [[store_source]] 0
  1613. %70 = OpCompositeExtract %v4float %69 0
  1614. %71 = OpAccessChain %_ptr_Output_v4float %22 %67
  1615. OpStore %71 %70
  1616. OpReturn
  1617. OpFunctionEnd)";
  1618. SinglePassRunAndMatch<SSARewritePass>(spv_asm, true);
  1619. }
  1620. // Test that the RelaxedPrecision decoration on the variable to added to the
  1621. // result of the OpPhi instruction.
  1622. TEST_F(LocalSSAElimTest, DecoratedVariable) {
  1623. const std::string spv_asm = R"(
  1624. ; CHECK: OpDecorate [[var:%\w+]] RelaxedPrecision
  1625. ; CHECK: OpDecorate [[phi_id:%\w+]] RelaxedPrecision
  1626. ; CHECK: [[phi_id]] = OpPhi
  1627. OpCapability Shader
  1628. %1 = OpExtInstImport "GLSL.std.450"
  1629. OpMemoryModel Logical GLSL450
  1630. OpEntryPoint GLCompute %2 "main"
  1631. OpDecorate %v RelaxedPrecision
  1632. %void = OpTypeVoid
  1633. %func_t = OpTypeFunction %void
  1634. %bool = OpTypeBool
  1635. %true = OpConstantTrue %bool
  1636. %int = OpTypeInt 32 0
  1637. %int_p = OpTypePointer Function %int
  1638. %int_1 = OpConstant %int 1
  1639. %int_0 = OpConstant %int 0
  1640. %2 = OpFunction %void None %func_t
  1641. %33 = OpLabel
  1642. %v = OpVariable %int_p Function
  1643. OpSelectionMerge %merge None
  1644. OpBranchConditional %true %l1 %l2
  1645. %l1 = OpLabel
  1646. OpStore %v %int_1
  1647. OpBranch %merge
  1648. %l2 = OpLabel
  1649. OpStore %v %int_0
  1650. OpBranch %merge
  1651. %merge = OpLabel
  1652. %ld = OpLoad %int %v
  1653. OpReturn
  1654. OpFunctionEnd)";
  1655. SinglePassRunAndMatch<SSARewritePass>(spv_asm, true);
  1656. }
  1657. // Test that the RelaxedPrecision decoration on the variable to added to the
  1658. // result of the OpPhi instruction.
  1659. TEST_F(LocalSSAElimTest, MultipleEdges) {
  1660. const std::string spv_asm = R"(
  1661. ; CHECK: OpSelectionMerge
  1662. ; CHECK: [[header_bb:%\w+]] = OpLabel
  1663. ; CHECK-NOT: OpLabel
  1664. ; CHECK: OpSwitch {{%\w+}} {{%\w+}} 76 [[bb1:%\w+]] 17 [[bb2:%\w+]]
  1665. ; CHECK-SAME: 4 [[bb2]]
  1666. ; CHECK: [[bb2]] = OpLabel
  1667. ; CHECK-NEXT: OpPhi [[type:%\w+]] [[val:%\w+]] [[header_bb]] %int_0 [[bb1]]
  1668. OpCapability Shader
  1669. %1 = OpExtInstImport "GLSL.std.450"
  1670. OpMemoryModel Logical GLSL450
  1671. OpEntryPoint Fragment %4 "main"
  1672. OpExecutionMode %4 OriginUpperLeft
  1673. OpSource ESSL 310
  1674. %void = OpTypeVoid
  1675. %3 = OpTypeFunction %void
  1676. %int = OpTypeInt 32 1
  1677. %_ptr_Function_int = OpTypePointer Function %int
  1678. %int_0 = OpConstant %int 0
  1679. %bool = OpTypeBool
  1680. %true = OpConstantTrue %bool
  1681. %false = OpConstantFalse %bool
  1682. %int_1 = OpConstant %int 1
  1683. %4 = OpFunction %void None %3
  1684. %5 = OpLabel
  1685. %8 = OpVariable %_ptr_Function_int Function
  1686. OpBranch %10
  1687. %10 = OpLabel
  1688. OpLoopMerge %12 %13 None
  1689. OpBranch %14
  1690. %14 = OpLabel
  1691. OpBranchConditional %true %11 %12
  1692. %11 = OpLabel
  1693. OpSelectionMerge %19 None
  1694. OpBranchConditional %false %18 %19
  1695. %18 = OpLabel
  1696. OpSelectionMerge %22 None
  1697. OpSwitch %int_0 %22 76 %20 17 %21 4 %21
  1698. %20 = OpLabel
  1699. %23 = OpLoad %int %8
  1700. OpStore %8 %int_0
  1701. OpBranch %21
  1702. %21 = OpLabel
  1703. OpBranch %22
  1704. %22 = OpLabel
  1705. OpBranch %19
  1706. %19 = OpLabel
  1707. OpBranch %13
  1708. %13 = OpLabel
  1709. OpBranch %10
  1710. %12 = OpLabel
  1711. OpReturn
  1712. OpFunctionEnd
  1713. )";
  1714. SinglePassRunAndMatch<SSARewritePass>(spv_asm, true);
  1715. }
  1716. TEST_F(LocalSSAElimTest, VariablePointerTest1) {
  1717. // Check that the load of the first variable is still used and that the load
  1718. // of the third variable is propagated. The first load has to remain because
  1719. // of the store to the variable pointer.
  1720. const std::string text = R"(
  1721. ; CHECK: [[v1:%\w+]] = OpVariable
  1722. ; CHECK: [[v2:%\w+]] = OpVariable
  1723. ; CHECK: [[v3:%\w+]] = OpVariable
  1724. ; CHECK: [[ld1:%\w+]] = OpLoad %int [[v1]]
  1725. ; CHECK: OpIAdd %int [[ld1]] %int_0
  1726. OpCapability Shader
  1727. OpCapability VariablePointers
  1728. %1 = OpExtInstImport "GLSL.std.450"
  1729. OpMemoryModel Logical GLSL450
  1730. OpEntryPoint GLCompute %2 "main"
  1731. OpExecutionMode %2 LocalSize 1 1 1
  1732. OpSource GLSL 450
  1733. OpMemberDecorate %_struct_3 0 Offset 0
  1734. OpMemberDecorate %_struct_3 1 Offset 4
  1735. %void = OpTypeVoid
  1736. %5 = OpTypeFunction %void
  1737. %int = OpTypeInt 32 1
  1738. %bool = OpTypeBool
  1739. %_struct_3 = OpTypeStruct %int %int
  1740. %_ptr_Function__struct_3 = OpTypePointer Function %_struct_3
  1741. %_ptr_Function_int = OpTypePointer Function %int
  1742. %true = OpConstantTrue %bool
  1743. %int_0 = OpConstant %int 0
  1744. %int_1 = OpConstant %int 1
  1745. %13 = OpConstantNull %_struct_3
  1746. %2 = OpFunction %void None %5
  1747. %14 = OpLabel
  1748. %15 = OpVariable %_ptr_Function_int Function
  1749. %16 = OpVariable %_ptr_Function_int Function
  1750. %17 = OpVariable %_ptr_Function_int Function
  1751. OpStore %15 %int_1
  1752. OpStore %17 %int_0
  1753. OpSelectionMerge %18 None
  1754. OpBranchConditional %true %19 %20
  1755. %19 = OpLabel
  1756. OpBranch %18
  1757. %20 = OpLabel
  1758. OpBranch %18
  1759. %18 = OpLabel
  1760. %21 = OpPhi %_ptr_Function_int %15 %19 %16 %20
  1761. OpStore %21 %int_0
  1762. %22 = OpLoad %int %15
  1763. %23 = OpLoad %int %17
  1764. %24 = OpIAdd %int %22 %23
  1765. OpReturn
  1766. OpFunctionEnd
  1767. )";
  1768. SinglePassRunAndMatch<SSARewritePass>(text, false);
  1769. }
  1770. TEST_F(LocalSSAElimTest, VariablePointerTest2) {
  1771. // Check that the load of the first variable is still used and that the load
  1772. // of the third variable is propagated. The first load has to remain because
  1773. // of the store to the variable pointer.
  1774. const std::string text = R"(
  1775. ; CHECK: [[v1:%\w+]] = OpVariable
  1776. ; CHECK: [[v2:%\w+]] = OpVariable
  1777. ; CHECK: [[v3:%\w+]] = OpVariable
  1778. ; CHECK: [[ld1:%\w+]] = OpLoad %int [[v1]]
  1779. ; CHECK: OpIAdd %int [[ld1]] %int_0
  1780. OpCapability Shader
  1781. OpCapability VariablePointers
  1782. %1 = OpExtInstImport "GLSL.std.450"
  1783. OpMemoryModel Logical GLSL450
  1784. OpEntryPoint GLCompute %2 "main"
  1785. OpExecutionMode %2 LocalSize 1 1 1
  1786. OpSource GLSL 450
  1787. OpMemberDecorate %_struct_3 0 Offset 0
  1788. OpMemberDecorate %_struct_3 1 Offset 4
  1789. %void = OpTypeVoid
  1790. %5 = OpTypeFunction %void
  1791. %int = OpTypeInt 32 1
  1792. %bool = OpTypeBool
  1793. %_struct_3 = OpTypeStruct %int %int
  1794. %_ptr_Function__struct_3 = OpTypePointer Function %_struct_3
  1795. %_ptr_Function_int = OpTypePointer Function %int
  1796. %true = OpConstantTrue %bool
  1797. %int_0 = OpConstant %int 0
  1798. %int_1 = OpConstant %int 1
  1799. %13 = OpConstantNull %_struct_3
  1800. %2 = OpFunction %void None %5
  1801. %14 = OpLabel
  1802. %15 = OpVariable %_ptr_Function_int Function
  1803. %16 = OpVariable %_ptr_Function_int Function
  1804. %17 = OpVariable %_ptr_Function_int Function
  1805. OpStore %15 %int_1
  1806. OpStore %17 %int_0
  1807. OpSelectionMerge %18 None
  1808. OpBranchConditional %true %19 %20
  1809. %19 = OpLabel
  1810. OpBranch %18
  1811. %20 = OpLabel
  1812. OpBranch %18
  1813. %18 = OpLabel
  1814. %21 = OpPhi %_ptr_Function_int %15 %19 %16 %20
  1815. OpStore %21 %int_0
  1816. %22 = OpLoad %int %15
  1817. %23 = OpLoad %int %17
  1818. %24 = OpIAdd %int %22 %23
  1819. OpReturn
  1820. OpFunctionEnd
  1821. )";
  1822. SinglePassRunAndMatch<SSARewritePass>(text, false);
  1823. }
  1824. TEST_F(LocalSSAElimTest, ChainedTrivialPhis) {
  1825. // Check that the copy object get the undef value implicitly assigned in the
  1826. // entry block.
  1827. const std::string text = R"(
  1828. ; CHECK: [[undef:%\w+]] = OpUndef %v4float
  1829. ; CHECK: OpCopyObject %v4float [[undef]]
  1830. OpCapability Shader
  1831. %1 = OpExtInstImport "GLSL.std.450"
  1832. OpMemoryModel Logical GLSL450
  1833. OpEntryPoint GLCompute %2 "main"
  1834. OpExecutionMode %2 LocalSize 1 18 6
  1835. OpSource ESSL 310
  1836. %void = OpTypeVoid
  1837. %4 = OpTypeFunction %void
  1838. %bool = OpTypeBool
  1839. %float = OpTypeFloat 32
  1840. %v4float = OpTypeVector %float 4
  1841. %_ptr_Function_v4float = OpTypePointer Function %v4float
  1842. %2 = OpFunction %void None %4
  1843. %9 = OpLabel
  1844. %10 = OpVariable %_ptr_Function_v4float Function
  1845. OpBranch %11
  1846. %11 = OpLabel
  1847. OpLoopMerge %12 %13 None
  1848. OpBranch %14
  1849. %14 = OpLabel
  1850. %15 = OpUndef %bool
  1851. OpBranchConditional %15 %16 %12
  1852. %16 = OpLabel
  1853. %17 = OpUndef %bool
  1854. OpSelectionMerge %18 None
  1855. OpBranchConditional %17 %19 %18
  1856. %19 = OpLabel
  1857. %20 = OpUndef %bool
  1858. OpLoopMerge %21 %22 None
  1859. OpBranchConditional %20 %23 %21
  1860. %23 = OpLabel
  1861. %24 = OpLoad %v4float %10
  1862. %25 = OpCopyObject %v4float %24
  1863. %26 = OpUndef %bool
  1864. OpBranch %22
  1865. %22 = OpLabel
  1866. OpBranch %19
  1867. %21 = OpLabel
  1868. OpBranch %12
  1869. %18 = OpLabel
  1870. OpBranch %13
  1871. %13 = OpLabel
  1872. OpBranch %11
  1873. %12 = OpLabel
  1874. %27 = OpLoad %v4float %10
  1875. OpReturn
  1876. OpFunctionEnd
  1877. )";
  1878. SinglePassRunAndMatch<SSARewritePass>(text, false);
  1879. }
  1880. TEST_F(LocalSSAElimTest, Overflowtest1) {
  1881. // Check that the copy object get the undef value implicitly assigned in the
  1882. // entry block.
  1883. const std::string text = R"(
  1884. OpCapability Geometry
  1885. OpMemoryModel Logical GLSL450
  1886. OpEntryPoint Fragment %4 "P2Mai" %12 %17
  1887. OpExecutionMode %4 OriginUpperLeft
  1888. %2 = OpTypeVoid
  1889. %3 = OpTypeFunction %2
  1890. %6 = OpTypeFloat 32
  1891. %7 = OpTypeVector %6 4
  1892. %11 = OpTypePointer Input %7
  1893. %16 = OpTypePointer Output %7
  1894. %23 = OpTypePointer Function %7
  1895. %12 = OpVariable %11 Input
  1896. %17 = OpVariable %16 Output
  1897. %4 = OpFunction %2 None %3
  1898. %2177 = OpLabel
  1899. %4194302 = OpVariable %23 Function
  1900. %4194301 = OpLoad %7 %4194302
  1901. OpStore %17 %4194301
  1902. OpReturn
  1903. OpFunctionEnd
  1904. )";
  1905. SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  1906. std::vector<Message> messages = {
  1907. {SPV_MSG_ERROR, "", 0, 0, "ID overflow. Try running compact-ids."}};
  1908. SetMessageConsumer(GetTestMessageConsumer(messages));
  1909. auto result = SinglePassRunToBinary<SSARewritePass>(text, true);
  1910. EXPECT_EQ(Pass::Status::Failure, std::get<1>(result));
  1911. }
  1912. TEST_F(LocalSSAElimTest, OpConstantNull) {
  1913. const std::string text = R"(
  1914. OpCapability Addresses
  1915. OpCapability Kernel
  1916. OpCapability Int64
  1917. OpMemoryModel Physical64 OpenCL
  1918. OpEntryPoint Kernel %4 "A"
  1919. OpSource OpenCL_C 200000
  1920. %2 = OpTypeVoid
  1921. %3 = OpTypeFunction %2
  1922. %6 = OpTypeInt 32 0
  1923. %11 = OpTypePointer CrossWorkgroup %6
  1924. %16 = OpConstantNull %11
  1925. %20 = OpConstant %6 269484031
  1926. %4 = OpFunction %2 None %3
  1927. %17 = OpLabel
  1928. %18 = OpLoad %6 %16 Aligned 536870912
  1929. %19 = OpBitwiseXor %6 %18 %20
  1930. OpStore %16 %19 Aligned 536870912
  1931. OpReturn
  1932. OpFunctionEnd
  1933. )";
  1934. SinglePassRunToBinary<SSARewritePass>(text, false);
  1935. }
  1936. TEST_F(LocalSSAElimTest, DebugForLoop) {
  1937. // #version 140
  1938. //
  1939. // in vec4 BC;
  1940. // out float fo;
  1941. //
  1942. // void main()
  1943. // {
  1944. // float f = 0.0;
  1945. // for (int i=0; i<4; i++) {
  1946. // f = f + BC[i];
  1947. // }
  1948. // fo = f;
  1949. // }
  1950. const std::string text = R"(
  1951. ; CHECK: [[f_name:%\w+]] = OpString "f"
  1952. ; CHECK: [[i_name:%\w+]] = OpString "i"
  1953. ; CHECK: [[dbg_f:%\w+]] = OpExtInst %void [[ext:%\d+]] DebugLocalVariable [[f_name]]
  1954. ; CHECK: [[dbg_i:%\w+]] = OpExtInst %void [[ext]] DebugLocalVariable [[i_name]]
  1955. ; CHECK: OpStore %f %float_0
  1956. ; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_f]] %float_0
  1957. ; CHECK-NEXT: OpStore %i %int_0
  1958. ; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_i]] %int_0
  1959. ; CHECK-NOT: DebugDeclare
  1960. ; CHECK: [[loop_head:%\w+]] = OpLabel
  1961. ; CHECK: [[phi0:%\w+]] = OpPhi %float %float_0
  1962. ; CHECK: [[phi1:%\w+]] = OpPhi %int %int_0
  1963. ; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_f]] [[phi0]]
  1964. ; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_i]] [[phi1]]
  1965. ; CHECK: OpLoopMerge [[loop_merge:%\w+]] [[loop_cont:%\w+]] None
  1966. ; CHECK-NEXT: OpBranch [[loop_body:%\w+]]
  1967. ; CHECK-NEXT: [[loop_body]] = OpLabel
  1968. ; CHECK: OpBranchConditional {{%\w+}} [[bb:%\w+]] [[loop_merge]]
  1969. ; CHECK: [[bb]] = OpLabel
  1970. ; CHECK: OpStore %f [[f_val:%\w+]]
  1971. ; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_f]] [[f_val]]
  1972. ; CHECK-NEXT: OpBranch [[loop_cont]]
  1973. ; CHECK: [[loop_cont]] = OpLabel
  1974. ; CHECK: OpStore %i [[i_val:%\w+]]
  1975. ; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_i]] [[i_val]]
  1976. ; CHECK-NEXT: OpBranch [[loop_head]]
  1977. ; CHECK: [[loop_merge]] = OpLabel
  1978. OpCapability Shader
  1979. %1 = OpExtInstImport "GLSL.std.450"
  1980. %ext = OpExtInstImport "OpenCL.DebugInfo.100"
  1981. OpMemoryModel Logical GLSL450
  1982. OpEntryPoint Fragment %main "main" %BC %fo
  1983. OpExecutionMode %main OriginUpperLeft
  1984. %file_name = OpString "test"
  1985. OpSource GLSL 140
  1986. %float_name = OpString "float"
  1987. %main_name = OpString "main"
  1988. %f_name = OpString "f"
  1989. %i_name = OpString "i"
  1990. OpName %main "main"
  1991. OpName %f "f"
  1992. OpName %i "i"
  1993. OpName %BC "BC"
  1994. OpName %fo "fo"
  1995. %void = OpTypeVoid
  1996. %8 = OpTypeFunction %void
  1997. %float = OpTypeFloat 32
  1998. %_ptr_Function_float = OpTypePointer Function %float
  1999. %float_0 = OpConstant %float 0
  2000. %int = OpTypeInt 32 1
  2001. %uint = OpTypeInt 32 0
  2002. %uint_32 = OpConstant %uint 32
  2003. %_ptr_Function_int = OpTypePointer Function %int
  2004. %int_0 = OpConstant %int 0
  2005. %int_4 = OpConstant %int 4
  2006. %bool = OpTypeBool
  2007. %v4float = OpTypeVector %float 4
  2008. %_ptr_Input_v4float = OpTypePointer Input %v4float
  2009. %BC = OpVariable %_ptr_Input_v4float Input
  2010. %_ptr_Input_float = OpTypePointer Input %float
  2011. %int_1 = OpConstant %int 1
  2012. %_ptr_Output_float = OpTypePointer Output %float
  2013. %fo = OpVariable %_ptr_Output_float Output
  2014. %null_expr = OpExtInst %void %ext DebugExpression
  2015. %src = OpExtInst %void %ext DebugSource %file_name
  2016. %cu = OpExtInst %void %ext DebugCompilationUnit 1 4 %src HLSL
  2017. %dbg_tf = OpExtInst %void %ext DebugTypeBasic %float_name %uint_32 Float
  2018. %dbg_v4f = OpExtInst %void %ext DebugTypeVector %dbg_tf 4
  2019. %main_ty = OpExtInst %void %ext DebugTypeFunction FlagIsProtected|FlagIsPrivate %dbg_v4f %dbg_v4f
  2020. %dbg_main = OpExtInst %void %ext DebugFunction %main_name %main_ty %src 0 0 %cu %main_name FlagIsProtected|FlagIsPrivate 10 %main
  2021. %dbg_f = OpExtInst %void %ext DebugLocalVariable %f_name %dbg_v4f %src 0 0 %dbg_main FlagIsLocal
  2022. %dbg_i = OpExtInst %void %ext DebugLocalVariable %i_name %dbg_v4f %src 0 0 %dbg_main FlagIsLocal
  2023. %main = OpFunction %void None %8
  2024. %22 = OpLabel
  2025. %s0 = OpExtInst %void %ext DebugScope %dbg_main
  2026. %f = OpVariable %_ptr_Function_float Function
  2027. %i = OpVariable %_ptr_Function_int Function
  2028. OpStore %f %float_0
  2029. OpStore %i %int_0
  2030. %decl0 = OpExtInst %void %ext DebugDeclare %dbg_f %f %null_expr
  2031. %decl1 = OpExtInst %void %ext DebugDeclare %dbg_i %i %null_expr
  2032. OpBranch %23
  2033. %23 = OpLabel
  2034. %s1 = OpExtInst %void %ext DebugScope %dbg_main
  2035. OpLoopMerge %24 %25 None
  2036. OpBranch %26
  2037. %26 = OpLabel
  2038. %s2 = OpExtInst %void %ext DebugScope %dbg_main
  2039. %27 = OpLoad %int %i
  2040. %28 = OpSLessThan %bool %27 %int_4
  2041. OpBranchConditional %28 %29 %24
  2042. %29 = OpLabel
  2043. %s3 = OpExtInst %void %ext DebugScope %dbg_main
  2044. %30 = OpLoad %float %f
  2045. %31 = OpLoad %int %i
  2046. %32 = OpAccessChain %_ptr_Input_float %BC %31
  2047. %33 = OpLoad %float %32
  2048. %34 = OpFAdd %float %30 %33
  2049. OpStore %f %34
  2050. OpBranch %25
  2051. %25 = OpLabel
  2052. %s4 = OpExtInst %void %ext DebugScope %dbg_main
  2053. %35 = OpLoad %int %i
  2054. %36 = OpIAdd %int %35 %int_1
  2055. OpStore %i %36
  2056. OpBranch %23
  2057. %24 = OpLabel
  2058. %s5 = OpExtInst %void %ext DebugScope %dbg_main
  2059. %37 = OpLoad %float %f
  2060. OpStore %fo %37
  2061. OpReturn
  2062. OpFunctionEnd
  2063. )";
  2064. SinglePassRunAndMatch<SSARewritePass>(text, true);
  2065. }
  2066. TEST_F(LocalSSAElimTest, ShaderDebugForLoop) {
  2067. const std::string text = R"(
  2068. ; CHECK: [[f_name:%\w+]] = OpString "f"
  2069. ; CHECK: [[i_name:%\w+]] = OpString "i"
  2070. ; CHECK: [[dbg_f:%\w+]] = OpExtInst %void [[ext:%\d+]] DebugLocalVariable [[f_name]]
  2071. ; CHECK: [[dbg_i:%\w+]] = OpExtInst %void [[ext]] DebugLocalVariable [[i_name]]
  2072. ; CHECK: OpStore %f %float_0
  2073. ; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_f]] %float_0
  2074. ; CHECK-NEXT: OpStore %i %int_0
  2075. ; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_i]] %int_0
  2076. ; CHECK-NOT: DebugDeclare
  2077. ; CHECK: [[loop_head:%\w+]] = OpLabel
  2078. ; CHECK: [[phi0:%\w+]] = OpPhi %float %float_0
  2079. ; CHECK: [[phi1:%\w+]] = OpPhi %int %int_0
  2080. ; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_f]] [[phi0]]
  2081. ; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_i]] [[phi1]]
  2082. ; CHECK: OpLoopMerge [[loop_merge:%\w+]] [[loop_cont:%\w+]] None
  2083. ; CHECK-NEXT: OpBranch [[loop_body:%\w+]]
  2084. ; CHECK-NEXT: [[loop_body]] = OpLabel
  2085. ; CHECK: OpBranchConditional {{%\w+}} [[bb:%\w+]] [[loop_merge]]
  2086. ; CHECK: [[bb]] = OpLabel
  2087. ; CHECK: OpStore %f [[f_val:%\w+]]
  2088. ; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_f]] [[f_val]]
  2089. ; CHECK-NEXT: OpBranch [[loop_cont]]
  2090. ; CHECK: [[loop_cont]] = OpLabel
  2091. ; CHECK: OpStore %i [[i_val:%\w+]]
  2092. ; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_i]] [[i_val]]
  2093. ; CHECK-NEXT: OpBranch [[loop_head]]
  2094. ; CHECK: [[loop_merge]] = OpLabel
  2095. OpCapability Shader
  2096. OpExtension "SPV_KHR_non_semantic_info"
  2097. %1 = OpExtInstImport "GLSL.std.450"
  2098. %ext = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
  2099. OpMemoryModel Logical GLSL450
  2100. OpEntryPoint Fragment %main "main" %BC %fo
  2101. OpExecutionMode %main OriginUpperLeft
  2102. %file_name = OpString "test"
  2103. OpSource GLSL 140
  2104. %float_name = OpString "float"
  2105. %main_name = OpString "main"
  2106. %f_name = OpString "f"
  2107. %i_name = OpString "i"
  2108. OpName %main "main"
  2109. OpName %f "f"
  2110. OpName %i "i"
  2111. OpName %BC "BC"
  2112. OpName %fo "fo"
  2113. %void = OpTypeVoid
  2114. %8 = OpTypeFunction %void
  2115. %float = OpTypeFloat 32
  2116. %_ptr_Function_float = OpTypePointer Function %float
  2117. %float_0 = OpConstant %float 0
  2118. %int = OpTypeInt 32 1
  2119. %uint = OpTypeInt 32 0
  2120. %uint_0 = OpConstant %uint 0
  2121. %uint_1 = OpConstant %uint 1
  2122. %uint_3 = OpConstant %uint 3
  2123. %uint_4 = OpConstant %uint 4
  2124. %uint_5 = OpConstant %uint 5
  2125. %uint_10 = OpConstant %uint 10
  2126. %uint_32 = OpConstant %uint 32
  2127. %_ptr_Function_int = OpTypePointer Function %int
  2128. %int_0 = OpConstant %int 0
  2129. %int_4 = OpConstant %int 4
  2130. %bool = OpTypeBool
  2131. %v4float = OpTypeVector %float 4
  2132. %_ptr_Input_v4float = OpTypePointer Input %v4float
  2133. %BC = OpVariable %_ptr_Input_v4float Input
  2134. %_ptr_Input_float = OpTypePointer Input %float
  2135. %int_1 = OpConstant %int 1
  2136. %_ptr_Output_float = OpTypePointer Output %float
  2137. %fo = OpVariable %_ptr_Output_float Output
  2138. %null_expr = OpExtInst %void %ext DebugExpression
  2139. %src = OpExtInst %void %ext DebugSource %file_name
  2140. %cu = OpExtInst %void %ext DebugCompilationUnit %uint_1 %uint_4 %src %uint_5
  2141. %dbg_tf = OpExtInst %void %ext DebugTypeBasic %float_name %uint_32 %uint_3 %uint_0
  2142. %dbg_v4f = OpExtInst %void %ext DebugTypeVector %dbg_tf %uint_4
  2143. %main_ty = OpExtInst %void %ext DebugTypeFunction %uint_3 %dbg_v4f %dbg_v4f
  2144. %dbg_main = OpExtInst %void %ext DebugFunction %main_name %main_ty %src %uint_0 %uint_0 %cu %main_name %uint_3 %uint_10
  2145. %dbg_f = OpExtInst %void %ext DebugLocalVariable %f_name %dbg_v4f %src %uint_0 %uint_0 %dbg_main %uint_4
  2146. %dbg_i = OpExtInst %void %ext DebugLocalVariable %i_name %dbg_v4f %src %uint_0 %uint_0 %dbg_main %uint_4
  2147. %main = OpFunction %void None %8
  2148. %22 = OpLabel
  2149. %s0 = OpExtInst %void %ext DebugScope %dbg_main
  2150. %f = OpVariable %_ptr_Function_float Function
  2151. %i = OpVariable %_ptr_Function_int Function
  2152. OpStore %f %float_0
  2153. OpStore %i %int_0
  2154. %decl0 = OpExtInst %void %ext DebugDeclare %dbg_f %f %null_expr
  2155. %decl1 = OpExtInst %void %ext DebugDeclare %dbg_i %i %null_expr
  2156. OpBranch %23
  2157. %23 = OpLabel
  2158. %s1 = OpExtInst %void %ext DebugScope %dbg_main
  2159. OpLoopMerge %24 %25 None
  2160. OpBranch %26
  2161. %26 = OpLabel
  2162. %s2 = OpExtInst %void %ext DebugScope %dbg_main
  2163. %27 = OpLoad %int %i
  2164. %28 = OpSLessThan %bool %27 %int_4
  2165. OpBranchConditional %28 %29 %24
  2166. %29 = OpLabel
  2167. %s3 = OpExtInst %void %ext DebugScope %dbg_main
  2168. %30 = OpLoad %float %f
  2169. %31 = OpLoad %int %i
  2170. %32 = OpAccessChain %_ptr_Input_float %BC %31
  2171. %33 = OpLoad %float %32
  2172. %34 = OpFAdd %float %30 %33
  2173. OpStore %f %34
  2174. OpBranch %25
  2175. %25 = OpLabel
  2176. %s4 = OpExtInst %void %ext DebugScope %dbg_main
  2177. %35 = OpLoad %int %i
  2178. %36 = OpIAdd %int %35 %int_1
  2179. OpStore %i %36
  2180. OpBranch %23
  2181. %24 = OpLabel
  2182. %s5 = OpExtInst %void %ext DebugScope %dbg_main
  2183. %37 = OpLoad %float %f
  2184. OpStore %fo %37
  2185. OpReturn
  2186. OpFunctionEnd
  2187. )";
  2188. SinglePassRunAndMatch<SSARewritePass>(text, true);
  2189. }
  2190. TEST_F(LocalSSAElimTest, AddDebugValueForFunctionParameterWithPhi) {
  2191. // Test the distribution of DebugValue for a parameter of an inlined function
  2192. // and the visibility of Phi instruction. The ssa-rewrite pass must add
  2193. // DebugValue for the value assignment of function argument even when it is an
  2194. // inlined function. It has to check the visibility Phi through all its value
  2195. // operands. See the DebugValue for "int i" of "foo()" in the following code.
  2196. //
  2197. // struct VS_OUTPUT {
  2198. // float4 pos : SV_POSITION;
  2199. // float4 color : COLOR;
  2200. // };
  2201. //
  2202. // float4 foo(int i, float4 pos) {
  2203. // while (i < pos.x) {
  2204. // pos = pos.x + i;
  2205. // ++i;
  2206. // }
  2207. // return pos;
  2208. // }
  2209. //
  2210. // VS_OUTPUT main(float4 pos : POSITION,
  2211. // float4 color : COLOR) {
  2212. // VS_OUTPUT vout;
  2213. // vout.pos = foo(4, pos);
  2214. // vout.color = color;
  2215. // return vout;
  2216. // }
  2217. const std::string text = R"(
  2218. OpCapability Shader
  2219. %1 = OpExtInstImport "OpenCL.DebugInfo.100"
  2220. OpMemoryModel Logical GLSL450
  2221. OpEntryPoint Vertex %main "main" %in_var_POSITION %in_var_COLOR %gl_Position %out_var_COLOR
  2222. %7 = OpString "vertex.hlsl"
  2223. %8 = OpString "float"
  2224. %9 = OpString "VS_OUTPUT"
  2225. %10 = OpString "color"
  2226. %11 = OpString "pos"
  2227. %12 = OpString "int"
  2228. %13 = OpString "foo"
  2229. %14 = OpString ""
  2230. %15 = OpString "i"
  2231. %16 = OpString "main"
  2232. %17 = OpString "vout"
  2233. OpName %in_var_POSITION "in.var.POSITION"
  2234. OpName %in_var_COLOR "in.var.COLOR"
  2235. OpName %out_var_COLOR "out.var.COLOR"
  2236. OpName %main "main"
  2237. OpName %param_var_pos "param.var.pos"
  2238. OpName %param_var_color "param.var.color"
  2239. OpName %VS_OUTPUT "VS_OUTPUT"
  2240. OpMemberName %VS_OUTPUT 0 "pos"
  2241. OpMemberName %VS_OUTPUT 1 "color"
  2242. OpDecorate %gl_Position BuiltIn Position
  2243. OpDecorate %in_var_POSITION Location 0
  2244. OpDecorate %in_var_COLOR Location 1
  2245. OpDecorate %out_var_COLOR Location 0
  2246. %int = OpTypeInt 32 1
  2247. %int_4 = OpConstant %int 4
  2248. %int_0 = OpConstant %int 0
  2249. %int_1 = OpConstant %int 1
  2250. %uint = OpTypeInt 32 0
  2251. %uint_32 = OpConstant %uint 32
  2252. %float = OpTypeFloat 32
  2253. %v4float = OpTypeVector %float 4
  2254. %_ptr_Input_v4float = OpTypePointer Input %v4float
  2255. %_ptr_Output_v4float = OpTypePointer Output %v4float
  2256. %void = OpTypeVoid
  2257. %uint_256 = OpConstant %uint 256
  2258. %uint_128 = OpConstant %uint 128
  2259. %uint_0 = OpConstant %uint 0
  2260. %50 = OpTypeFunction %void
  2261. %_ptr_Function_v4float = OpTypePointer Function %v4float
  2262. %VS_OUTPUT = OpTypeStruct %v4float %v4float
  2263. %_ptr_Function_int = OpTypePointer Function %int
  2264. %_ptr_Function_float = OpTypePointer Function %float
  2265. %bool = OpTypeBool
  2266. %in_var_POSITION = OpVariable %_ptr_Input_v4float Input
  2267. %in_var_COLOR = OpVariable %_ptr_Input_v4float Input
  2268. %gl_Position = OpVariable %_ptr_Output_v4float Output
  2269. %out_var_COLOR = OpVariable %_ptr_Output_v4float Output
  2270. %156 = OpExtInst %void %1 DebugInfoNone
  2271. %77 = OpExtInst %void %1 DebugExpression
  2272. %58 = OpExtInst %void %1 DebugTypeBasic %8 %uint_32 Float
  2273. %59 = OpExtInst %void %1 DebugTypeVector %58 4
  2274. %60 = OpExtInst %void %1 DebugSource %7
  2275. %61 = OpExtInst %void %1 DebugCompilationUnit 1 4 %60 HLSL
  2276. %62 = OpExtInst %void %1 DebugTypeComposite %9 Structure %60 1 8 %61 %9 %uint_256 FlagIsProtected|FlagIsPrivate %63 %64
  2277. %64 = OpExtInst %void %1 DebugTypeMember %10 %59 %60 3 10 %62 %uint_128 %uint_128 FlagIsProtected|FlagIsPrivate
  2278. %63 = OpExtInst %void %1 DebugTypeMember %11 %59 %60 2 10 %62 %uint_0 %uint_128 FlagIsProtected|FlagIsPrivate
  2279. %65 = OpExtInst %void %1 DebugTypeBasic %12 %uint_32 Signed
  2280. %66 = OpExtInst %void %1 DebugTypeFunction FlagIsProtected|FlagIsPrivate %59 %65 %59
  2281. %67 = OpExtInst %void %1 DebugFunction %13 %66 %60 6 1 %61 %14 FlagIsProtected|FlagIsPrivate 6 %156
  2282. %68 = OpExtInst %void %1 DebugLexicalBlock %60 6 31 %67
  2283. %69 = OpExtInst %void %1 DebugLexicalBlock %60 7 21 %68
  2284. %70 = OpExtInst %void %1 DebugLocalVariable %11 %59 %60 6 26 %67 FlagIsLocal 2
  2285. ; CHECK: [[color_name:%\w+]] = OpString "color"
  2286. ; CHECK: [[pos_name:%\w+]] = OpString "pos"
  2287. ; CHECK: [[i_name:%\w+]] = OpString "i"
  2288. ; CHECK: [[null_expr:%\w+]] = OpExtInst %void [[ext:%\w+]] DebugExpression
  2289. ; CHECK: [[dbg_i:%\w+]] = OpExtInst %void [[ext]] DebugLocalVariable [[i_name]] {{%\w+}} {{%\w+}} 6 16 {{%\w+}} FlagIsLocal 1
  2290. ; CHECK: [[dbg_color:%\w+]] = OpExtInst %void [[ext]] DebugLocalVariable [[color_name]] {{%\w+}} {{%\w+}} 15 23
  2291. ; CHECK: [[dbg_pos:%\w+]] = OpExtInst %void [[ext]] DebugLocalVariable [[pos_name]] {{%\w+}} {{%\w+}} 14 23
  2292. %71 = OpExtInst %void %1 DebugLocalVariable %15 %65 %60 6 16 %67 FlagIsLocal 1
  2293. %72 = OpExtInst %void %1 DebugTypeFunction FlagIsProtected|FlagIsPrivate %62 %59 %59
  2294. %73 = OpExtInst %void %1 DebugFunction %16 %72 %60 14 1 %61 %14 FlagIsProtected|FlagIsPrivate 15 %156
  2295. %74 = OpExtInst %void %1 DebugLexicalBlock %60 15 38 %73
  2296. %75 = OpExtInst %void %1 DebugLocalVariable %17 %62 %60 16 13 %74 FlagIsLocal
  2297. %76 = OpExtInst %void %1 DebugLocalVariable %10 %59 %60 15 23 %73 FlagIsLocal 2
  2298. %78 = OpExtInst %void %1 DebugLocalVariable %11 %59 %60 14 23 %73 FlagIsLocal 1
  2299. %155 = OpExtInst %void %1 DebugInlinedAt 17 %74
  2300. %main = OpFunction %void None %50
  2301. %79 = OpLabel
  2302. %168 = OpExtInst %void %1 DebugScope %74
  2303. ; CHECK: [[i:%\w+]] = OpVariable %_ptr_Function_int Function
  2304. %120 = OpVariable %_ptr_Function_int Function
  2305. %121 = OpVariable %_ptr_Function_v4float Function
  2306. %169 = OpExtInst %void %1 DebugNoScope
  2307. %param_var_pos = OpVariable %_ptr_Function_v4float Function
  2308. %param_var_color = OpVariable %_ptr_Function_v4float Function
  2309. OpLine %7 100 105
  2310. %80 = OpLoad %v4float %in_var_POSITION
  2311. OpStore %param_var_pos %80
  2312. OpNoLine
  2313. OpLine %7 200 205
  2314. %81 = OpLoad %v4float %in_var_COLOR
  2315. OpStore %param_var_color %81
  2316. OpNoLine
  2317. %170 = OpExtInst %void %1 DebugScope %73
  2318. ; CHECK: OpLine {{%\w+}} 100 105
  2319. ; CHECK: DebugValue [[dbg_pos]]
  2320. %124 = OpExtInst %void %1 DebugDeclare %78 %param_var_pos %77
  2321. ; CHECK: OpLine {{%\w+}} 200 205
  2322. ; CHECK: DebugValue [[dbg_color]]
  2323. %125 = OpExtInst %void %1 DebugDeclare %76 %param_var_color %77
  2324. %171 = OpExtInst %void %1 DebugScope %74
  2325. OpLine %7 17 18
  2326. ; CHECK: OpStore {{%\w+}} %int_4
  2327. ; CHECK: DebugValue [[dbg_i]] %int_4 [[null_expr]]
  2328. OpStore %120 %int_4
  2329. OpStore %121 %80
  2330. %172 = OpExtInst %void %1 DebugScope %67 %155
  2331. %135 = OpExtInst %void %1 DebugDeclare %71 %120 %77
  2332. %136 = OpExtInst %void %1 DebugDeclare %70 %121 %77
  2333. %173 = OpExtInst %void %1 DebugScope %68 %155
  2334. OpLine %7 7 3
  2335. OpBranch %137
  2336. %174 = OpExtInst %void %1 DebugNoScope
  2337. %137 = OpLabel
  2338. ; CHECK: [[phi:%\w+]] = OpPhi %int %int_4
  2339. ; CHECK: DebugValue [[dbg_i]] [[phi]] [[null_expr]]
  2340. %175 = OpExtInst %void %1 DebugScope %68 %155
  2341. OpLine %7 7 10
  2342. %138 = OpLoad %int %120
  2343. %139 = OpConvertSToF %float %138
  2344. OpLine %7 7 14
  2345. %140 = OpAccessChain %_ptr_Function_float %121 %int_0
  2346. %141 = OpLoad %float %140
  2347. OpLine %7 7 12
  2348. %142 = OpFOrdLessThan %bool %139 %141
  2349. OpLine %7 7 3
  2350. %176 = OpExtInst %void %1 DebugNoScope
  2351. OpLoopMerge %153 %152 None
  2352. OpBranchConditional %142 %143 %153
  2353. %177 = OpExtInst %void %1 DebugNoScope
  2354. %143 = OpLabel
  2355. %178 = OpExtInst %void %1 DebugScope %69 %155
  2356. OpLine %7 8 11
  2357. %144 = OpAccessChain %_ptr_Function_float %121 %int_0
  2358. %145 = OpLoad %float %144
  2359. OpLine %7 8 19
  2360. %146 = OpLoad %int %120
  2361. %147 = OpConvertSToF %float %146
  2362. OpLine %7 8 17
  2363. %148 = OpFAdd %float %145 %147
  2364. OpLine %7 8 11
  2365. %149 = OpCompositeConstruct %v4float %148 %148 %148 %148
  2366. OpLine %7 8 5
  2367. OpStore %121 %149
  2368. OpLine %7 9 5
  2369. %151 = OpIAdd %int %146 %int_1
  2370. OpLine %7 9 7
  2371. ; CHECK: OpStore [[i]] [[value:%\w+]]
  2372. ; CHECK: DebugValue [[dbg_i]] [[value]] [[null_expr]]
  2373. OpStore %120 %151
  2374. %179 = OpExtInst %void %1 DebugScope %68 %155
  2375. OpLine %7 10 3
  2376. OpBranch %152
  2377. %180 = OpExtInst %void %1 DebugNoScope
  2378. %152 = OpLabel
  2379. %181 = OpExtInst %void %1 DebugScope %68 %155
  2380. OpBranch %137
  2381. %182 = OpExtInst %void %1 DebugNoScope
  2382. %153 = OpLabel
  2383. %183 = OpExtInst %void %1 DebugScope %68 %155
  2384. OpLine %7 11 10
  2385. %154 = OpLoad %v4float %121
  2386. %184 = OpExtInst %void %1 DebugScope %74
  2387. %167 = OpExtInst %void %1 DebugValue %75 %154 %77 %int_0
  2388. %166 = OpExtInst %void %1 DebugValue %75 %81 %77 %int_1
  2389. OpLine %7 19 10
  2390. %165 = OpCompositeConstruct %VS_OUTPUT %154 %81
  2391. %185 = OpExtInst %void %1 DebugNoScope
  2392. %83 = OpCompositeExtract %v4float %165 0
  2393. OpStore %gl_Position %83
  2394. %84 = OpCompositeExtract %v4float %165 1
  2395. OpStore %out_var_COLOR %84
  2396. OpReturn
  2397. OpFunctionEnd
  2398. )";
  2399. SinglePassRunAndMatch<SSARewritePass>(text, true);
  2400. }
  2401. TEST_F(LocalSSAElimTest, DebugValueWithIndexesInForLoop) {
  2402. // #version 140
  2403. //
  2404. // in vec4 BC;
  2405. // out float fo;
  2406. //
  2407. // struct T {
  2408. // float a;
  2409. // float f;
  2410. // };
  2411. //
  2412. // struct value {
  2413. // int x;
  2414. // int y;
  2415. // T z;
  2416. // };
  2417. //
  2418. // void main()
  2419. // {
  2420. // value v;
  2421. // v.z.f = 0.0;
  2422. // for (int i=0; i<4; i++) {
  2423. // v.z.f = v.z.f + BC[i];
  2424. // }
  2425. // fo = v.z.f;
  2426. // }
  2427. const std::string text = R"(
  2428. ; CHECK: [[f_name:%\w+]] = OpString "f"
  2429. ; CHECK: [[dbg_f:%\w+]] = OpExtInst %void [[ext:%\d+]] DebugLocalVariable [[f_name]]
  2430. ; CHECK: OpStore %f %float_0
  2431. ; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_f]] %float_0 [[null_expr:%\d+]] %int_2 %int_1
  2432. ; CHECK-NOT: DebugDeclare
  2433. ; CHECK: [[loop_head:%\w+]] = OpLabel
  2434. ; CHECK: [[phi0:%\w+]] = OpPhi %float %float_0
  2435. ; CHECK: OpExtInst %void [[ext]] DebugValue [[dbg_f]] [[phi0]] [[null_expr]] %int_2 %int_1
  2436. ; CHECK: OpLoopMerge [[loop_merge:%\w+]] [[loop_cont:%\w+]] None
  2437. ; CHECK-NEXT: OpBranch [[loop_body:%\w+]]
  2438. ; CHECK-NEXT: [[loop_body]] = OpLabel
  2439. ; CHECK: OpBranchConditional {{%\w+}} [[bb:%\w+]] [[loop_merge]]
  2440. ; CHECK: [[bb]] = OpLabel
  2441. ; CHECK: OpStore %f [[f_val:%\w+]]
  2442. ; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_f]] [[f_val]] [[null_expr]] %int_2 %int_1
  2443. ; CHECK-NEXT: OpBranch [[loop_cont]]
  2444. ; CHECK: [[loop_cont]] = OpLabel
  2445. ; CHECK: OpBranch [[loop_head]]
  2446. ; CHECK: [[loop_merge]] = OpLabel
  2447. OpCapability Shader
  2448. %1 = OpExtInstImport "GLSL.std.450"
  2449. %ext = OpExtInstImport "OpenCL.DebugInfo.100"
  2450. OpMemoryModel Logical GLSL450
  2451. OpEntryPoint Fragment %main "main" %BC %fo
  2452. OpExecutionMode %main OriginUpperLeft
  2453. %file_name = OpString "test"
  2454. OpSource GLSL 140
  2455. %float_name = OpString "float"
  2456. %main_name = OpString "main"
  2457. %f_name = OpString "f"
  2458. %i_name = OpString "i"
  2459. OpName %main "main"
  2460. OpName %f "f"
  2461. OpName %i "i"
  2462. OpName %BC "BC"
  2463. OpName %fo "fo"
  2464. %void = OpTypeVoid
  2465. %8 = OpTypeFunction %void
  2466. %float = OpTypeFloat 32
  2467. %_ptr_Function_float = OpTypePointer Function %float
  2468. %float_0 = OpConstant %float 0
  2469. %int = OpTypeInt 32 1
  2470. %uint = OpTypeInt 32 0
  2471. %uint_32 = OpConstant %uint 32
  2472. %_ptr_Function_int = OpTypePointer Function %int
  2473. %int_0 = OpConstant %int 0
  2474. %int_4 = OpConstant %int 4
  2475. %bool = OpTypeBool
  2476. %v4float = OpTypeVector %float 4
  2477. %_ptr_Input_v4float = OpTypePointer Input %v4float
  2478. %BC = OpVariable %_ptr_Input_v4float Input
  2479. %_ptr_Input_float = OpTypePointer Input %float
  2480. %int_1 = OpConstant %int 1
  2481. %int_2 = OpConstant %int 2
  2482. %_ptr_Output_float = OpTypePointer Output %float
  2483. %fo = OpVariable %_ptr_Output_float Output
  2484. %deref = OpExtInst %void %ext DebugOperation Deref
  2485. %null_expr = OpExtInst %void %ext DebugExpression
  2486. %deref_expr = OpExtInst %void %ext DebugExpression %deref
  2487. %src = OpExtInst %void %ext DebugSource %file_name
  2488. %cu = OpExtInst %void %ext DebugCompilationUnit 1 4 %src HLSL
  2489. %dbg_tf = OpExtInst %void %ext DebugTypeBasic %float_name %uint_32 Float
  2490. %dbg_v4f = OpExtInst %void %ext DebugTypeVector %dbg_tf 4
  2491. %main_ty = OpExtInst %void %ext DebugTypeFunction FlagIsProtected|FlagIsPrivate %dbg_v4f %dbg_v4f
  2492. %dbg_main = OpExtInst %void %ext DebugFunction %main_name %main_ty %src 0 0 %cu %main_name FlagIsProtected|FlagIsPrivate 10 %main
  2493. %dbg_f = OpExtInst %void %ext DebugLocalVariable %f_name %dbg_v4f %src 0 0 %dbg_main FlagIsLocal
  2494. %dbg_i = OpExtInst %void %ext DebugLocalVariable %i_name %dbg_v4f %src 0 0 %dbg_main FlagIsLocal
  2495. %main = OpFunction %void None %8
  2496. %22 = OpLabel
  2497. %s0 = OpExtInst %void %ext DebugScope %dbg_main
  2498. %f = OpVariable %_ptr_Function_float Function
  2499. %i = OpVariable %_ptr_Function_int Function
  2500. OpStore %f %float_0
  2501. OpStore %i %int_0
  2502. %decl0 = OpExtInst %void %ext DebugValue %dbg_f %f %deref_expr %int_2 %int_1
  2503. %decl1 = OpExtInst %void %ext DebugDeclare %dbg_i %i %null_expr
  2504. OpBranch %23
  2505. %23 = OpLabel
  2506. %s1 = OpExtInst %void %ext DebugScope %dbg_main
  2507. OpLoopMerge %24 %25 None
  2508. OpBranch %26
  2509. %26 = OpLabel
  2510. %s2 = OpExtInst %void %ext DebugScope %dbg_main
  2511. %27 = OpLoad %int %i
  2512. %28 = OpSLessThan %bool %27 %int_4
  2513. OpBranchConditional %28 %29 %24
  2514. %29 = OpLabel
  2515. %s3 = OpExtInst %void %ext DebugScope %dbg_main
  2516. %30 = OpLoad %float %f
  2517. %31 = OpLoad %int %i
  2518. %32 = OpAccessChain %_ptr_Input_float %BC %31
  2519. %33 = OpLoad %float %32
  2520. %34 = OpFAdd %float %30 %33
  2521. OpStore %f %34
  2522. OpBranch %25
  2523. %25 = OpLabel
  2524. %s4 = OpExtInst %void %ext DebugScope %dbg_main
  2525. %35 = OpLoad %int %i
  2526. %36 = OpIAdd %int %35 %int_1
  2527. OpStore %i %36
  2528. OpBranch %23
  2529. %24 = OpLabel
  2530. %s5 = OpExtInst %void %ext DebugScope %dbg_main
  2531. %37 = OpLoad %float %f
  2532. OpStore %fo %37
  2533. OpReturn
  2534. OpFunctionEnd
  2535. )";
  2536. SinglePassRunAndMatch<SSARewritePass>(text, true);
  2537. }
  2538. TEST_F(LocalSSAElimTest, PartiallyKillDebugDeclare) {
  2539. // For a reference variable e.g., int i in the following example,
  2540. // we do not propagate DebugValue for a store or phi instruction
  2541. // out of the variable's scope. In that case, we should not remove
  2542. // DebugDeclare for the variable that we did not add its DebugValue.
  2543. //
  2544. // #version 140
  2545. //
  2546. // in vec4 BC;
  2547. // out float fo;
  2548. //
  2549. // int j;
  2550. // void main()
  2551. // {
  2552. // float f = 0.0;
  2553. // for (j=0; j<4; j++) {
  2554. // int& i = j;
  2555. // f = f + BC[i];
  2556. // }
  2557. // fo = f;
  2558. // }
  2559. const std::string text = R"(
  2560. ; CHECK: [[f_name:%\w+]] = OpString "f"
  2561. ; CHECK: [[i_name:%\w+]] = OpString "i"
  2562. ; CHECK: [[fn:%\w+]] = OpExtInst %void [[ext:%\d+]] DebugFunction
  2563. ; CHECK: [[bb:%\w+]] = OpExtInst %void [[ext]] DebugLexicalBlock
  2564. ; CHECK: [[dbg_f:%\w+]] = OpExtInst %void [[ext]] DebugLocalVariable [[f_name]] {{%\w+}} {{%\w+}} 0 0 [[fn]]
  2565. ; CHECK: [[dbg_i:%\w+]] = OpExtInst %void [[ext]] DebugLocalVariable [[i_name]] {{%\w+}} {{%\w+}} 0 0 [[bb]]
  2566. ; CHECK: OpStore %f %float_0
  2567. ; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_f]] %float_0
  2568. ; CHECK-NOT: DebugDeclare [[dbg_f]]
  2569. ; CHECK: OpExtInst %void [[ext]] DebugDeclare [[dbg_i]] %j
  2570. OpCapability Shader
  2571. %1 = OpExtInstImport "GLSL.std.450"
  2572. %ext = OpExtInstImport "OpenCL.DebugInfo.100"
  2573. OpMemoryModel Logical GLSL450
  2574. OpEntryPoint Fragment %main "main" %BC %fo
  2575. OpExecutionMode %main OriginUpperLeft
  2576. %file_name = OpString "test"
  2577. OpSource GLSL 140
  2578. %float_name = OpString "float"
  2579. %main_name = OpString "main"
  2580. %f_name = OpString "f"
  2581. %i_name = OpString "i"
  2582. %j_name = OpString "j"
  2583. OpName %main "main"
  2584. OpName %f "f"
  2585. OpName %j "j"
  2586. OpName %BC "BC"
  2587. OpName %fo "fo"
  2588. %void = OpTypeVoid
  2589. %8 = OpTypeFunction %void
  2590. %float = OpTypeFloat 32
  2591. %_ptr_Function_float = OpTypePointer Function %float
  2592. %float_0 = OpConstant %float 0
  2593. %int = OpTypeInt 32 1
  2594. %uint = OpTypeInt 32 0
  2595. %uint_32 = OpConstant %uint 32
  2596. %_ptr_Function_int = OpTypePointer Function %int
  2597. %_ptr_Private_int = OpTypePointer Private %int
  2598. %int_0 = OpConstant %int 0
  2599. %int_4 = OpConstant %int 4
  2600. %bool = OpTypeBool
  2601. %v4float = OpTypeVector %float 4
  2602. %_ptr_Input_v4float = OpTypePointer Input %v4float
  2603. %BC = OpVariable %_ptr_Input_v4float Input
  2604. %_ptr_Input_float = OpTypePointer Input %float
  2605. %int_1 = OpConstant %int 1
  2606. %_ptr_Output_float = OpTypePointer Output %float
  2607. %fo = OpVariable %_ptr_Output_float Output
  2608. %j = OpVariable %_ptr_Private_int Private
  2609. %null_expr = OpExtInst %void %ext DebugExpression
  2610. %src = OpExtInst %void %ext DebugSource %file_name
  2611. %cu = OpExtInst %void %ext DebugCompilationUnit 1 4 %src HLSL
  2612. %dbg_tf = OpExtInst %void %ext DebugTypeBasic %float_name %uint_32 Float
  2613. %dbg_v4f = OpExtInst %void %ext DebugTypeVector %dbg_tf 4
  2614. %main_ty = OpExtInst %void %ext DebugTypeFunction FlagIsProtected|FlagIsPrivate %dbg_v4f %dbg_v4f
  2615. %dbg_main = OpExtInst %void %ext DebugFunction %main_name %main_ty %src 0 0 %cu %main_name FlagIsProtected|FlagIsPrivate 10 %main
  2616. %bb = OpExtInst %void %ext DebugLexicalBlock %src 0 0 %dbg_main
  2617. %dbg_f = OpExtInst %void %ext DebugLocalVariable %f_name %dbg_v4f %src 0 0 %dbg_main FlagIsLocal
  2618. %dbg_i = OpExtInst %void %ext DebugLocalVariable %i_name %dbg_v4f %src 0 0 %bb FlagIsLocal
  2619. %dbg_j = OpExtInst %void %ext DebugGlobalVariable %j_name %dbg_v4f %src 0 0 %dbg_main %j_name %j FlagIsPrivate
  2620. %main = OpFunction %void None %8
  2621. %22 = OpLabel
  2622. %s0 = OpExtInst %void %ext DebugScope %dbg_main
  2623. %f = OpVariable %_ptr_Function_float Function
  2624. OpStore %f %float_0
  2625. OpStore %j %int_0
  2626. %decl0 = OpExtInst %void %ext DebugDeclare %dbg_f %f %null_expr
  2627. OpBranch %23
  2628. %23 = OpLabel
  2629. %s1 = OpExtInst %void %ext DebugScope %dbg_main
  2630. OpLoopMerge %24 %25 None
  2631. OpBranch %26
  2632. %26 = OpLabel
  2633. %s2 = OpExtInst %void %ext DebugScope %dbg_main
  2634. %27 = OpLoad %int %j
  2635. %28 = OpSLessThan %bool %27 %int_4
  2636. OpBranchConditional %28 %29 %24
  2637. %29 = OpLabel
  2638. %s3 = OpExtInst %void %ext DebugScope %bb
  2639. %decl1 = OpExtInst %void %ext DebugDeclare %dbg_i %j %null_expr
  2640. %30 = OpLoad %float %f
  2641. %31 = OpLoad %int %j
  2642. %32 = OpAccessChain %_ptr_Input_float %BC %31
  2643. %33 = OpLoad %float %32
  2644. %34 = OpFAdd %float %30 %33
  2645. OpStore %f %34
  2646. OpBranch %25
  2647. %25 = OpLabel
  2648. %s4 = OpExtInst %void %ext DebugScope %dbg_main
  2649. %35 = OpLoad %int %j
  2650. %36 = OpIAdd %int %35 %int_1
  2651. OpStore %j %36
  2652. OpBranch %23
  2653. %24 = OpLabel
  2654. %s5 = OpExtInst %void %ext DebugScope %dbg_main
  2655. %37 = OpLoad %float %f
  2656. OpStore %fo %37
  2657. OpReturn
  2658. OpFunctionEnd
  2659. )";
  2660. SinglePassRunAndMatch<SSARewritePass>(text, true);
  2661. }
  2662. TEST_F(LocalSSAElimTest, DebugValueForReferenceVariable) {
  2663. // #version 140
  2664. //
  2665. // in vec4 BC;
  2666. // out float fo;
  2667. //
  2668. // void main()
  2669. // {
  2670. // float f = 0.0;
  2671. // float& x = f;
  2672. // for (int i=0; i<4; i++) {
  2673. // x = x + BC[i];
  2674. // }
  2675. // fo = f;
  2676. // }
  2677. const std::string text = R"(
  2678. ; CHECK: [[f_name:%\w+]] = OpString "f"
  2679. ; CHECK: [[i_name:%\w+]] = OpString "i"
  2680. ; CHECK: [[x_name:%\w+]] = OpString "x"
  2681. ; CHECK: [[dbg_f:%\w+]] = OpExtInst %void [[ext:%\d+]] DebugLocalVariable [[f_name]]
  2682. ; CHECK: [[dbg_i:%\w+]] = OpExtInst %void [[ext]] DebugLocalVariable [[i_name]]
  2683. ; CHECK: [[dbg_x:%\w+]] = OpExtInst %void [[ext]] DebugLocalVariable [[x_name]]
  2684. ; CHECK: OpStore %f %float_0
  2685. ; CHECK-DAG: OpExtInst %void [[ext]] DebugValue [[dbg_f]] %float_0
  2686. ; CHECK-DAG: OpExtInst %void [[ext]] DebugValue [[dbg_x]] %float_0
  2687. ; CHECK: OpStore %i %int_0
  2688. ; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_i]] %int_0
  2689. ; CHECK-NOT: DebugDeclare
  2690. ; CHECK: [[loop_head:%\w+]] = OpLabel
  2691. ; CHECK: [[phi0:%\w+]] = OpPhi %float %float_0
  2692. ; CHECK: [[phi1:%\w+]] = OpPhi %int %int_0
  2693. ; CHECK-DAG: OpExtInst %void [[ext]] DebugValue [[dbg_f]] [[phi0]]
  2694. ; CHECK-DAG: OpExtInst %void [[ext]] DebugValue [[dbg_x]] [[phi0]]
  2695. ; CHECK: OpExtInst %void [[ext]] DebugValue [[dbg_i]] [[phi1]]
  2696. ; CHECK: OpLoopMerge [[loop_merge:%\w+]] [[loop_cont:%\w+]] None
  2697. ; CHECK-NEXT: OpBranch [[loop_body:%\w+]]
  2698. ; CHECK: [[loop_body]] = OpLabel
  2699. ; CHECK: OpBranchConditional {{%\w+}} [[bb:%\w+]] [[loop_merge]]
  2700. ; CHECK: [[bb]] = OpLabel
  2701. ; CHECK: OpStore %f [[f_val:%\w+]]
  2702. ; CHECK-DAG: OpExtInst %void [[ext]] DebugValue [[dbg_f]] [[f_val]]
  2703. ; CHECK-DAG: OpExtInst %void [[ext]] DebugValue [[dbg_x]] [[f_val]]
  2704. ; CHECK: OpBranch [[loop_cont]]
  2705. ; CHECK: [[loop_cont]] = OpLabel
  2706. ; CHECK: OpStore %i [[i_val:%\w+]]
  2707. ; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_i]] [[i_val]]
  2708. ; CHECK-NEXT: OpBranch [[loop_head]]
  2709. ; CHECK: [[loop_merge]] = OpLabel
  2710. OpCapability Shader
  2711. %1 = OpExtInstImport "GLSL.std.450"
  2712. %ext = OpExtInstImport "OpenCL.DebugInfo.100"
  2713. OpMemoryModel Logical GLSL450
  2714. OpEntryPoint Fragment %main "main" %BC %fo
  2715. OpExecutionMode %main OriginUpperLeft
  2716. %file_name = OpString "test"
  2717. OpSource GLSL 140
  2718. %float_name = OpString "float"
  2719. %main_name = OpString "main"
  2720. %f_name = OpString "f"
  2721. %i_name = OpString "i"
  2722. %x_name = OpString "x"
  2723. OpName %main "main"
  2724. OpName %f "f"
  2725. OpName %i "i"
  2726. OpName %BC "BC"
  2727. OpName %fo "fo"
  2728. %void = OpTypeVoid
  2729. %8 = OpTypeFunction %void
  2730. %float = OpTypeFloat 32
  2731. %_ptr_Function_float = OpTypePointer Function %float
  2732. %float_0 = OpConstant %float 0
  2733. %int = OpTypeInt 32 1
  2734. %uint = OpTypeInt 32 0
  2735. %uint_32 = OpConstant %uint 32
  2736. %_ptr_Function_int = OpTypePointer Function %int
  2737. %int_0 = OpConstant %int 0
  2738. %int_4 = OpConstant %int 4
  2739. %bool = OpTypeBool
  2740. %v4float = OpTypeVector %float 4
  2741. %_ptr_Input_v4float = OpTypePointer Input %v4float
  2742. %BC = OpVariable %_ptr_Input_v4float Input
  2743. %_ptr_Input_float = OpTypePointer Input %float
  2744. %int_1 = OpConstant %int 1
  2745. %_ptr_Output_float = OpTypePointer Output %float
  2746. %fo = OpVariable %_ptr_Output_float Output
  2747. %null_expr = OpExtInst %void %ext DebugExpression
  2748. %src = OpExtInst %void %ext DebugSource %file_name
  2749. %cu = OpExtInst %void %ext DebugCompilationUnit 1 4 %src HLSL
  2750. %dbg_tf = OpExtInst %void %ext DebugTypeBasic %float_name %uint_32 Float
  2751. %dbg_v4f = OpExtInst %void %ext DebugTypeVector %dbg_tf 4
  2752. %main_ty = OpExtInst %void %ext DebugTypeFunction FlagIsProtected|FlagIsPrivate %dbg_v4f %dbg_v4f
  2753. %dbg_main = OpExtInst %void %ext DebugFunction %main_name %main_ty %src 0 0 %cu %main_name FlagIsProtected|FlagIsPrivate 10 %main
  2754. %dbg_f = OpExtInst %void %ext DebugLocalVariable %f_name %dbg_v4f %src 0 0 %dbg_main FlagIsLocal
  2755. %dbg_i = OpExtInst %void %ext DebugLocalVariable %i_name %dbg_v4f %src 1 0 %dbg_main FlagIsLocal
  2756. %dbg_x = OpExtInst %void %ext DebugLocalVariable %x_name %dbg_v4f %src 2 0 %dbg_main FlagIsLocal
  2757. %main = OpFunction %void None %8
  2758. %22 = OpLabel
  2759. %s0 = OpExtInst %void %ext DebugScope %dbg_main
  2760. %f = OpVariable %_ptr_Function_float Function
  2761. %i = OpVariable %_ptr_Function_int Function
  2762. OpStore %f %float_0
  2763. OpStore %i %int_0
  2764. %decl0 = OpExtInst %void %ext DebugDeclare %dbg_f %f %null_expr
  2765. %decl1 = OpExtInst %void %ext DebugDeclare %dbg_i %i %null_expr
  2766. %decl2 = OpExtInst %void %ext DebugDeclare %dbg_x %f %null_expr
  2767. OpBranch %23
  2768. %23 = OpLabel
  2769. %s1 = OpExtInst %void %ext DebugScope %dbg_main
  2770. OpLoopMerge %24 %25 None
  2771. OpBranch %26
  2772. %26 = OpLabel
  2773. %s2 = OpExtInst %void %ext DebugScope %dbg_main
  2774. %27 = OpLoad %int %i
  2775. %28 = OpSLessThan %bool %27 %int_4
  2776. OpBranchConditional %28 %29 %24
  2777. %29 = OpLabel
  2778. %s3 = OpExtInst %void %ext DebugScope %dbg_main
  2779. %30 = OpLoad %float %f
  2780. %31 = OpLoad %int %i
  2781. %32 = OpAccessChain %_ptr_Input_float %BC %31
  2782. %33 = OpLoad %float %32
  2783. %34 = OpFAdd %float %30 %33
  2784. OpStore %f %34
  2785. OpBranch %25
  2786. %25 = OpLabel
  2787. %s4 = OpExtInst %void %ext DebugScope %dbg_main
  2788. %35 = OpLoad %int %i
  2789. %36 = OpIAdd %int %35 %int_1
  2790. OpStore %i %36
  2791. OpBranch %23
  2792. %24 = OpLabel
  2793. %s5 = OpExtInst %void %ext DebugScope %dbg_main
  2794. %37 = OpLoad %float %f
  2795. OpStore %fo %37
  2796. OpReturn
  2797. OpFunctionEnd
  2798. )";
  2799. SinglePassRunAndMatch<SSARewritePass>(text, true);
  2800. }
  2801. TEST_F(LocalSSAElimTest, DebugValueForReferenceVariableInBB) {
  2802. // #version 140
  2803. //
  2804. // in vec4 BC;
  2805. // out float fo;
  2806. //
  2807. // void main()
  2808. // {
  2809. // float f = 0.0;
  2810. // for (int i=0; i<4; i++) {
  2811. // float& x = f;
  2812. // x = x + BC[i];
  2813. // {
  2814. // x = x + BC[i];
  2815. // }
  2816. // }
  2817. // fo = f;
  2818. // }
  2819. const std::string text = R"(
  2820. ; CHECK: [[f_name:%\w+]] = OpString "f"
  2821. ; CHECK: [[i_name:%\w+]] = OpString "i"
  2822. ; CHECK: [[x_name:%\w+]] = OpString "x"
  2823. ; CHECK: [[dbg_main:%\w+]] = OpExtInst %void [[ext:%\d+]] DebugFunction
  2824. ; CHECK: [[dbg_bb:%\w+]] = OpExtInst %void [[ext]] DebugLexicalBlock
  2825. ; CHECK: [[dbg_bb_child:%\w+]] = OpExtInst %void [[ext]] DebugLexicalBlock
  2826. ; CHECK: [[dbg_f:%\w+]] = OpExtInst %void [[ext]] DebugLocalVariable [[f_name]]
  2827. ; CHECK: [[dbg_i:%\w+]] = OpExtInst %void [[ext]] DebugLocalVariable [[i_name]]
  2828. ; CHECK: [[dbg_x:%\w+]] = OpExtInst %void [[ext]] DebugLocalVariable [[x_name]]
  2829. ; CHECK: OpExtInst %void [[ext]] DebugScope [[dbg_main]]
  2830. ; CHECK: OpStore %f %float_0
  2831. ; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_x]] %float_0
  2832. ; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_f]] %float_0
  2833. ; CHECK-NEXT: OpStore %i %int_0
  2834. ; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_i]] %int_0
  2835. ; CHECK-NOT: DebugDeclare
  2836. ; CHECK: [[loop_head:%\w+]] = OpLabel
  2837. ; CHECK: OpExtInst %void [[ext]] DebugScope [[dbg_main]]
  2838. ; CHECK: [[phi0:%\w+]] = OpPhi %float %float_0
  2839. ; CHECK: [[phi1:%\w+]] = OpPhi %int %int_0
  2840. ; CHECK-DAG: OpExtInst %void [[ext]] DebugValue [[dbg_f]] [[phi0]]
  2841. ; CHECK-DAG: OpExtInst %void [[ext]] DebugValue [[dbg_x]] [[phi0]]
  2842. ; CHECK-DAG: OpExtInst %void [[ext]] DebugValue [[dbg_i]] [[phi1]]
  2843. ; CHECK: OpLoopMerge [[loop_merge:%\w+]] [[loop_cont:%\w+]] None
  2844. ; CHECK-NEXT: OpBranch [[loop_body:%\w+]]
  2845. ; CHECK-NEXT: [[loop_body]] = OpLabel
  2846. ; CHECK: OpBranchConditional {{%\w+}} [[bb:%\w+]] [[loop_merge]]
  2847. ; CHECK: [[bb]] = OpLabel
  2848. ; CHECK: OpExtInst %void [[ext]] DebugScope [[dbg_bb]]
  2849. ; CHECK: OpStore %f [[f_val:%\w+]]
  2850. ; CHECK-DAG: OpExtInst %void [[ext]] DebugValue [[dbg_f]] [[f_val]]
  2851. ; CHECK-DAG: OpExtInst %void [[ext]] DebugValue [[dbg_x]] [[f_val]]
  2852. ; CHECK: OpBranch [[bb_child:%\w+]]
  2853. ; CHECK: [[bb_child]] = OpLabel
  2854. ; CHECK: OpExtInst %void [[ext]] DebugScope [[dbg_bb_child]]
  2855. ; CHECK: OpStore %f [[new_f_val:%\w+]]
  2856. ; CHECK-DAG: OpExtInst %void [[ext]] DebugValue [[dbg_f]] [[new_f_val]]
  2857. ; CHECK-DAG: OpExtInst %void [[ext]] DebugValue [[dbg_x]] [[new_f_val]]
  2858. ; CHECK: OpBranch [[loop_cont]]
  2859. ; CHECK: [[loop_cont]] = OpLabel
  2860. ; CHECK: OpStore %i [[i_val:%\w+]]
  2861. ; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_i]] [[i_val]]
  2862. ; CHECK-NEXT: OpBranch [[loop_head]]
  2863. ; CHECK: [[loop_merge]] = OpLabel
  2864. OpCapability Shader
  2865. %1 = OpExtInstImport "GLSL.std.450"
  2866. %ext = OpExtInstImport "OpenCL.DebugInfo.100"
  2867. OpMemoryModel Logical GLSL450
  2868. OpEntryPoint Fragment %main "main" %BC %fo
  2869. OpExecutionMode %main OriginUpperLeft
  2870. %file_name = OpString "test"
  2871. OpSource GLSL 140
  2872. %float_name = OpString "float"
  2873. %main_name = OpString "main"
  2874. %f_name = OpString "f"
  2875. %i_name = OpString "i"
  2876. %x_name = OpString "x"
  2877. OpName %main "main"
  2878. OpName %f "f"
  2879. OpName %i "i"
  2880. OpName %BC "BC"
  2881. OpName %fo "fo"
  2882. %void = OpTypeVoid
  2883. %8 = OpTypeFunction %void
  2884. %float = OpTypeFloat 32
  2885. %_ptr_Function_float = OpTypePointer Function %float
  2886. %float_0 = OpConstant %float 0
  2887. %int = OpTypeInt 32 1
  2888. %uint = OpTypeInt 32 0
  2889. %uint_32 = OpConstant %uint 32
  2890. %_ptr_Function_int = OpTypePointer Function %int
  2891. %int_0 = OpConstant %int 0
  2892. %int_4 = OpConstant %int 4
  2893. %bool = OpTypeBool
  2894. %v4float = OpTypeVector %float 4
  2895. %_ptr_Input_v4float = OpTypePointer Input %v4float
  2896. %BC = OpVariable %_ptr_Input_v4float Input
  2897. %_ptr_Input_float = OpTypePointer Input %float
  2898. %int_1 = OpConstant %int 1
  2899. %_ptr_Output_float = OpTypePointer Output %float
  2900. %fo = OpVariable %_ptr_Output_float Output
  2901. %null_expr = OpExtInst %void %ext DebugExpression
  2902. %src = OpExtInst %void %ext DebugSource %file_name
  2903. %cu = OpExtInst %void %ext DebugCompilationUnit 1 4 %src HLSL
  2904. %dbg_tf = OpExtInst %void %ext DebugTypeBasic %float_name %uint_32 Float
  2905. %dbg_v4f = OpExtInst %void %ext DebugTypeVector %dbg_tf 4
  2906. %main_ty = OpExtInst %void %ext DebugTypeFunction FlagIsProtected|FlagIsPrivate %dbg_v4f %dbg_v4f
  2907. %dbg_main = OpExtInst %void %ext DebugFunction %main_name %main_ty %src 0 0 %cu %main_name FlagIsProtected|FlagIsPrivate 10 %main
  2908. %bb = OpExtInst %void %ext DebugLexicalBlock %src 0 0 %dbg_main
  2909. %bb_child = OpExtInst %void %ext DebugLexicalBlock %src 1 0 %bb
  2910. %dbg_f = OpExtInst %void %ext DebugLocalVariable %f_name %dbg_v4f %src 0 0 %dbg_main FlagIsLocal
  2911. %dbg_i = OpExtInst %void %ext DebugLocalVariable %i_name %dbg_v4f %src 1 0 %dbg_main FlagIsLocal
  2912. %dbg_x = OpExtInst %void %ext DebugLocalVariable %x_name %dbg_v4f %src 2 0 %bb FlagIsLocal
  2913. %main = OpFunction %void None %8
  2914. %22 = OpLabel
  2915. %s0 = OpExtInst %void %ext DebugScope %dbg_main
  2916. %f = OpVariable %_ptr_Function_float Function
  2917. %i = OpVariable %_ptr_Function_int Function
  2918. OpStore %f %float_0
  2919. OpStore %i %int_0
  2920. %decl0 = OpExtInst %void %ext DebugDeclare %dbg_f %f %null_expr
  2921. %decl1 = OpExtInst %void %ext DebugDeclare %dbg_i %i %null_expr
  2922. OpBranch %23
  2923. %23 = OpLabel
  2924. %s1 = OpExtInst %void %ext DebugScope %dbg_main
  2925. OpLoopMerge %24 %25 None
  2926. OpBranch %26
  2927. %26 = OpLabel
  2928. %s2 = OpExtInst %void %ext DebugScope %dbg_main
  2929. %27 = OpLoad %int %i
  2930. %28 = OpSLessThan %bool %27 %int_4
  2931. OpBranchConditional %28 %29 %24
  2932. %29 = OpLabel
  2933. %scope = OpExtInst %void %ext DebugScope %bb
  2934. %decl2 = OpExtInst %void %ext DebugDeclare %dbg_x %f %null_expr
  2935. %30 = OpLoad %float %f
  2936. %31 = OpLoad %int %i
  2937. %32 = OpAccessChain %_ptr_Input_float %BC %31
  2938. %33 = OpLoad %float %32
  2939. %34 = OpFAdd %float %30 %33
  2940. OpStore %f %34
  2941. OpBranch %38
  2942. %38 = OpLabel
  2943. %child_scope = OpExtInst %void %ext DebugScope %bb_child
  2944. %39 = OpLoad %float %f
  2945. %40 = OpFAdd %float %39 %33
  2946. OpStore %f %40
  2947. OpBranch %25
  2948. %25 = OpLabel
  2949. %s3 = OpExtInst %void %ext DebugScope %dbg_main
  2950. %35 = OpLoad %int %i
  2951. %36 = OpIAdd %int %35 %int_1
  2952. OpStore %i %36
  2953. OpBranch %23
  2954. %24 = OpLabel
  2955. %s4 = OpExtInst %void %ext DebugScope %dbg_main
  2956. %37 = OpLoad %float %f
  2957. OpStore %fo %37
  2958. OpReturn
  2959. OpFunctionEnd
  2960. )";
  2961. SinglePassRunAndMatch<SSARewritePass>(text, true);
  2962. }
  2963. TEST_F(LocalSSAElimTest, DebugForLoopUseDebugValueInsteadOfDebugDeclare) {
  2964. // #version 140
  2965. //
  2966. // in vec4 BC;
  2967. // out float fo;
  2968. //
  2969. // struct S {
  2970. // float f;
  2971. // int i;
  2972. // };
  2973. //
  2974. // void main()
  2975. // {
  2976. // S foo = {0.0, 0};
  2977. // for (; foo.i<4; foo.i++) {
  2978. // foo.f = foo.f + BC[foo.i];
  2979. // }
  2980. // fo = foo.f;
  2981. // }
  2982. const std::string text = R"(
  2983. ; CHECK: [[f_name:%\w+]] = OpString "f"
  2984. ; CHECK: [[empty_expr:%\w+]] = OpExtInst %void [[ext:%\d+]] DebugExpression
  2985. ; CHECK: [[deref_op:%\w+]] = OpExtInst %void [[ext]] DebugOperation Deref
  2986. ; CHECK: [[deref:%\w+]] = OpExtInst %void [[ext]] DebugExpression [[deref_op]]
  2987. ; CHECK: [[dbg_foo:%\w+]] = OpExtInst %void [[ext]] DebugLocalVariable [[f_name]]
  2988. ; CHECK: OpStore %f %float_0
  2989. ; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_foo]] %float_0 [[empty_expr]] %uint_0
  2990. ; CHECK-NEXT: OpStore %i %int_0
  2991. ; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_foo]] %int_0 [[empty_expr]] %uint_1
  2992. ; CHECK: [[loop_head:%\w+]] = OpLabel
  2993. ; CHECK: [[phi0:%\w+]] = OpPhi %float %float_0
  2994. ; CHECK: [[phi1:%\w+]] = OpPhi %int %int_0
  2995. ; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_foo]] [[phi0]] [[empty_expr]] %uint_0
  2996. ; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_foo]] [[phi1]] [[empty_expr]] %uint_1
  2997. ; CHECK: OpLoopMerge [[loop_merge:%\w+]] [[loop_cont:%\w+]] None
  2998. ; CHECK-NEXT: OpBranch [[loop_body:%\w+]]
  2999. ; CHECK: [[loop_body]] = OpLabel
  3000. ; CHECK: OpBranchConditional {{%\w+}} [[bb:%\w+]] [[loop_merge]]
  3001. ; CHECK: [[bb]] = OpLabel
  3002. ; CHECK: OpStore %f [[f_val:%\w+]]
  3003. ; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_foo]] [[f_val]] [[empty_expr]] %uint_0
  3004. ; CHECK-NEXT: OpBranch [[loop_cont]]
  3005. ; CHECK: [[loop_cont]] = OpLabel
  3006. ; CHECK: OpStore %i [[i_val:%\w+]]
  3007. ; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_foo]] [[i_val]] [[empty_expr]] %uint_1
  3008. ; CHECK-NEXT: OpBranch [[loop_head]]
  3009. OpCapability Shader
  3010. %1 = OpExtInstImport "GLSL.std.450"
  3011. %ext = OpExtInstImport "OpenCL.DebugInfo.100"
  3012. OpMemoryModel Logical GLSL450
  3013. OpEntryPoint Fragment %main "main" %BC %fo
  3014. OpExecutionMode %main OriginUpperLeft
  3015. %file_name = OpString "test"
  3016. OpSource GLSL 140
  3017. %float_name = OpString "float"
  3018. %main_name = OpString "main"
  3019. %f_name = OpString "f"
  3020. OpName %main "main"
  3021. OpName %f "f"
  3022. OpName %i "i"
  3023. OpName %BC "BC"
  3024. OpName %fo "fo"
  3025. %void = OpTypeVoid
  3026. %8 = OpTypeFunction %void
  3027. %float = OpTypeFloat 32
  3028. %_ptr_Function_float = OpTypePointer Function %float
  3029. %float_0 = OpConstant %float 0
  3030. %int = OpTypeInt 32 1
  3031. %uint = OpTypeInt 32 0
  3032. %uint_32 = OpConstant %uint 32
  3033. %uint_0 = OpConstant %uint 0
  3034. %uint_1 = OpConstant %uint 1
  3035. %_ptr_Function_int = OpTypePointer Function %int
  3036. %int_0 = OpConstant %int 0
  3037. %int_4 = OpConstant %int 4
  3038. %bool = OpTypeBool
  3039. %v4float = OpTypeVector %float 4
  3040. %_ptr_Input_v4float = OpTypePointer Input %v4float
  3041. %BC = OpVariable %_ptr_Input_v4float Input
  3042. %_ptr_Input_float = OpTypePointer Input %float
  3043. %int_1 = OpConstant %int 1
  3044. %_ptr_Output_float = OpTypePointer Output %float
  3045. %fo = OpVariable %_ptr_Output_float Output
  3046. %deref_op = OpExtInst %void %ext DebugOperation Deref
  3047. %deref = OpExtInst %void %ext DebugExpression %deref_op
  3048. %src = OpExtInst %void %ext DebugSource %file_name
  3049. %cu = OpExtInst %void %ext DebugCompilationUnit 1 4 %src HLSL
  3050. %dbg_tf = OpExtInst %void %ext DebugTypeBasic %float_name %uint_32 Float
  3051. %dbg_v4f = OpExtInst %void %ext DebugTypeVector %dbg_tf 4
  3052. %main_ty = OpExtInst %void %ext DebugTypeFunction FlagIsProtected|FlagIsPrivate %dbg_v4f %dbg_v4f
  3053. %dbg_main = OpExtInst %void %ext DebugFunction %main_name %main_ty %src 0 0 %cu %main_name FlagIsProtected|FlagIsPrivate 10 %main
  3054. %dbg_foo = OpExtInst %void %ext DebugLocalVariable %f_name %dbg_v4f %src 0 0 %dbg_main FlagIsLocal
  3055. %main = OpFunction %void None %8
  3056. %22 = OpLabel
  3057. %s0 = OpExtInst %void %ext DebugScope %dbg_main
  3058. %f = OpVariable %_ptr_Function_float Function
  3059. %i = OpVariable %_ptr_Function_int Function
  3060. OpStore %f %float_0
  3061. OpStore %i %int_0
  3062. %decl0 = OpExtInst %void %ext DebugValue %dbg_foo %f %deref %uint_0
  3063. %decl1 = OpExtInst %void %ext DebugValue %dbg_foo %i %deref %uint_1
  3064. OpBranch %23
  3065. %23 = OpLabel
  3066. %s1 = OpExtInst %void %ext DebugScope %dbg_main
  3067. OpLoopMerge %24 %25 None
  3068. OpBranch %26
  3069. %26 = OpLabel
  3070. %s2 = OpExtInst %void %ext DebugScope %dbg_main
  3071. %27 = OpLoad %int %i
  3072. %28 = OpSLessThan %bool %27 %int_4
  3073. OpBranchConditional %28 %29 %24
  3074. %29 = OpLabel
  3075. %s3 = OpExtInst %void %ext DebugScope %dbg_main
  3076. %30 = OpLoad %float %f
  3077. %31 = OpLoad %int %i
  3078. %32 = OpAccessChain %_ptr_Input_float %BC %31
  3079. %33 = OpLoad %float %32
  3080. %34 = OpFAdd %float %30 %33
  3081. OpStore %f %34
  3082. OpBranch %25
  3083. %25 = OpLabel
  3084. %s4 = OpExtInst %void %ext DebugScope %dbg_main
  3085. %35 = OpLoad %int %i
  3086. %36 = OpIAdd %int %35 %int_1
  3087. OpStore %i %36
  3088. OpBranch %23
  3089. %24 = OpLabel
  3090. %s5 = OpExtInst %void %ext DebugScope %dbg_main
  3091. %37 = OpLoad %float %f
  3092. OpStore %fo %37
  3093. OpReturn
  3094. OpFunctionEnd
  3095. )";
  3096. SinglePassRunAndMatch<SSARewritePass>(text, true);
  3097. }
  3098. TEST_F(LocalSSAElimTest, DebugValueNotUsedForDebugDeclare) {
  3099. // #version 140
  3100. //
  3101. // in vec4 BC;
  3102. // out float fo;
  3103. //
  3104. // void main()
  3105. // {
  3106. // float f = 0.0;
  3107. // for (int i=0; i<4; i++) {
  3108. // f = f + BC[i];
  3109. // }
  3110. // fo = f;
  3111. // }
  3112. const std::string text = R"(
  3113. ; CHECK: [[f_name:%\w+]] = OpString "f"
  3114. ; CHECK: [[i_name:%\w+]] = OpString "i"
  3115. ; CHECK: [[dbg_f:%\w+]] = OpExtInst %void [[ext:%\d+]] DebugLocalVariable [[f_name]]
  3116. ; CHECK: [[dbg_i:%\w+]] = OpExtInst %void [[ext]] DebugLocalVariable [[i_name]]
  3117. ; CHECK: OpStore %f %float_0
  3118. ; CHECK-NEXT: OpStore %i %int_0
  3119. ; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_f]] %f
  3120. ; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_i]] %i
  3121. ; CHECK-NOT: DebugValue
  3122. ; CHECK-NOT: DebugDeclare
  3123. OpCapability Shader
  3124. %1 = OpExtInstImport "GLSL.std.450"
  3125. %ext = OpExtInstImport "OpenCL.DebugInfo.100"
  3126. OpMemoryModel Logical GLSL450
  3127. OpEntryPoint Fragment %main "main" %BC %fo
  3128. OpExecutionMode %main OriginUpperLeft
  3129. %file_name = OpString "test"
  3130. OpSource GLSL 140
  3131. %float_name = OpString "float"
  3132. %main_name = OpString "main"
  3133. %f_name = OpString "f"
  3134. %i_name = OpString "i"
  3135. OpName %main "main"
  3136. OpName %f "f"
  3137. OpName %i "i"
  3138. OpName %BC "BC"
  3139. OpName %fo "fo"
  3140. %void = OpTypeVoid
  3141. %8 = OpTypeFunction %void
  3142. %float = OpTypeFloat 32
  3143. %_ptr_Function_float = OpTypePointer Function %float
  3144. %float_0 = OpConstant %float 0
  3145. %int = OpTypeInt 32 1
  3146. %uint = OpTypeInt 32 0
  3147. %uint_32 = OpConstant %uint 32
  3148. %_ptr_Function_int = OpTypePointer Function %int
  3149. %int_0 = OpConstant %int 0
  3150. %int_4 = OpConstant %int 4
  3151. %bool = OpTypeBool
  3152. %v4float = OpTypeVector %float 4
  3153. %_ptr_Input_v4float = OpTypePointer Input %v4float
  3154. %BC = OpVariable %_ptr_Input_v4float Input
  3155. %_ptr_Input_float = OpTypePointer Input %float
  3156. %int_1 = OpConstant %int 1
  3157. %_ptr_Output_float = OpTypePointer Output %float
  3158. %fo = OpVariable %_ptr_Output_float Output
  3159. %null_expr = OpExtInst %void %ext DebugExpression
  3160. %src = OpExtInst %void %ext DebugSource %file_name
  3161. %cu = OpExtInst %void %ext DebugCompilationUnit 1 4 %src HLSL
  3162. %dbg_tf = OpExtInst %void %ext DebugTypeBasic %float_name %uint_32 Float
  3163. %dbg_v4f = OpExtInst %void %ext DebugTypeVector %dbg_tf 4
  3164. %main_ty = OpExtInst %void %ext DebugTypeFunction FlagIsProtected|FlagIsPrivate %dbg_v4f %dbg_v4f
  3165. %dbg_main = OpExtInst %void %ext DebugFunction %main_name %main_ty %src 0 0 %cu %main_name FlagIsProtected|FlagIsPrivate 10 %main
  3166. %dbg_f = OpExtInst %void %ext DebugLocalVariable %f_name %dbg_v4f %src 0 0 %dbg_main FlagIsLocal
  3167. %dbg_i = OpExtInst %void %ext DebugLocalVariable %i_name %dbg_v4f %src 1 0 %dbg_main FlagIsLocal
  3168. %main = OpFunction %void None %8
  3169. %22 = OpLabel
  3170. %s0 = OpExtInst %void %ext DebugScope %dbg_main
  3171. %f = OpVariable %_ptr_Function_float Function
  3172. %i = OpVariable %_ptr_Function_int Function
  3173. OpStore %f %float_0
  3174. OpStore %i %int_0
  3175. %decl0 = OpExtInst %void %ext DebugValue %dbg_f %f %null_expr
  3176. %decl1 = OpExtInst %void %ext DebugValue %dbg_i %i %null_expr
  3177. OpBranch %23
  3178. %23 = OpLabel
  3179. %s1 = OpExtInst %void %ext DebugScope %dbg_main
  3180. OpLoopMerge %24 %25 None
  3181. OpBranch %26
  3182. %26 = OpLabel
  3183. %s2 = OpExtInst %void %ext DebugScope %dbg_main
  3184. %27 = OpLoad %int %i
  3185. %28 = OpSLessThan %bool %27 %int_4
  3186. OpBranchConditional %28 %29 %24
  3187. %29 = OpLabel
  3188. %s3 = OpExtInst %void %ext DebugScope %dbg_main
  3189. %30 = OpLoad %float %f
  3190. %31 = OpLoad %int %i
  3191. %32 = OpAccessChain %_ptr_Input_float %BC %31
  3192. %33 = OpLoad %float %32
  3193. %34 = OpFAdd %float %30 %33
  3194. OpStore %f %34
  3195. OpBranch %25
  3196. %25 = OpLabel
  3197. %s4 = OpExtInst %void %ext DebugScope %dbg_main
  3198. %35 = OpLoad %int %i
  3199. %36 = OpIAdd %int %35 %int_1
  3200. OpStore %i %36
  3201. OpBranch %23
  3202. %24 = OpLabel
  3203. %s5 = OpExtInst %void %ext DebugScope %dbg_main
  3204. %37 = OpLoad %float %f
  3205. OpStore %fo %37
  3206. OpReturn
  3207. OpFunctionEnd
  3208. )";
  3209. SinglePassRunAndMatch<SSARewritePass>(text, true);
  3210. }
  3211. TEST_F(LocalSSAElimTest, DebugNestedForLoop) {
  3212. const std::string text = R"(
  3213. ; CHECK: = OpFunction
  3214. ; CHECK-NEXT: [[entry:%\w+]] = OpLabel
  3215. ; CHECK: OpStore %f %float_0
  3216. ; CHECK-NEXT: = OpExtInst %void [[ext:%\w+]] DebugValue [[dbg_f:%\w+]] %float_0
  3217. ; CHECK: [[outer_header:%\w+]] = OpLabel
  3218. ; CHECK: [[outer_f:%\w+]] = OpPhi %float %float_0 [[entry]] [[inner_f:%\w+]] [[outer_be:%\w+]]
  3219. ; CHECK: = OpExtInst %void [[ext]] DebugValue [[dbg_f]] [[outer_f]]
  3220. ; CHECK: [[inner_pre_header:%\w+]] = OpLabel
  3221. ; CHECK: [[inner_header:%\w+]] = OpLabel
  3222. ; CHECK: [[inner_f]] = OpPhi %float [[outer_f]] [[inner_pre_header]] [[f_next:%\w+]] [[inner_be:%\w+]]
  3223. ; CHECK: = OpExtInst %void [[ext]] DebugValue [[dbg_f]] [[inner_f]]
  3224. ; CHECK: [[inner_be]] = OpLabel
  3225. ; CHECK: [[f_next]] = OpFAdd %float [[inner_f]]
  3226. ; CHECK-NEXT: OpStore %f [[f_next]]
  3227. ; CHECK-NEXT: = OpExtInst %void [[ext]] DebugValue [[dbg_f]] [[f_next]]
  3228. OpCapability Shader
  3229. %1 = OpExtInstImport "GLSL.std.450"
  3230. %ext = OpExtInstImport "OpenCL.DebugInfo.100"
  3231. OpMemoryModel Logical GLSL450
  3232. OpEntryPoint Fragment %main "main" %BC %fo
  3233. OpExecutionMode %main OriginUpperLeft
  3234. %file_name = OpString "test"
  3235. %float_name = OpString "float"
  3236. %main_name = OpString "main"
  3237. %f_name = OpString "f"
  3238. OpSource GLSL 450
  3239. OpName %main "main"
  3240. OpName %f "f"
  3241. OpName %i "i"
  3242. OpName %j "j"
  3243. OpName %BC "BC"
  3244. OpName %fo "fo"
  3245. OpDecorate %BC Location 0
  3246. OpDecorate %fo Location 0
  3247. %void = OpTypeVoid
  3248. %9 = OpTypeFunction %void
  3249. %float = OpTypeFloat 32
  3250. %_ptr_Function_float = OpTypePointer Function %float
  3251. %float_0 = OpConstant %float 0
  3252. %int = OpTypeInt 32 1
  3253. %_ptr_Function_int = OpTypePointer Function %int
  3254. %int_0 = OpConstant %int 0
  3255. %int_4 = OpConstant %int 4
  3256. %uint = OpTypeInt 32 0
  3257. %uint_32 = OpConstant %uint 32
  3258. %bool = OpTypeBool
  3259. %v4float = OpTypeVector %float 4
  3260. %mat4v4float = OpTypeMatrix %v4float 4
  3261. %_ptr_Input_mat4v4float = OpTypePointer Input %mat4v4float
  3262. %BC = OpVariable %_ptr_Input_mat4v4float Input
  3263. %_ptr_Input_float = OpTypePointer Input %float
  3264. %int_1 = OpConstant %int 1
  3265. %_ptr_Output_float = OpTypePointer Output %float
  3266. %fo = OpVariable %_ptr_Output_float Output
  3267. ; Debug information
  3268. %null_expr = OpExtInst %void %ext DebugExpression
  3269. %src = OpExtInst %void %ext DebugSource %file_name
  3270. %cu = OpExtInst %void %ext DebugCompilationUnit 1 4 %src HLSL
  3271. %dbg_tf = OpExtInst %void %ext DebugTypeBasic %float_name %uint_32 Float
  3272. %main_ty = OpExtInst %void %ext DebugTypeFunction FlagIsProtected|FlagIsPrivate %void
  3273. %dbg_main = OpExtInst %void %ext DebugFunction %main_name %main_ty %src 0 0 %cu %main_name FlagIsProtected|FlagIsPrivate 10 %main
  3274. %dbg_f = OpExtInst %void %ext DebugLocalVariable %f_name %dbg_tf %src 0 0 %dbg_main FlagIsLocal
  3275. %main = OpFunction %void None %9
  3276. %24 = OpLabel
  3277. %s1 = OpExtInst %void %ext DebugScope %dbg_main
  3278. %f = OpVariable %_ptr_Function_float Function
  3279. %i = OpVariable %_ptr_Function_int Function
  3280. %j = OpVariable %_ptr_Function_int Function
  3281. ; DebugDeclare
  3282. OpStore %f %float_0
  3283. %decl = OpExtInst %void %ext DebugDeclare %dbg_f %f %null_expr
  3284. OpStore %i %int_0
  3285. OpBranch %25
  3286. %25 = OpLabel
  3287. %s2 = OpExtInst %void %ext DebugScope %dbg_main
  3288. %26 = OpLoad %int %i
  3289. %27 = OpSLessThan %bool %26 %int_4
  3290. OpLoopMerge %28 %29 None
  3291. OpBranchConditional %27 %30 %28
  3292. %30 = OpLabel
  3293. %s3 = OpExtInst %void %ext DebugScope %dbg_main
  3294. OpStore %j %int_0
  3295. OpBranch %31
  3296. %31 = OpLabel
  3297. %s4 = OpExtInst %void %ext DebugScope %dbg_main
  3298. %32 = OpLoad %int %j
  3299. %33 = OpSLessThan %bool %32 %int_4
  3300. OpLoopMerge %50 %34 None
  3301. OpBranchConditional %33 %34 %50
  3302. %34 = OpLabel
  3303. %s5 = OpExtInst %void %ext DebugScope %dbg_main
  3304. %35 = OpLoad %float %f
  3305. %36 = OpLoad %int %i
  3306. %37 = OpLoad %int %j
  3307. %38 = OpAccessChain %_ptr_Input_float %BC %36 %37
  3308. %39 = OpLoad %float %38
  3309. %40 = OpFAdd %float %35 %39
  3310. OpStore %f %40
  3311. %41 = OpLoad %int %j
  3312. %42 = OpIAdd %int %41 %int_1
  3313. OpStore %j %42
  3314. OpBranch %31
  3315. %50 = OpLabel
  3316. %s6 = OpExtInst %void %ext DebugScope %dbg_main
  3317. OpBranch %29
  3318. %29 = OpLabel
  3319. %s7 = OpExtInst %void %ext DebugScope %dbg_main
  3320. %43 = OpLoad %int %i
  3321. %44 = OpIAdd %int %43 %int_1
  3322. OpStore %i %44
  3323. OpBranch %25
  3324. %28 = OpLabel
  3325. %s8 = OpExtInst %void %ext DebugScope %dbg_main
  3326. %45 = OpLoad %float %f
  3327. OpStore %fo %45
  3328. OpReturn
  3329. OpFunctionEnd
  3330. )";
  3331. SinglePassRunAndMatch<SSARewritePass>(text, true);
  3332. }
  3333. TEST_F(LocalSSAElimTest, DebugForLoopWithContinue) {
  3334. const std::string text = R"(
  3335. ; CHECK: = OpFunction
  3336. ; CHECK-NEXT: [[entry:%\w+]] = OpLabel
  3337. ; CHECK: OpStore %f %float_0
  3338. ; CHECK-NEXT: = OpExtInst %void [[ext:%\w+]] DebugValue [[dbg_f:%\w+]] %float_0
  3339. ; CHECK: [[outer_header:%\w+]] = OpLabel
  3340. ; CHECK: [[outer_f:%\w+]] = OpPhi %float %float_0 [[entry]] [[inner_f:%\w+]] [[cont:%\w+]]
  3341. ; CHECK: = OpExtInst %void [[ext]] DebugValue [[dbg_f]] [[outer_f]]
  3342. ; CHECK: [[f_next:%\w+]] = OpFAdd %float [[outer_f]]
  3343. ; CHECK-NEXT: OpStore %f [[f_next]]
  3344. ; CHECK-NEXT: = OpExtInst %void [[ext]] DebugValue [[dbg_f]] [[f_next]]
  3345. ; CHECK: [[cont]] = OpLabel
  3346. ; CHECK: [[inner_f]] = OpPhi %float [[outer_f]] {{%\d+}} [[f_next]] {{%\d+}}
  3347. ; CHECK-NEXT: = OpExtInst %void [[ext]] DebugValue [[dbg_f]] [[inner_f]]
  3348. OpCapability Shader
  3349. %1 = OpExtInstImport "GLSL.std.450"
  3350. %ext = OpExtInstImport "OpenCL.DebugInfo.100"
  3351. OpMemoryModel Logical GLSL450
  3352. OpEntryPoint Fragment %main "main" %BC %fo
  3353. OpExecutionMode %main OriginUpperLeft
  3354. %file_name = OpString "test"
  3355. %float_name = OpString "float"
  3356. %main_name = OpString "main"
  3357. %f_name = OpString "f"
  3358. OpSource GLSL 140
  3359. OpName %main "main"
  3360. OpName %f "f"
  3361. OpName %i "i"
  3362. OpName %t "t"
  3363. OpName %BC "BC"
  3364. OpName %fo "fo"
  3365. %void = OpTypeVoid
  3366. %9 = OpTypeFunction %void
  3367. %float = OpTypeFloat 32
  3368. %_ptr_Function_float = OpTypePointer Function %float
  3369. %float_0 = OpConstant %float 0
  3370. %int = OpTypeInt 32 1
  3371. %_ptr_Function_int = OpTypePointer Function %int
  3372. %int_0 = OpConstant %int 0
  3373. %int_4 = OpConstant %int 4
  3374. %uint = OpTypeInt 32 0
  3375. %uint_32 = OpConstant %uint 32
  3376. %bool = OpTypeBool
  3377. %v4float = OpTypeVector %float 4
  3378. %_ptr_Input_v4float = OpTypePointer Input %v4float
  3379. %BC = OpVariable %_ptr_Input_v4float Input
  3380. %_ptr_Input_float = OpTypePointer Input %float
  3381. %int_1 = OpConstant %int 1
  3382. %_ptr_Output_float = OpTypePointer Output %float
  3383. %fo = OpVariable %_ptr_Output_float Output
  3384. ; Debug information
  3385. %null_expr = OpExtInst %void %ext DebugExpression
  3386. %src = OpExtInst %void %ext DebugSource %file_name
  3387. %cu = OpExtInst %void %ext DebugCompilationUnit 1 4 %src HLSL
  3388. %dbg_tf = OpExtInst %void %ext DebugTypeBasic %float_name %uint_32 Float
  3389. %main_ty = OpExtInst %void %ext DebugTypeFunction FlagIsProtected|FlagIsPrivate %void
  3390. %dbg_main = OpExtInst %void %ext DebugFunction %main_name %main_ty %src 0 0 %cu %main_name FlagIsProtected|FlagIsPrivate 10 %main
  3391. %dbg_f = OpExtInst %void %ext DebugLocalVariable %f_name %dbg_tf %src 0 0 %dbg_main FlagIsLocal
  3392. %main = OpFunction %void None %9
  3393. %23 = OpLabel
  3394. %s0 = OpExtInst %void %ext DebugScope %dbg_main
  3395. %f = OpVariable %_ptr_Function_float Function
  3396. %i = OpVariable %_ptr_Function_int Function
  3397. %t = OpVariable %_ptr_Function_float Function
  3398. ; DebugDeclare
  3399. OpStore %f %float_0
  3400. %decl = OpExtInst %void %ext DebugDeclare %dbg_f %f %null_expr
  3401. OpStore %i %int_0
  3402. OpBranch %24
  3403. %24 = OpLabel
  3404. %s1 = OpExtInst %void %ext DebugScope %dbg_main
  3405. OpLoopMerge %25 %26 None
  3406. OpBranch %27
  3407. %27 = OpLabel
  3408. %s2 = OpExtInst %void %ext DebugScope %dbg_main
  3409. %28 = OpLoad %int %i
  3410. %29 = OpSLessThan %bool %28 %int_4
  3411. OpBranchConditional %29 %30 %25
  3412. %30 = OpLabel
  3413. %s3 = OpExtInst %void %ext DebugScope %dbg_main
  3414. %31 = OpLoad %int %i
  3415. %32 = OpAccessChain %_ptr_Input_float %BC %31
  3416. %33 = OpLoad %float %32
  3417. OpStore %t %33
  3418. %34 = OpLoad %float %t
  3419. %35 = OpFOrdLessThan %bool %34 %float_0
  3420. OpSelectionMerge %36 None
  3421. OpBranchConditional %35 %37 %36
  3422. %37 = OpLabel
  3423. %s4 = OpExtInst %void %ext DebugScope %dbg_main
  3424. OpBranch %26
  3425. %36 = OpLabel
  3426. %s5 = OpExtInst %void %ext DebugScope %dbg_main
  3427. %38 = OpLoad %float %f
  3428. %39 = OpLoad %float %t
  3429. %40 = OpFAdd %float %38 %39
  3430. OpStore %f %40
  3431. OpBranch %26
  3432. %26 = OpLabel
  3433. %s6 = OpExtInst %void %ext DebugScope %dbg_main
  3434. %41 = OpLoad %int %i
  3435. %42 = OpIAdd %int %41 %int_1
  3436. OpStore %i %42
  3437. OpBranch %24
  3438. %25 = OpLabel
  3439. %s7 = OpExtInst %void %ext DebugScope %dbg_main
  3440. %43 = OpLoad %float %f
  3441. OpStore %fo %43
  3442. OpReturn
  3443. OpFunctionEnd
  3444. )";
  3445. SinglePassRunAndMatch<SSARewritePass>(text, true);
  3446. }
  3447. TEST_F(LocalSSAElimTest, DebugIfElse) {
  3448. const std::string text = R"(
  3449. OpCapability Shader
  3450. %1 = OpExtInstImport "GLSL.std.450"
  3451. %ext = OpExtInstImport "OpenCL.DebugInfo.100"
  3452. OpMemoryModel Logical GLSL450
  3453. OpEntryPoint Fragment %main "main" %f %BaseColor %gl_FragColor
  3454. OpExecutionMode %main OriginUpperLeft
  3455. %file_name = OpString "test"
  3456. %float_name = OpString "float"
  3457. %main_name = OpString "main"
  3458. %v_name = OpString "v"
  3459. OpSource GLSL 140
  3460. OpName %main "main"
  3461. OpName %f "f"
  3462. OpName %v "v"
  3463. OpName %BaseColor "BaseColor"
  3464. OpName %gl_FragColor "gl_FragColor"
  3465. %void = OpTypeVoid
  3466. %8 = OpTypeFunction %void
  3467. %float = OpTypeFloat 32
  3468. %_ptr_Input_float = OpTypePointer Input %float
  3469. %f = OpVariable %_ptr_Input_float Input
  3470. %float_0 = OpConstant %float 0
  3471. %uint = OpTypeInt 32 0
  3472. %uint_32 = OpConstant %uint 32
  3473. %bool = OpTypeBool
  3474. %v4float = OpTypeVector %float 4
  3475. %_ptr_Function_v4float = OpTypePointer Function %v4float
  3476. %_ptr_Input_v4float = OpTypePointer Input %v4float
  3477. %BaseColor = OpVariable %_ptr_Input_v4float Input
  3478. %float_0_5 = OpConstant %float 0.5
  3479. %float_1 = OpConstant %float 1
  3480. %18 = OpConstantComposite %v4float %float_1 %float_1 %float_1 %float_1
  3481. %_ptr_Output_v4float = OpTypePointer Output %v4float
  3482. %gl_FragColor = OpVariable %_ptr_Output_v4float Output
  3483. ; Debug information
  3484. %null_expr = OpExtInst %void %ext DebugExpression
  3485. %src = OpExtInst %void %ext DebugSource %file_name
  3486. %cu = OpExtInst %void %ext DebugCompilationUnit 1 4 %src HLSL
  3487. %dbg_tf = OpExtInst %void %ext DebugTypeBasic %float_name %uint_32 Float
  3488. %main_ty = OpExtInst %void %ext DebugTypeFunction FlagIsProtected|FlagIsPrivate %void
  3489. %dbg_main = OpExtInst %void %ext DebugFunction %main_name %main_ty %src 0 0 %cu %main_name FlagIsProtected|FlagIsPrivate 10 %main
  3490. %dbg_v = OpExtInst %void %ext DebugLocalVariable %v_name %dbg_tf %src 0 0 %dbg_main FlagIsLocal
  3491. %main = OpFunction %void None %8
  3492. %20 = OpLabel
  3493. %s0 = OpExtInst %void %ext DebugScope %dbg_main
  3494. ; DebugDeclare
  3495. %v = OpVariable %_ptr_Function_v4float Function
  3496. %decl = OpExtInst %void %ext DebugDeclare %dbg_v %v %null_expr
  3497. %21 = OpLoad %float %f
  3498. %22 = OpFOrdGreaterThanEqual %bool %21 %float_0
  3499. OpSelectionMerge %23 None
  3500. OpBranchConditional %22 %24 %25
  3501. ; CHECK: OpBranchConditional
  3502. ; CHECK-NEXT: [[br0:%\w+]] = OpLabel
  3503. ; CHECK: OpStore %v [[v0:%\w+]]
  3504. ; CHECK-NEXT: = OpExtInst %void [[ext:%\w+]] DebugValue [[dbg_v:%\w+]] [[v0]]
  3505. %24 = OpLabel
  3506. %s1 = OpExtInst %void %ext DebugScope %dbg_main
  3507. %26 = OpLoad %v4float %BaseColor
  3508. %27 = OpVectorTimesScalar %v4float %26 %float_0_5
  3509. OpStore %v %27
  3510. OpBranch %23
  3511. ; CHECK: [[br1:%\w+]] = OpLabel
  3512. ; CHECK: OpStore %v [[v1:%\w+]]
  3513. ; CHECK-NEXT: = OpExtInst %void [[ext]] DebugValue [[dbg_v]] [[v1]]
  3514. %25 = OpLabel
  3515. %s2 = OpExtInst %void %ext DebugScope %dbg_main
  3516. %28 = OpLoad %v4float %BaseColor
  3517. %29 = OpFAdd %v4float %28 %18
  3518. OpStore %v %29
  3519. OpBranch %23
  3520. ; CHECK: [[phi:%\w+]] = OpPhi %v4float [[v0]] [[br0]] [[v1]] [[br1]]
  3521. ; CHECK-NEXT: = OpExtInst %void [[ext]] DebugValue [[dbg_v]] [[phi]]
  3522. %23 = OpLabel
  3523. %s3 = OpExtInst %void %ext DebugScope %dbg_main
  3524. %30 = OpLoad %v4float %v
  3525. OpStore %gl_FragColor %30
  3526. OpReturn
  3527. OpFunctionEnd
  3528. )";
  3529. SinglePassRunAndMatch<SSARewritePass>(text, true);
  3530. }
  3531. TEST_F(LocalSSAElimTest, DebugSwitch) {
  3532. const std::string text = R"(
  3533. OpCapability Shader
  3534. %1 = OpExtInstImport "GLSL.std.450"
  3535. %ext = OpExtInstImport "OpenCL.DebugInfo.100"
  3536. OpMemoryModel Logical GLSL450
  3537. OpEntryPoint Fragment %main "main" %BaseColor %f %gl_FragColor
  3538. OpExecutionMode %main OriginUpperLeft
  3539. %file_name = OpString "test"
  3540. %float_name = OpString "float"
  3541. %main_name = OpString "main"
  3542. %v_name = OpString "v"
  3543. OpSource GLSL 140
  3544. OpName %main "main"
  3545. OpName %v "v"
  3546. OpName %BaseColor "BaseColor"
  3547. OpName %i "i"
  3548. OpName %f "f"
  3549. OpName %gl_FragColor "gl_FragColor"
  3550. %void = OpTypeVoid
  3551. %9 = OpTypeFunction %void
  3552. %float = OpTypeFloat 32
  3553. %v4float = OpTypeVector %float 4
  3554. %uint = OpTypeInt 32 0
  3555. %uint_32 = OpConstant %uint 32
  3556. %_ptr_Function_v4float = OpTypePointer Function %v4float
  3557. %_ptr_Input_v4float = OpTypePointer Input %v4float
  3558. %BaseColor = OpVariable %_ptr_Input_v4float Input
  3559. %int = OpTypeInt 32 1
  3560. %_ptr_Function_int = OpTypePointer Function %int
  3561. %_ptr_Input_float = OpTypePointer Input %float
  3562. %f = OpVariable %_ptr_Input_float Input
  3563. %float_0_25 = OpConstant %float 0.25
  3564. %float_0_75 = OpConstant %float 0.75
  3565. %_ptr_Output_v4float = OpTypePointer Output %v4float
  3566. %gl_FragColor = OpVariable %_ptr_Output_v4float Output
  3567. ; Debug information
  3568. %null_expr = OpExtInst %void %ext DebugExpression
  3569. %src = OpExtInst %void %ext DebugSource %file_name
  3570. %cu = OpExtInst %void %ext DebugCompilationUnit 1 4 %src HLSL
  3571. %dbg_tf = OpExtInst %void %ext DebugTypeBasic %float_name %uint_32 Float
  3572. %main_ty = OpExtInst %void %ext DebugTypeFunction FlagIsProtected|FlagIsPrivate %void
  3573. %dbg_main = OpExtInst %void %ext DebugFunction %main_name %main_ty %src 0 0 %cu %main_name FlagIsProtected|FlagIsPrivate 10 %main
  3574. %dbg_v = OpExtInst %void %ext DebugLocalVariable %v_name %dbg_tf %src 0 0 %dbg_main FlagIsLocal
  3575. %main = OpFunction %void None %9
  3576. %20 = OpLabel
  3577. %s0 = OpExtInst %void %ext DebugScope %dbg_main
  3578. %v = OpVariable %_ptr_Function_v4float Function
  3579. %i = OpVariable %_ptr_Function_int Function
  3580. %21 = OpLoad %v4float %BaseColor
  3581. ; DebugDeclare
  3582. OpStore %v %21
  3583. %decl = OpExtInst %void %ext DebugDeclare %dbg_v %v %null_expr
  3584. ; CHECK: %main = OpFunction %void None
  3585. ; CHECK-NEXT: [[entry:%\w+]] = OpLabel
  3586. ; CHECK: OpStore %v [[v0:%\w+]]
  3587. ; CHECK-NEXT: = OpExtInst %void [[ext:%\w+]] DebugValue [[dbg_v:%\w+]] [[v0]]
  3588. ; CHECK: OpSwitch {{%\w+}} [[case0:%\w+]] 0 [[case1:%\w+]] 1 [[case2:%\w+]] 2 [[case3:%\w+]]
  3589. ; CHECK: OpStore %v [[v1:%\w+]]
  3590. ; CHECK-NEXT: = OpExtInst %void [[ext]] DebugValue [[dbg_v]] [[v1]]
  3591. ; CHECK: OpStore %v [[v2:%\w+]]
  3592. ; CHECK-NEXT: = OpExtInst %void [[ext]] DebugValue [[dbg_v]] [[v2]]
  3593. ; CHECK: [[phi0:%\w+]] = OpPhi %v4float [[v0]] [[entry]] [[v2]] [[case2]]
  3594. ; CHECK-NEXT: = OpExtInst %void [[ext]] DebugValue [[dbg_v]] [[phi0]]
  3595. ; CHECK: OpStore %v [[v3:%\w+]]
  3596. ; CHECK-NEXT: = OpExtInst %void [[ext]] DebugValue [[dbg_v]] [[v3]]
  3597. ; CHECK: [[phi1:%\w+]] = OpPhi %v4float [[v0]] [[case0]] [[v1]] [[case1]] [[v3]] [[case3]]
  3598. ; CHECK-NEXT: = OpExtInst %void [[ext]] DebugValue [[dbg_v]] [[phi1]]
  3599. %22 = OpLoad %float %f
  3600. %23 = OpConvertFToS %int %22
  3601. OpStore %i %23
  3602. %24 = OpLoad %int %i
  3603. OpSelectionMerge %25 None
  3604. OpSwitch %24 %26 0 %27 1 %28 2 %29
  3605. %26 = OpLabel
  3606. %s1 = OpExtInst %void %ext DebugScope %dbg_main
  3607. OpBranch %25
  3608. %27 = OpLabel
  3609. %s2 = OpExtInst %void %ext DebugScope %dbg_main
  3610. %30 = OpLoad %v4float %v
  3611. %31 = OpVectorTimesScalar %v4float %30 %float_0_25
  3612. OpStore %v %31
  3613. OpBranch %25
  3614. %28 = OpLabel
  3615. %s3 = OpExtInst %void %ext DebugScope %dbg_main
  3616. %32 = OpLoad %v4float %v
  3617. %33 = OpCompositeConstruct %v4float %float_0_25 %float_0_25 %float_0_25 %float_0_25
  3618. %34 = OpFAdd %v4float %32 %33
  3619. OpStore %v %34
  3620. OpBranch %29
  3621. %29 = OpLabel
  3622. %s4 = OpExtInst %void %ext DebugScope %dbg_main
  3623. %35 = OpLoad %v4float %v
  3624. %36 = OpVectorTimesScalar %v4float %35 %float_0_75
  3625. OpStore %v %36
  3626. OpBranch %25
  3627. %25 = OpLabel
  3628. %s5 = OpExtInst %void %ext DebugScope %dbg_main
  3629. %37 = OpLoad %v4float %v
  3630. OpStore %gl_FragColor %37
  3631. OpReturn
  3632. OpFunctionEnd
  3633. )";
  3634. SinglePassRunAndMatch<SSARewritePass>(text, true);
  3635. }
  3636. TEST_F(LocalSSAElimTest, DebugSwapProblem) {
  3637. // #version 140
  3638. //
  3639. // in float fe;
  3640. // out float fo;
  3641. //
  3642. // void main()
  3643. // {
  3644. // float f1 = 0.0;
  3645. // float f2 = 1.0;
  3646. // int ie = int(fe);
  3647. // for (int i=0; i<ie; i++) {
  3648. // float t = f1;
  3649. // f1 = f2;
  3650. // f2 = t;
  3651. // }
  3652. // fo = f1;
  3653. // }
  3654. //
  3655. // Because of the swap in the for loop, it generates the following phi
  3656. // instructions:
  3657. //
  3658. // [[phi_f2]] = OpPhi %float %float_1 [[entry]] [[phi_f1]] ..
  3659. // [[phi_f1]] = OpPhi %float %float_0 [[entry]] [[phi_f2]] ..
  3660. //
  3661. // Since they are used as operands by each other, we want to clearly check
  3662. // what DebugValue we have to add for them.
  3663. const std::string text = R"(
  3664. OpCapability Shader
  3665. %1 = OpExtInstImport "GLSL.std.450"
  3666. %ext = OpExtInstImport "OpenCL.DebugInfo.100"
  3667. OpMemoryModel Logical GLSL450
  3668. OpEntryPoint Fragment %main "main" %fe %fo
  3669. OpExecutionMode %main OriginUpperLeft
  3670. OpSource GLSL 140
  3671. %file_name = OpString "test"
  3672. %float_name = OpString "float"
  3673. %main_name = OpString "main"
  3674. %t_name = OpString "t"
  3675. OpName %main "main"
  3676. OpName %f1 "f1"
  3677. OpName %f2 "f2"
  3678. OpName %ie "ie"
  3679. OpName %fe "fe"
  3680. OpName %i "i"
  3681. OpName %t "t"
  3682. OpName %fo "fo"
  3683. %void = OpTypeVoid
  3684. %11 = OpTypeFunction %void
  3685. %float = OpTypeFloat 32
  3686. %_ptr_Function_float = OpTypePointer Function %float
  3687. %float_0 = OpConstant %float 0
  3688. %float_1 = OpConstant %float 1
  3689. %int = OpTypeInt 32 1
  3690. %_ptr_Function_int = OpTypePointer Function %int
  3691. %_ptr_Input_float = OpTypePointer Input %float
  3692. %fe = OpVariable %_ptr_Input_float Input
  3693. %int_0 = OpConstant %int 0
  3694. %bool = OpTypeBool
  3695. %int_1 = OpConstant %int 1
  3696. %uint = OpTypeInt 32 0
  3697. %uint_32 = OpConstant %uint 32
  3698. %_ptr_Output_float = OpTypePointer Output %float
  3699. %fo = OpVariable %_ptr_Output_float Output
  3700. ; Debug information
  3701. %null_expr = OpExtInst %void %ext DebugExpression
  3702. %src = OpExtInst %void %ext DebugSource %file_name
  3703. %cu = OpExtInst %void %ext DebugCompilationUnit 1 4 %src HLSL
  3704. %dbg_tf = OpExtInst %void %ext DebugTypeBasic %float_name %uint_32 Float
  3705. %main_ty = OpExtInst %void %ext DebugTypeFunction FlagIsProtected|FlagIsPrivate %void
  3706. %dbg_main = OpExtInst %void %ext DebugFunction %main_name %main_ty %src 0 0 %cu %main_name FlagIsProtected|FlagIsPrivate 10 %main
  3707. %dbg_f1 = OpExtInst %void %ext DebugLocalVariable %t_name %dbg_tf %src 0 0 %dbg_main FlagIsLocal
  3708. %dbg_f2 = OpExtInst %void %ext DebugLocalVariable %t_name %dbg_tf %src 0 0 %dbg_main FlagIsLocal
  3709. %dbg_i = OpExtInst %void %ext DebugLocalVariable %t_name %dbg_tf %src 0 0 %dbg_main FlagIsLocal
  3710. %main = OpFunction %void None %11
  3711. %23 = OpLabel
  3712. %s0 = OpExtInst %void %ext DebugScope %dbg_main
  3713. %f1 = OpVariable %_ptr_Function_float Function
  3714. %f2 = OpVariable %_ptr_Function_float Function
  3715. %ie = OpVariable %_ptr_Function_int Function
  3716. %i = OpVariable %_ptr_Function_int Function
  3717. %t = OpVariable %_ptr_Function_float Function
  3718. OpStore %f1 %float_0
  3719. OpStore %f2 %float_1
  3720. %24 = OpLoad %float %fe
  3721. %25 = OpConvertFToS %int %24
  3722. OpStore %ie %25
  3723. OpStore %i %int_0
  3724. ; DebugDeclare
  3725. %decl0 = OpExtInst %void %ext DebugDeclare %dbg_f1 %f1 %null_expr
  3726. %decl1 = OpExtInst %void %ext DebugDeclare %dbg_f2 %f2 %null_expr
  3727. %decl2 = OpExtInst %void %ext DebugDeclare %dbg_i %i %null_expr
  3728. ; CHECK: %main = OpFunction %void None
  3729. ; CHECK-NEXT: [[entry:%\w+]] = OpLabel
  3730. ; CHECK: OpStore %f1 %float_0
  3731. ; CHECK-NEXT: = OpExtInst %void [[ext:%\w+]] DebugValue [[dbg_f1:%\w+]] %float_0
  3732. ; CHECK: OpStore %f2 %float_1
  3733. ; CHECK-NEXT: = OpExtInst %void [[ext]] DebugValue [[dbg_f2:%\w+]] %float_1
  3734. ; CHECK: OpStore %i %int_0
  3735. ; CHECK-NEXT: = OpExtInst %void [[ext]] DebugValue [[dbg_i:%\w+]] %int_0
  3736. ; CHECK: [[phi_f2:%\w+]] = OpPhi %float %float_1 [[entry]] [[phi_f1:%\w+]]
  3737. ; CHECK: [[phi_f1]] = OpPhi %float %float_0 [[entry]] [[phi_f2]]
  3738. ; CHECK: [[phi_i:%\w+]] = OpPhi %int %int_0 [[entry]]
  3739. ; CHECK-NEXT: = OpExtInst %void [[ext]] DebugValue [[dbg_f2]] [[phi_f2]]
  3740. ; CHECK-NEXT: = OpExtInst %void [[ext]] DebugValue [[dbg_f1]] [[phi_f1]]
  3741. ; CHECK-NEXT: = OpExtInst %void [[ext]] DebugValue [[dbg_i]] [[phi_i]]
  3742. OpBranch %26
  3743. %26 = OpLabel
  3744. %s1 = OpExtInst %void %ext DebugScope %dbg_main
  3745. OpLoopMerge %27 %28 None
  3746. OpBranch %29
  3747. %29 = OpLabel
  3748. %s2 = OpExtInst %void %ext DebugScope %dbg_main
  3749. %30 = OpLoad %int %i
  3750. %31 = OpLoad %int %ie
  3751. %32 = OpSLessThan %bool %30 %31
  3752. OpBranchConditional %32 %33 %27
  3753. %33 = OpLabel
  3754. %s3 = OpExtInst %void %ext DebugScope %dbg_main
  3755. %34 = OpLoad %float %f1
  3756. OpStore %t %34
  3757. %35 = OpLoad %float %f2
  3758. OpStore %f1 %35
  3759. %36 = OpLoad %float %t
  3760. OpStore %f2 %36
  3761. OpBranch %28
  3762. %28 = OpLabel
  3763. %s4 = OpExtInst %void %ext DebugScope %dbg_main
  3764. %37 = OpLoad %int %i
  3765. %38 = OpIAdd %int %37 %int_1
  3766. OpStore %i %38
  3767. OpBranch %26
  3768. %27 = OpLabel
  3769. %s5 = OpExtInst %void %ext DebugScope %dbg_main
  3770. %39 = OpLoad %float %f1
  3771. OpStore %fo %39
  3772. OpReturn
  3773. OpFunctionEnd
  3774. )";
  3775. SinglePassRunAndMatch<SSARewritePass>(text, true);
  3776. }
  3777. TEST_F(LocalSSAElimTest, RemoveDebugDeclareWithoutLoads) {
  3778. // Check that the DebugDeclare for c is removed even though its loads
  3779. // had been removed previously by single block store/load optimization.
  3780. // In the presence of DebugDeclare, single-block can and does remove loads,
  3781. // but cannot change the stores into DebugValues and remove the DebugDeclare
  3782. // because it is only a per block optimization, not a function optimization.
  3783. // So SSA-rewrite must perform this role.
  3784. //
  3785. // Texture2D g_tColor;
  3786. // SamplerState g_sAniso;
  3787. //
  3788. // struct PS_INPUT
  3789. // {
  3790. // float2 vTextureCoords2 : TEXCOORD2;
  3791. // float2 vTextureCoords3 : TEXCOORD3;
  3792. // };
  3793. //
  3794. // struct PS_OUTPUT
  3795. // {
  3796. // float4 vColor : SV_Target0;
  3797. // };
  3798. //
  3799. // PS_OUTPUT MainPs(PS_INPUT i)
  3800. // {
  3801. // PS_OUTPUT ps_output;
  3802. // float4 c;
  3803. // c = g_tColor.Sample(g_sAniso, i.vTextureCoords2.xy);
  3804. // c += g_tColor.Sample(g_sAniso, i.vTextureCoords3.xy);
  3805. // ps_output.vColor = c;
  3806. // return ps_output;
  3807. // }
  3808. const std::string text = R"(
  3809. OpCapability Shader
  3810. %1 = OpExtInstImport "OpenCL.DebugInfo.100"
  3811. OpMemoryModel Logical GLSL450
  3812. OpEntryPoint Fragment %MainPs "MainPs" %g_tColor %g_sAniso %in_var_TEXCOORD2 %in_var_TEXCOORD3 %out_var_SV_Target0
  3813. OpExecutionMode %MainPs OriginUpperLeft
  3814. %22 = OpString "foo.frag"
  3815. %26 = OpString "PS_OUTPUT"
  3816. %30 = OpString "float"
  3817. %33 = OpString "vColor"
  3818. %35 = OpString "PS_INPUT"
  3819. %40 = OpString "vTextureCoords3"
  3820. %42 = OpString "vTextureCoords2"
  3821. %44 = OpString "@type.2d.image"
  3822. %45 = OpString "type.2d.image"
  3823. %47 = OpString "Texture2D.TemplateParam"
  3824. %51 = OpString "src.MainPs"
  3825. %55 = OpString "c"
  3826. %57 = OpString "ps_output"
  3827. %60 = OpString "i"
  3828. %62 = OpString "@type.sampler"
  3829. %63 = OpString "type.sampler"
  3830. %65 = OpString "g_sAniso"
  3831. %67 = OpString "g_tColor"
  3832. OpName %type_2d_image "type.2d.image"
  3833. OpName %g_tColor "g_tColor"
  3834. OpName %type_sampler "type.sampler"
  3835. OpName %g_sAniso "g_sAniso"
  3836. OpName %in_var_TEXCOORD2 "in.var.TEXCOORD2"
  3837. OpName %in_var_TEXCOORD3 "in.var.TEXCOORD3"
  3838. OpName %out_var_SV_Target0 "out.var.SV_Target0"
  3839. OpName %MainPs "MainPs"
  3840. OpName %PS_INPUT "PS_INPUT"
  3841. OpMemberName %PS_INPUT 0 "vTextureCoords2"
  3842. OpMemberName %PS_INPUT 1 "vTextureCoords3"
  3843. OpName %param_var_i "param.var.i"
  3844. OpName %PS_OUTPUT "PS_OUTPUT"
  3845. OpMemberName %PS_OUTPUT 0 "vColor"
  3846. OpName %type_sampled_image "type.sampled.image"
  3847. OpDecorate %in_var_TEXCOORD2 Location 0
  3848. OpDecorate %in_var_TEXCOORD3 Location 1
  3849. OpDecorate %out_var_SV_Target0 Location 0
  3850. OpDecorate %g_tColor DescriptorSet 0
  3851. OpDecorate %g_tColor Binding 0
  3852. OpDecorate %g_sAniso DescriptorSet 0
  3853. OpDecorate %g_sAniso Binding 1
  3854. %int = OpTypeInt 32 1
  3855. %int_0 = OpConstant %int 0
  3856. %int_1 = OpConstant %int 1
  3857. %uint = OpTypeInt 32 0
  3858. %uint_32 = OpConstant %uint 32
  3859. %float = OpTypeFloat 32
  3860. %type_2d_image = OpTypeImage %float 2D 2 0 0 1 Unknown
  3861. %_ptr_UniformConstant_type_2d_image = OpTypePointer UniformConstant %type_2d_image
  3862. %type_sampler = OpTypeSampler
  3863. %_ptr_UniformConstant_type_sampler = OpTypePointer UniformConstant %type_sampler
  3864. %v2float = OpTypeVector %float 2
  3865. %_ptr_Input_v2float = OpTypePointer Input %v2float
  3866. %v4float = OpTypeVector %float 4
  3867. %_ptr_Output_v4float = OpTypePointer Output %v4float
  3868. %void = OpTypeVoid
  3869. %uint_128 = OpConstant %uint 128
  3870. %uint_0 = OpConstant %uint 0
  3871. %uint_64 = OpConstant %uint 64
  3872. %69 = OpTypeFunction %void
  3873. %PS_INPUT = OpTypeStruct %v2float %v2float
  3874. %_ptr_Function_PS_INPUT = OpTypePointer Function %PS_INPUT
  3875. %PS_OUTPUT = OpTypeStruct %v4float
  3876. %_ptr_Function_PS_OUTPUT = OpTypePointer Function %PS_OUTPUT
  3877. %_ptr_Function_v4float = OpTypePointer Function %v4float
  3878. %_ptr_Function_v2float = OpTypePointer Function %v2float
  3879. %type_sampled_image = OpTypeSampledImage %type_2d_image
  3880. %g_tColor = OpVariable %_ptr_UniformConstant_type_2d_image UniformConstant
  3881. %g_sAniso = OpVariable %_ptr_UniformConstant_type_sampler UniformConstant
  3882. %in_var_TEXCOORD2 = OpVariable %_ptr_Input_v2float Input
  3883. %in_var_TEXCOORD3 = OpVariable %_ptr_Input_v2float Input
  3884. %out_var_SV_Target0 = OpVariable %_ptr_Output_v4float Output
  3885. %43 = OpExtInst %void %1 DebugInfoNone
  3886. %59 = OpExtInst %void %1 DebugExpression
  3887. %24 = OpExtInst %void %1 DebugSource %22
  3888. %25 = OpExtInst %void %1 DebugCompilationUnit 1 4 %24 HLSL
  3889. %28 = OpExtInst %void %1 DebugTypeComposite %26 Structure %24 11 1 %25 %26 %uint_128 FlagIsProtected|FlagIsPrivate %29
  3890. %31 = OpExtInst %void %1 DebugTypeBasic %30 %uint_32 Float
  3891. %32 = OpExtInst %void %1 DebugTypeVector %31 4
  3892. %29 = OpExtInst %void %1 DebugTypeMember %33 %32 %24 13 5 %28 %uint_0 %uint_128 FlagIsProtected|FlagIsPrivate
  3893. %36 = OpExtInst %void %1 DebugTypeComposite %35 Structure %24 5 1 %25 %35 %uint_128 FlagIsProtected|FlagIsPrivate %37 %38
  3894. %39 = OpExtInst %void %1 DebugTypeVector %31 2
  3895. %38 = OpExtInst %void %1 DebugTypeMember %40 %39 %24 8 5 %36 %uint_64 %uint_64 FlagIsProtected|FlagIsPrivate
  3896. %37 = OpExtInst %void %1 DebugTypeMember %42 %39 %24 7 5 %36 %uint_0 %uint_64 FlagIsProtected|FlagIsPrivate
  3897. %46 = OpExtInst %void %1 DebugTypeComposite %44 Class %24 0 0 %25 %45 %43 FlagIsProtected|FlagIsPrivate
  3898. %50 = OpExtInst %void %1 DebugTypeFunction FlagIsProtected|FlagIsPrivate %28 %36
  3899. %52 = OpExtInst %void %1 DebugFunction %51 %50 %24 16 1 %25 %51 FlagIsProtected|FlagIsPrivate 17 %43
  3900. %54 = OpExtInst %void %1 DebugLexicalBlock %24 17 1 %52
  3901. %56 = OpExtInst %void %1 DebugLocalVariable %55 %32 %24 20 12 %54 FlagIsLocal
  3902. %58 = OpExtInst %void %1 DebugLocalVariable %57 %28 %24 18 15 %54 FlagIsLocal
  3903. %61 = OpExtInst %void %1 DebugLocalVariable %60 %36 %24 16 29 %52 FlagIsLocal 1
  3904. %64 = OpExtInst %void %1 DebugTypeComposite %62 Structure %24 0 0 %25 %63 %43 FlagIsProtected|FlagIsPrivate
  3905. %66 = OpExtInst %void %1 DebugGlobalVariable %65 %64 %24 3 14 %25 %65 %g_sAniso FlagIsDefinition
  3906. %68 = OpExtInst %void %1 DebugGlobalVariable %67 %46 %24 1 11 %25 %67 %g_tColor FlagIsDefinition
  3907. %MainPs = OpFunction %void None %69
  3908. %70 = OpLabel
  3909. %135 = OpExtInst %void %1 DebugScope %54
  3910. %111 = OpVariable %_ptr_Function_PS_OUTPUT Function
  3911. %112 = OpVariable %_ptr_Function_v4float Function
  3912. %136 = OpExtInst %void %1 DebugNoScope
  3913. %param_var_i = OpVariable %_ptr_Function_PS_INPUT Function
  3914. %74 = OpLoad %v2float %in_var_TEXCOORD2
  3915. %75 = OpLoad %v2float %in_var_TEXCOORD3
  3916. %76 = OpCompositeConstruct %PS_INPUT %74 %75
  3917. OpStore %param_var_i %76
  3918. %137 = OpExtInst %void %1 DebugScope %52
  3919. %115 = OpExtInst %void %1 DebugDeclare %61 %param_var_i %59
  3920. %138 = OpExtInst %void %1 DebugScope %54
  3921. %116 = OpExtInst %void %1 DebugDeclare %58 %111 %59
  3922. %117 = OpExtInst %void %1 DebugDeclare %56 %112 %59
  3923. ;CHECK-NOT: %117 = OpExtInst %void %1 DebugDeclare %56 %112 %59
  3924. OpLine %22 21 9
  3925. %118 = OpLoad %type_2d_image %g_tColor
  3926. OpLine %22 21 29
  3927. %119 = OpLoad %type_sampler %g_sAniso
  3928. OpLine %22 21 40
  3929. %120 = OpAccessChain %_ptr_Function_v2float %param_var_i %int_0
  3930. %121 = OpLoad %v2float %120
  3931. OpLine %22 21 9
  3932. %122 = OpSampledImage %type_sampled_image %118 %119
  3933. %123 = OpImageSampleImplicitLod %v4float %122 %121 None
  3934. OpLine %22 21 5
  3935. OpStore %112 %123
  3936. ;CHECK: %140 = OpExtInst %void %1 DebugValue %56 %123 %59
  3937. OpLine %22 22 10
  3938. %124 = OpLoad %type_2d_image %g_tColor
  3939. OpLine %22 22 30
  3940. %125 = OpLoad %type_sampler %g_sAniso
  3941. OpLine %22 22 41
  3942. %126 = OpAccessChain %_ptr_Function_v2float %param_var_i %int_1
  3943. %127 = OpLoad %v2float %126
  3944. OpLine %22 22 10
  3945. %128 = OpSampledImage %type_sampled_image %124 %125
  3946. %129 = OpImageSampleImplicitLod %v4float %128 %127 None
  3947. OpLine %22 22 7
  3948. %131 = OpFAdd %v4float %123 %129
  3949. OpLine %22 22 5
  3950. OpStore %112 %131
  3951. ;CHECK: %141 = OpExtInst %void %1 DebugValue %56 %131 %59
  3952. OpLine %22 23 5
  3953. %133 = OpAccessChain %_ptr_Function_v4float %111 %int_0
  3954. OpStore %133 %131
  3955. OpLine %22 24 12
  3956. %134 = OpLoad %PS_OUTPUT %111
  3957. %139 = OpExtInst %void %1 DebugNoScope
  3958. %79 = OpCompositeExtract %v4float %134 0
  3959. OpStore %out_var_SV_Target0 %79
  3960. OpReturn
  3961. OpFunctionEnd
  3962. )";
  3963. SetTargetEnv(SPV_ENV_VULKAN_1_2);
  3964. SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  3965. SinglePassRunAndMatch<SSARewritePass>(text, true);
  3966. }
  3967. // Check support for pointer variables. When pointer variables are used, the
  3968. // computation of reaching definitions may need to follow pointer chains.
  3969. // See https://github.com/KhronosGroup/SPIRV-Tools/issues/3873 for details.
  3970. TEST_F(LocalSSAElimTest, PointerVariables) {
  3971. const std::string text = R"(
  3972. OpCapability Shader
  3973. OpCapability VariablePointers
  3974. OpExtension "SPV_KHR_variable_pointers"
  3975. OpMemoryModel Logical Simple
  3976. OpEntryPoint Fragment %1 "main" %2 %3
  3977. OpExecutionMode %1 OriginUpperLeft
  3978. %float = OpTypeFloat 32
  3979. %void = OpTypeVoid
  3980. %6 = OpTypeFunction %void
  3981. %_ptr_Input_float = OpTypePointer Input %float
  3982. %_ptr_Output_float = OpTypePointer Output %float
  3983. %_ptr_Function__ptr_Input_float = OpTypePointer Function %_ptr_Input_float
  3984. %2 = OpVariable %_ptr_Input_float Input
  3985. %3 = OpVariable %_ptr_Output_float Output
  3986. %1 = OpFunction %void None %6
  3987. %10 = OpLabel
  3988. %11 = OpVariable %_ptr_Function__ptr_Input_float Function
  3989. OpStore %11 %2
  3990. ; CHECK-NOT: %12 = OpLoad %_ptr_Input_float %11
  3991. %12 = OpLoad %_ptr_Input_float %11
  3992. ; CHECK: %13 = OpLoad %float %2
  3993. %13 = OpLoad %float %12
  3994. OpStore %3 %13
  3995. OpReturn
  3996. OpFunctionEnd
  3997. )";
  3998. SinglePassRunAndMatch<SSARewritePass>(text, true);
  3999. }
  4000. TEST_F(LocalSSAElimTest, FunctionDeclaration) {
  4001. // Make sure the pass works with a function declaration that is called.
  4002. const std::string text = R"(OpCapability Addresses
  4003. OpCapability Linkage
  4004. OpCapability Kernel
  4005. OpCapability Int8
  4006. %1 = OpExtInstImport "OpenCL.std"
  4007. OpMemoryModel Physical64 OpenCL
  4008. OpEntryPoint Kernel %2 "_Z23julia__1166_kernel_77094Bool"
  4009. OpExecutionMode %2 ContractionOff
  4010. OpSource Unknown 0
  4011. OpDecorate %3 LinkageAttributes "julia_error_7712" Import
  4012. %void = OpTypeVoid
  4013. %5 = OpTypeFunction %void
  4014. %3 = OpFunction %void None %5
  4015. OpFunctionEnd
  4016. %2 = OpFunction %void None %5
  4017. %6 = OpLabel
  4018. %7 = OpFunctionCall %void %3
  4019. OpReturn
  4020. OpFunctionEnd
  4021. )";
  4022. SinglePassRunAndCheck<SSARewritePass>(text, text, false);
  4023. }
  4024. TEST_F(LocalSSAElimTest, MissingDebugValue) {
  4025. // Make sure DebugValue for final fragcolor assignment is generated.
  4026. const std::string text =
  4027. R"(
  4028. OpCapability Shader
  4029. OpCapability ImageQuery
  4030. OpExtension "SPV_KHR_non_semantic_info"
  4031. %1 = OpExtInstImport "GLSL.std.450"
  4032. %2 = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
  4033. OpMemoryModel Logical GLSL450
  4034. OpEntryPoint Fragment %main "main" %in_var_TEXCOORD0 %out_var_SV_TARGET %textureposition %samplerposition %textureNormal %samplerNormal %textureAlbedo %samplerAlbedo %textureShadowMap %samplerShadowMap %ubo
  4035. OpExecutionMode %main OriginUpperLeft
  4036. %15 = OpString "d2.frag"
  4037. %55 = OpString "float"
  4038. %63 = OpString "// Copyright 2020 Google LLC
  4039. Texture2D textureposition : register(t1);
  4040. SamplerState samplerposition : register(s1);
  4041. Texture2D textureNormal : register(t2);
  4042. SamplerState samplerNormal : register(s2);
  4043. Texture2D textureAlbedo : register(t3);
  4044. SamplerState samplerAlbedo : register(s3);
  4045. // Depth from the light's point of view
  4046. //layout (binding = 5) uniform sampler2DShadow samplerShadowMap;
  4047. Texture2DArray textureShadowMap : register(t5);
  4048. SamplerState samplerShadowMap : register(s5);
  4049. #define LIGHT_COUNT 3
  4050. #define SHADOW_FACTOR 0.25
  4051. #define AMBIENT_LIGHT 0.1
  4052. #define USE_PCF
  4053. struct Light
  4054. {
  4055. float4 position;
  4056. float4 target;
  4057. float4 color;
  4058. float4x4 viewMatrix;
  4059. };
  4060. struct UBO
  4061. {
  4062. float4 viewPos;
  4063. Light lights[LIGHT_COUNT];
  4064. int useShadows;
  4065. int displayDebugTarget;
  4066. };
  4067. cbuffer ubo : register(b4) { UBO ubo; }
  4068. float textureProj(float4 P, float layer, float2 offset)
  4069. {
  4070. float shadow = 1.0;
  4071. float4 shadowCoord = P / P.w;
  4072. shadowCoord.xy = shadowCoord.xy * 0.5 + 0.5;
  4073. if (shadowCoord.z > -1.0 && shadowCoord.z < 1.0)
  4074. {
  4075. float dist = textureShadowMap.Sample(samplerShadowMap, float3(shadowCoord.xy + offset, layer)).r;
  4076. if (shadowCoord.w > 0.0 && dist < shadowCoord.z)
  4077. {
  4078. shadow = SHADOW_FACTOR;
  4079. }
  4080. }
  4081. return shadow;
  4082. }
  4083. float filterPCF(float4 sc, float layer)
  4084. {
  4085. int2 texDim; int elements; int levels;
  4086. textureShadowMap.GetDimensions(0, texDim.x, texDim.y, elements, levels);
  4087. float scale = 1.5;
  4088. float dx = scale * 1.0 / float(texDim.x);
  4089. float dy = scale * 1.0 / float(texDim.y);
  4090. float shadowFactor = 0.0;
  4091. int count = 0;
  4092. int range = 1;
  4093. for (int x = -range; x <= range; x++)
  4094. {
  4095. for (int y = -range; y <= range; y++)
  4096. {
  4097. shadowFactor += textureProj(sc, layer, float2(dx*x, dy*y));
  4098. count++;
  4099. }
  4100. }
  4101. return shadowFactor / count;
  4102. }
  4103. float3 shadow(float3 fragcolor, float3 fragPos) {
  4104. for (int i = 0; i < LIGHT_COUNT; ++i)
  4105. {
  4106. float4 shadowClip = mul(ubo.lights[i].viewMatrix, float4(fragPos.xyz, 1.0));
  4107. float shadowFactor;
  4108. #ifdef USE_PCF
  4109. shadowFactor= filterPCF(shadowClip, i);
  4110. #else
  4111. shadowFactor = textureProj(shadowClip, i, float2(0.0, 0.0));
  4112. #endif
  4113. fragcolor *= shadowFactor;
  4114. }
  4115. return fragcolor;
  4116. }
  4117. float4 main([[vk::location(0)]] float2 inUV : TEXCOORD0) : SV_TARGET
  4118. {
  4119. // Get G-Buffer values
  4120. float3 fragPos = textureposition.Sample(samplerposition, inUV).rgb;
  4121. float3 normal = textureNormal.Sample(samplerNormal, inUV).rgb;
  4122. float4 albedo = textureAlbedo.Sample(samplerAlbedo, inUV);
  4123. // Ambient part
  4124. float3 fragcolor = albedo.rgb * AMBIENT_LIGHT;
  4125. float3 N = normalize(normal);
  4126. for(int i = 0; i < LIGHT_COUNT; ++i)
  4127. {
  4128. // Vector to light
  4129. float3 L = ubo.lights[i].position.xyz - fragPos;
  4130. // Distance from light to fragment position
  4131. float dist = length(L);
  4132. L = normalize(L);
  4133. // Viewer to fragment
  4134. float3 V = ubo.viewPos.xyz - fragPos;
  4135. V = normalize(V);
  4136. float lightCosInnerAngle = cos(radians(15.0));
  4137. float lightCosOuterAngle = cos(radians(25.0));
  4138. float lightRange = 100.0;
  4139. // Direction vector from source to target
  4140. float3 dir = normalize(ubo.lights[i].position.xyz - ubo.lights[i].target.xyz);
  4141. // Dual cone spot light with smooth transition between inner and outer angle
  4142. float cosDir = dot(L, dir);
  4143. float spotEffect = smoothstep(lightCosOuterAngle, lightCosInnerAngle, cosDir);
  4144. float heightAttenuation = smoothstep(lightRange, 0.0f, dist);
  4145. // Diffuse lighting
  4146. float NdotL = max(0.0, dot(N, L));
  4147. float3 diff = NdotL.xxx;
  4148. // Specular lighting
  4149. float3 R = reflect(-L, N);
  4150. float NdotR = max(0.0, dot(R, V));
  4151. float3 spec = (pow(NdotR, 16.0) * albedo.a * 2.5).xxx;
  4152. fragcolor += float3((diff + spec) * spotEffect * heightAttenuation) * ubo.lights[i].color.rgb * albedo.rgb;
  4153. }
  4154. // Shadow calculations in a separate pass
  4155. if (ubo.useShadows > 0)
  4156. {
  4157. fragcolor = shadow(fragcolor, fragPos);
  4158. }
  4159. return float4(fragcolor, 1);
  4160. }
  4161. "
  4162. %68 = OpString "textureProj"
  4163. %69 = OpString ""
  4164. %78 = OpString "dist"
  4165. %82 = OpString "shadowCoord"
  4166. %85 = OpString "shadow"
  4167. %89 = OpString "offset"
  4168. %92 = OpString "layer"
  4169. %95 = OpString "P"
  4170. %99 = OpString "filterPCF"
  4171. %108 = OpString "int"
  4172. %110 = OpString "y"
  4173. %114 = OpString "x"
  4174. %118 = OpString "range"
  4175. %122 = OpString "count"
  4176. %125 = OpString "shadowFactor"
  4177. %128 = OpString "dy"
  4178. %131 = OpString "dx"
  4179. %134 = OpString "scale"
  4180. %137 = OpString "levels"
  4181. %141 = OpString "elements"
  4182. %145 = OpString "texDim"
  4183. %150 = OpString "sc"
  4184. %162 = OpString "shadowClip"
  4185. %166 = OpString "i"
  4186. %169 = OpString "fragPos"
  4187. %171 = OpString "fragcolor"
  4188. %175 = OpString "main"
  4189. %184 = OpString "spec"
  4190. %187 = OpString "NdotR"
  4191. %190 = OpString "R"
  4192. %193 = OpString "diff"
  4193. %196 = OpString "NdotL"
  4194. %199 = OpString "heightAttenuation"
  4195. %202 = OpString "spotEffect"
  4196. %205 = OpString "cosDir"
  4197. %208 = OpString "dir"
  4198. %211 = OpString "lightRange"
  4199. %214 = OpString "lightCosOuterAngle"
  4200. %217 = OpString "lightCosInnerAngle"
  4201. %220 = OpString "V"
  4202. %225 = OpString "L"
  4203. %230 = OpString "N"
  4204. %235 = OpString "albedo"
  4205. %238 = OpString "normal"
  4206. %244 = OpString "inUV"
  4207. %246 = OpString "viewPos"
  4208. %249 = OpString "position"
  4209. %252 = OpString "target"
  4210. %254 = OpString "color"
  4211. %259 = OpString "viewMatrix"
  4212. %263 = OpString "Light"
  4213. %267 = OpString "lights"
  4214. %271 = OpString "useShadows"
  4215. %275 = OpString "displayDebugTarget"
  4216. %278 = OpString "UBO"
  4217. %282 = OpString "ubo"
  4218. %285 = OpString "type.ubo"
  4219. %289 = OpString "@type.sampler"
  4220. %290 = OpString "type.sampler"
  4221. %292 = OpString "samplerShadowMap"
  4222. %295 = OpString "@type.2d.image.array"
  4223. %296 = OpString "type.2d.image.array"
  4224. %298 = OpString "TemplateParam"
  4225. %301 = OpString "textureShadowMap"
  4226. %304 = OpString "samplerAlbedo"
  4227. %306 = OpString "@type.2d.image"
  4228. %307 = OpString "type.2d.image"
  4229. %311 = OpString "textureAlbedo"
  4230. %313 = OpString "samplerNormal"
  4231. %315 = OpString "textureNormal"
  4232. %317 = OpString "samplerposition"
  4233. %319 = OpString "textureposition"
  4234. OpName %type_2d_image "type.2d.image"
  4235. OpName %textureposition "textureposition"
  4236. OpName %type_sampler "type.sampler"
  4237. OpName %samplerposition "samplerposition"
  4238. OpName %textureNormal "textureNormal"
  4239. OpName %samplerNormal "samplerNormal"
  4240. OpName %textureAlbedo "textureAlbedo"
  4241. OpName %samplerAlbedo "samplerAlbedo"
  4242. OpName %type_2d_image_array "type.2d.image.array"
  4243. OpName %textureShadowMap "textureShadowMap"
  4244. OpName %samplerShadowMap "samplerShadowMap"
  4245. OpName %type_ubo "type.ubo"
  4246. OpMemberName %type_ubo 0 "ubo"
  4247. OpName %UBO "UBO"
  4248. OpMemberName %UBO 0 "viewPos"
  4249. OpMemberName %UBO 1 "lights"
  4250. OpMemberName %UBO 2 "useShadows"
  4251. OpMemberName %UBO 3 "displayDebugTarget"
  4252. OpName %Light "Light"
  4253. OpMemberName %Light 0 "position"
  4254. OpMemberName %Light 1 "target"
  4255. OpMemberName %Light 2 "color"
  4256. OpMemberName %Light 3 "viewMatrix"
  4257. OpName %ubo "ubo"
  4258. OpName %in_var_TEXCOORD0 "in.var.TEXCOORD0"
  4259. OpName %out_var_SV_TARGET "out.var.SV_TARGET"
  4260. OpName %main "main"
  4261. OpName %param_var_inUV "param.var.inUV"
  4262. OpName %type_sampled_image "type.sampled.image"
  4263. OpName %type_sampled_image_0 "type.sampled.image"
  4264. OpDecorate %in_var_TEXCOORD0 Location 0
  4265. OpDecorate %out_var_SV_TARGET Location 0
  4266. OpDecorate %textureposition DescriptorSet 0
  4267. OpDecorate %textureposition Binding 1
  4268. OpDecorate %samplerposition DescriptorSet 0
  4269. OpDecorate %samplerposition Binding 1
  4270. OpDecorate %textureNormal DescriptorSet 0
  4271. OpDecorate %textureNormal Binding 2
  4272. OpDecorate %samplerNormal DescriptorSet 0
  4273. OpDecorate %samplerNormal Binding 2
  4274. OpDecorate %textureAlbedo DescriptorSet 0
  4275. OpDecorate %textureAlbedo Binding 3
  4276. OpDecorate %samplerAlbedo DescriptorSet 0
  4277. OpDecorate %samplerAlbedo Binding 3
  4278. OpDecorate %textureShadowMap DescriptorSet 0
  4279. OpDecorate %textureShadowMap Binding 5
  4280. OpDecorate %samplerShadowMap DescriptorSet 0
  4281. OpDecorate %samplerShadowMap Binding 5
  4282. OpDecorate %ubo DescriptorSet 0
  4283. OpDecorate %ubo Binding 4
  4284. OpMemberDecorate %Light 0 Offset 0
  4285. OpMemberDecorate %Light 1 Offset 16
  4286. OpMemberDecorate %Light 2 Offset 32
  4287. OpMemberDecorate %Light 3 Offset 48
  4288. OpMemberDecorate %Light 3 MatrixStride 16
  4289. OpMemberDecorate %Light 3 RowMajor
  4290. OpDecorate %_arr_Light_uint_3 ArrayStride 112
  4291. OpMemberDecorate %UBO 0 Offset 0
  4292. OpMemberDecorate %UBO 1 Offset 16
  4293. OpMemberDecorate %UBO 2 Offset 352
  4294. OpMemberDecorate %UBO 3 Offset 356
  4295. OpMemberDecorate %type_ubo 0 Offset 0
  4296. OpDecorate %type_ubo Block
  4297. )"
  4298. R"( %float = OpTypeFloat 32
  4299. %float_0_100000001 = OpConstant %float 0.100000001
  4300. %int = OpTypeInt 32 1
  4301. %int_0 = OpConstant %int 0
  4302. %int_3 = OpConstant %int 3
  4303. %int_1 = OpConstant %int 1
  4304. %float_15 = OpConstant %float 15
  4305. %float_25 = OpConstant %float 25
  4306. %float_100 = OpConstant %float 100
  4307. %float_0 = OpConstant %float 0
  4308. %float_16 = OpConstant %float 16
  4309. %float_2_5 = OpConstant %float 2.5
  4310. %int_2 = OpConstant %int 2
  4311. %float_1 = OpConstant %float 1
  4312. %uint = OpTypeInt 32 0
  4313. %uint_0 = OpConstant %uint 0
  4314. %float_1_5 = OpConstant %float 1.5
  4315. %float_0_5 = OpConstant %float 0.5
  4316. %v2float = OpTypeVector %float 2
  4317. %35 = OpConstantComposite %v2float %float_0_5 %float_0_5
  4318. %float_n1 = OpConstant %float -1
  4319. %float_0_25 = OpConstant %float 0.25
  4320. %uint_32 = OpConstant %uint 32
  4321. %type_2d_image = OpTypeImage %float 2D 2 0 0 1 Unknown
  4322. %_ptr_UniformConstant_type_2d_image = OpTypePointer UniformConstant %type_2d_image
  4323. %type_sampler = OpTypeSampler
  4324. %_ptr_UniformConstant_type_sampler = OpTypePointer UniformConstant %type_sampler
  4325. %type_2d_image_array = OpTypeImage %float 2D 2 1 0 1 Unknown
  4326. %_ptr_UniformConstant_type_2d_image_array = OpTypePointer UniformConstant %type_2d_image_array
  4327. %v4float = OpTypeVector %float 4
  4328. %uint_3 = OpConstant %uint 3
  4329. %mat4v4float = OpTypeMatrix %v4float 4
  4330. %Light = OpTypeStruct %v4float %v4float %v4float %mat4v4float
  4331. %_arr_Light_uint_3 = OpTypeArray %Light %uint_3
  4332. %UBO = OpTypeStruct %v4float %_arr_Light_uint_3 %int %int
  4333. %type_ubo = OpTypeStruct %UBO
  4334. %_ptr_Uniform_type_ubo = OpTypePointer Uniform %type_ubo
  4335. %_ptr_Input_v2float = OpTypePointer Input %v2float
  4336. %_ptr_Output_v4float = OpTypePointer Output %v4float
  4337. %void = OpTypeVoid
  4338. %uint_4 = OpConstant %uint 4
  4339. %uint_2 = OpConstant %uint 2
  4340. %uint_1 = OpConstant %uint 1
  4341. %uint_5 = OpConstant %uint 5
  4342. %uint_37 = OpConstant %uint 37
  4343. %uint_38 = OpConstant %uint 38
  4344. %uint_44 = OpConstant %uint 44
  4345. %uint_47 = OpConstant %uint 47
  4346. %uint_45 = OpConstant %uint 45
  4347. %uint_9 = OpConstant %uint 9
  4348. %uint_40 = OpConstant %uint 40
  4349. %uint_39 = OpConstant %uint 39
  4350. %uint_8 = OpConstant %uint 8
  4351. %uint_49 = OpConstant %uint 49
  4352. %uint_35 = OpConstant %uint 35
  4353. %uint_26 = OpConstant %uint 26
  4354. %uint_54 = OpConstant %uint 54
  4355. %uint_55 = OpConstant %uint 55
  4356. %uint_67 = OpConstant %uint 67
  4357. %uint_69 = OpConstant %uint 69
  4358. %uint_68 = OpConstant %uint 68
  4359. %uint_12 = OpConstant %uint 12
  4360. %uint_66 = OpConstant %uint 66
  4361. %uint_11 = OpConstant %uint 11
  4362. %uint_64 = OpConstant %uint 64
  4363. %uint_6 = OpConstant %uint 6
  4364. %uint_63 = OpConstant %uint 63
  4365. %uint_62 = OpConstant %uint 62
  4366. %uint_60 = OpConstant %uint 60
  4367. %uint_59 = OpConstant %uint 59
  4368. %uint_58 = OpConstant %uint 58
  4369. %uint_56 = OpConstant %uint 56
  4370. %uint_33 = OpConstant %uint 33
  4371. %uint_19 = OpConstant %uint 19
  4372. %uint_7 = OpConstant %uint 7
  4373. %uint_34 = OpConstant %uint 34
  4374. %uint_24 = OpConstant %uint 24
  4375. %uint_78 = OpConstant %uint 78
  4376. %uint_80 = OpConstant %uint 80
  4377. %uint_83 = OpConstant %uint 83
  4378. %uint_81 = OpConstant %uint 81
  4379. %uint_10 = OpConstant %uint 10
  4380. %uint_79 = OpConstant %uint 79
  4381. %uint_22 = OpConstant %uint 22
  4382. %uint_95 = OpConstant %uint 95
  4383. %uint_96 = OpConstant %uint 96
  4384. %uint_145 = OpConstant %uint 145
  4385. %uint_108 = OpConstant %uint 108
  4386. %uint_138 = OpConstant %uint 138
  4387. %uint_137 = OpConstant %uint 137
  4388. %uint_136 = OpConstant %uint 136
  4389. %uint_133 = OpConstant %uint 133
  4390. %uint_132 = OpConstant %uint 132
  4391. %uint_129 = OpConstant %uint 129
  4392. %uint_128 = OpConstant %uint 128
  4393. %uint_127 = OpConstant %uint 127
  4394. %uint_124 = OpConstant %uint 124
  4395. %uint_121 = OpConstant %uint 121
  4396. %uint_120 = OpConstant %uint 120
  4397. %uint_119 = OpConstant %uint 119
  4398. %uint_116 = OpConstant %uint 116
  4399. %uint_112 = OpConstant %uint 112
  4400. %uint_110 = OpConstant %uint 110
  4401. %uint_107 = OpConstant %uint 107
  4402. %uint_105 = OpConstant %uint 105
  4403. %uint_103 = OpConstant %uint 103
  4404. %uint_100 = OpConstant %uint 100
  4405. %uint_99 = OpConstant %uint 99
  4406. %uint_98 = OpConstant %uint 98
  4407. %uint_29 = OpConstant %uint 29
  4408. %uint_21 = OpConstant %uint 21
  4409. %uint_256 = OpConstant %uint 256
  4410. %uint_23 = OpConstant %uint 23
  4411. %uint_384 = OpConstant %uint 384
  4412. %uint_512 = OpConstant %uint 512
  4413. %uint_896 = OpConstant %uint 896
  4414. %uint_2688 = OpConstant %uint 2688
  4415. %uint_30 = OpConstant %uint 30
  4416. %uint_2816 = OpConstant %uint 2816
  4417. %uint_31 = OpConstant %uint 31
  4418. %uint_2848 = OpConstant %uint 2848
  4419. %uint_2880 = OpConstant %uint 2880
  4420. %uint_27 = OpConstant %uint 27
  4421. %uint_2944 = OpConstant %uint 2944
  4422. %uint_14 = OpConstant %uint 14
  4423. %uint_16 = OpConstant %uint 16
  4424. %321 = OpTypeFunction %void
  4425. %_ptr_Function_v2float = OpTypePointer Function %v2float
  4426. %uint_150 = OpConstant %uint 150
  4427. %v3float = OpTypeVector %float 3
  4428. %_ptr_Function_v3float = OpTypePointer Function %v3float
  4429. %_ptr_Function_v4float = OpTypePointer Function %v4float
  4430. %_ptr_Function_int = OpTypePointer Function %int
  4431. %_ptr_Function_float = OpTypePointer Function %float
  4432. %uint_42 = OpConstant %uint 42
  4433. %type_sampled_image = OpTypeSampledImage %type_2d_image
  4434. %uint_65 = OpConstant %uint 65
  4435. %uint_18 = OpConstant %uint 18
  4436. %uint_13 = OpConstant %uint 13
  4437. %uint_15 = OpConstant %uint 15
  4438. %uint_17 = OpConstant %uint 17
  4439. %bool = OpTypeBool
  4440. %uint_25 = OpConstant %uint 25
  4441. %_ptr_Uniform_UBO = OpTypePointer Uniform %UBO
  4442. %_ptr_Uniform_v4float = OpTypePointer Uniform %v4float
  4443. %uint_28 = OpConstant %uint 28
  4444. %uint_43 = OpConstant %uint 43
  4445. %uint_113 = OpConstant %uint 113
  4446. %uint_117 = OpConstant %uint 117
  4447. %uint_46 = OpConstant %uint 46
  4448. %uint_76 = OpConstant %uint 76
  4449. %uint_53 = OpConstant %uint 53
  4450. %uint_73 = OpConstant %uint 73
  4451. %uint_48 = OpConstant %uint 48
  4452. %uint_140 = OpConstant %uint 140
  4453. %uint_52 = OpConstant %uint 52
  4454. %uint_93 = OpConstant %uint 93
  4455. %uint_87 = OpConstant %uint 87
  4456. %uint_106 = OpConstant %uint 106
  4457. %uint_36 = OpConstant %uint 36
  4458. %uint_144 = OpConstant %uint 144
  4459. %_ptr_Uniform_int = OpTypePointer Uniform %int
  4460. %uint_146 = OpConstant %uint 146
  4461. %uint_147 = OpConstant %uint 147
  4462. %uint_149 = OpConstant %uint 149
  4463. %uint_41 = OpConstant %uint 41
  4464. %_ptr_Uniform_mat4v4float = OpTypePointer Uniform %mat4v4float
  4465. %uint_77 = OpConstant %uint 77
  4466. %uint_85 = OpConstant %uint 85
  4467. %uint_90 = OpConstant %uint 90
  4468. %uint_92 = OpConstant %uint 92
  4469. %v2int = OpTypeVector %int 2
  4470. %_ptr_Function_v2int = OpTypePointer Function %v2int
  4471. %uint_57 = OpConstant %uint 57
  4472. %v3uint = OpTypeVector %uint 3
  4473. %uint_72 = OpConstant %uint 72
  4474. %uint_70 = OpConstant %uint 70
  4475. %uint_50 = OpConstant %uint 50
  4476. %uint_61 = OpConstant %uint 61
  4477. %uint_71 = OpConstant %uint 71
  4478. %uint_75 = OpConstant %uint 75
  4479. %uint_82 = OpConstant %uint 82
  4480. %type_sampled_image_0 = OpTypeSampledImage %type_2d_image_array
  4481. %uint_51 = OpConstant %uint 51
  4482. %textureposition = OpVariable %_ptr_UniformConstant_type_2d_image UniformConstant
  4483. %samplerposition = OpVariable %_ptr_UniformConstant_type_sampler UniformConstant
  4484. %textureNormal = OpVariable %_ptr_UniformConstant_type_2d_image UniformConstant
  4485. %samplerNormal = OpVariable %_ptr_UniformConstant_type_sampler UniformConstant
  4486. %textureAlbedo = OpVariable %_ptr_UniformConstant_type_2d_image UniformConstant
  4487. %samplerAlbedo = OpVariable %_ptr_UniformConstant_type_sampler UniformConstant
  4488. %textureShadowMap = OpVariable %_ptr_UniformConstant_type_2d_image_array UniformConstant
  4489. %samplerShadowMap = OpVariable %_ptr_UniformConstant_type_sampler UniformConstant
  4490. %ubo = OpVariable %_ptr_Uniform_type_ubo Uniform
  4491. %in_var_TEXCOORD0 = OpVariable %_ptr_Input_v2float Input
  4492. %out_var_SV_TARGET = OpVariable %_ptr_Output_v4float Output
  4493. %uint_1792 = OpConstant %uint 1792
  4494. %uint_1869 = OpConstant %uint 1869
  4495. %uint_2060 = OpConstant %uint 2060
  4496. %288 = OpExtInst %void %2 DebugInfoNone
  4497. %243 = OpExtInst %void %2 DebugExpression
  4498. %57 = OpExtInst %void %2 DebugTypeBasic %55 %uint_32 %uint_3 %uint_0
  4499. %58 = OpExtInst %void %2 DebugTypeVector %57 %uint_4
  4500. %60 = OpExtInst %void %2 DebugTypeVector %57 %uint_2
  4501. %62 = OpExtInst %void %2 DebugTypeFunction %uint_3 %57 %58 %57 %60
  4502. %64 = OpExtInst %void %2 DebugSource %15 %63
  4503. %65 = OpExtInst %void %2 DebugCompilationUnit %uint_1 %uint_4 %64 %uint_5
  4504. %70 = OpExtInst %void %2 DebugFunction %68 %62 %64 %uint_37 %uint_1 %65 %69 %uint_3 %uint_38
  4505. %73 = OpExtInst %void %2 DebugLexicalBlock %64 %uint_38 %uint_1 %70
  4506. %74 = OpExtInst %void %2 DebugLexicalBlock %64 %uint_44 %uint_2 %73
  4507. %76 = OpExtInst %void %2 DebugLexicalBlock %64 %uint_47 %uint_3 %74
  4508. %79 = OpExtInst %void %2 DebugLocalVariable %78 %57 %64 %uint_45 %uint_9 %74 %uint_4
  4509. %83 = OpExtInst %void %2 DebugLocalVariable %82 %58 %64 %uint_40 %uint_9 %73 %uint_4
  4510. %86 = OpExtInst %void %2 DebugLocalVariable %85 %57 %64 %uint_39 %uint_8 %73 %uint_4
  4511. %90 = OpExtInst %void %2 DebugLocalVariable %89 %60 %64 %uint_37 %uint_49 %70 %uint_4 %uint_3
  4512. %93 = OpExtInst %void %2 DebugLocalVariable %92 %57 %64 %uint_37 %uint_35 %70 %uint_4 %uint_2
  4513. %96 = OpExtInst %void %2 DebugLocalVariable %95 %58 %64 %uint_37 %uint_26 %70 %uint_4 %uint_1
  4514. %98 = OpExtInst %void %2 DebugTypeFunction %uint_3 %57 %58 %57
  4515. %100 = OpExtInst %void %2 DebugFunction %99 %98 %64 %uint_54 %uint_1 %65 %69 %uint_3 %uint_55
  4516. %103 = OpExtInst %void %2 DebugLexicalBlock %64 %uint_55 %uint_1 %100
  4517. %104 = OpExtInst %void %2 DebugLexicalBlock %64 %uint_67 %uint_2 %103
  4518. %106 = OpExtInst %void %2 DebugLexicalBlock %64 %uint_69 %uint_3 %104
  4519. %109 = OpExtInst %void %2 DebugTypeBasic %108 %uint_32 %uint_4 %uint_0
  4520. %111 = OpExtInst %void %2 DebugLocalVariable %110 %109 %64 %uint_68 %uint_12 %104 %uint_4
  4521. %115 = OpExtInst %void %2 DebugLocalVariable %114 %109 %64 %uint_66 %uint_11 %103 %uint_4
  4522. %119 = OpExtInst %void %2 DebugLocalVariable %118 %109 %64 %uint_64 %uint_6 %103 %uint_4
  4523. %123 = OpExtInst %void %2 DebugLocalVariable %122 %109 %64 %uint_63 %uint_6 %103 %uint_4
  4524. %126 = OpExtInst %void %2 DebugLocalVariable %125 %57 %64 %uint_62 %uint_8 %103 %uint_4
  4525. %129 = OpExtInst %void %2 DebugLocalVariable %128 %57 %64 %uint_60 %uint_8 %103 %uint_4
  4526. %132 = OpExtInst %void %2 DebugLocalVariable %131 %57 %64 %uint_59 %uint_8 %103 %uint_4
  4527. %135 = OpExtInst %void %2 DebugLocalVariable %134 %57 %64 %uint_58 %uint_8 %103 %uint_4
  4528. %138 = OpExtInst %void %2 DebugLocalVariable %137 %109 %64 %uint_56 %uint_33 %103 %uint_4
  4529. %142 = OpExtInst %void %2 DebugLocalVariable %141 %109 %64 %uint_56 %uint_19 %103 %uint_4
  4530. %144 = OpExtInst %void %2 DebugTypeVector %109 %uint_2
  4531. %146 = OpExtInst %void %2 DebugLocalVariable %145 %144 %64 %uint_56 %uint_7 %103 %uint_4
  4532. %148 = OpExtInst %void %2 DebugLocalVariable %92 %57 %64 %uint_54 %uint_34 %100 %uint_4 %uint_2
  4533. %151 = OpExtInst %void %2 DebugLocalVariable %150 %58 %64 %uint_54 %uint_24 %100 %uint_4 %uint_1
  4534. %153 = OpExtInst %void %2 DebugTypeVector %57 %uint_3
  4535. %154 = OpExtInst %void %2 DebugTypeFunction %uint_3 %153 %153 %153
  4536. %155 = OpExtInst %void %2 DebugFunction %85 %154 %64 %uint_78 %uint_1 %65 %69 %uint_3 %uint_78
  4537. %157 = OpExtInst %void %2 DebugLexicalBlock %64 %uint_78 %uint_49 %155
  4538. %158 = OpExtInst %void %2 DebugLexicalBlock %64 %uint_80 %uint_2 %157
  4539. %160 = OpExtInst %void %2 DebugLocalVariable %125 %57 %64 %uint_83 %uint_9 %158 %uint_4
  4540. %163 = OpExtInst %void %2 DebugLocalVariable %162 %58 %64 %uint_81 %uint_10 %158 %uint_4
  4541. %167 = OpExtInst %void %2 DebugLocalVariable %166 %109 %64 %uint_79 %uint_11 %157 %uint_4
  4542. %170 = OpExtInst %void %2 DebugLocalVariable %169 %153 %64 %uint_78 %uint_40 %155 %uint_4 %uint_2
  4543. %172 = OpExtInst %void %2 DebugLocalVariable %171 %153 %64 %uint_78 %uint_22 %155 %uint_4 %uint_1
  4544. %174 = OpExtInst %void %2 DebugTypeFunction %uint_3 %58 %60
  4545. %176 = OpExtInst %void %2 DebugFunction %175 %174 %64 %uint_95 %uint_1 %65 %69 %uint_3 %uint_96
  4546. %179 = OpExtInst %void %2 DebugLexicalBlock %64 %uint_96 %uint_1 %176
  4547. %180 = OpExtInst %void %2 DebugLexicalBlock %64 %uint_145 %uint_2 %179
  4548. %182 = OpExtInst %void %2 DebugLexicalBlock %64 %uint_108 %uint_2 %179
  4549. %185 = OpExtInst %void %2 DebugLocalVariable %184 %153 %64 %uint_138 %uint_10 %182 %uint_4
  4550. %188 = OpExtInst %void %2 DebugLocalVariable %187 %57 %64 %uint_137 %uint_9 %182 %uint_4
  4551. %191 = OpExtInst %void %2 DebugLocalVariable %190 %153 %64 %uint_136 %uint_10 %182 %uint_4
  4552. %194 = OpExtInst %void %2 DebugLocalVariable %193 %153 %64 %uint_133 %uint_10 %182 %uint_4
  4553. %197 = OpExtInst %void %2 DebugLocalVariable %196 %57 %64 %uint_132 %uint_9 %182 %uint_4
  4554. %200 = OpExtInst %void %2 DebugLocalVariable %199 %57 %64 %uint_129 %uint_9 %182 %uint_4
  4555. %203 = OpExtInst %void %2 DebugLocalVariable %202 %57 %64 %uint_128 %uint_9 %182 %uint_4
  4556. %206 = OpExtInst %void %2 DebugLocalVariable %205 %57 %64 %uint_127 %uint_9 %182 %uint_4
  4557. %209 = OpExtInst %void %2 DebugLocalVariable %208 %153 %64 %uint_124 %uint_10 %182 %uint_4
  4558. %212 = OpExtInst %void %2 DebugLocalVariable %211 %57 %64 %uint_121 %uint_9 %182 %uint_4
  4559. %215 = OpExtInst %void %2 DebugLocalVariable %214 %57 %64 %uint_120 %uint_9 %182 %uint_4
  4560. %218 = OpExtInst %void %2 DebugLocalVariable %217 %57 %64 %uint_119 %uint_9 %182 %uint_4
  4561. %221 = OpExtInst %void %2 DebugLocalVariable %220 %153 %64 %uint_116 %uint_10 %182 %uint_4
  4562. %223 = OpExtInst %void %2 DebugLocalVariable %78 %57 %64 %uint_112 %uint_9 %182 %uint_4
  4563. %226 = OpExtInst %void %2 DebugLocalVariable %225 %153 %64 %uint_110 %uint_10 %182 %uint_4
  4564. %228 = OpExtInst %void %2 DebugLocalVariable %166 %109 %64 %uint_107 %uint_10 %179 %uint_4
  4565. %231 = OpExtInst %void %2 DebugLocalVariable %230 %153 %64 %uint_105 %uint_9 %179 %uint_4
  4566. %233 = OpExtInst %void %2 DebugLocalVariable %171 %153 %64 %uint_103 %uint_9 %179 %uint_4
  4567. %236 = OpExtInst %void %2 DebugLocalVariable %235 %58 %64 %uint_100 %uint_9 %179 %uint_4
  4568. %239 = OpExtInst %void %2 DebugLocalVariable %238 %153 %64 %uint_99 %uint_9 %179 %uint_4
  4569. %241 = OpExtInst %void %2 DebugLocalVariable %169 %153 %64 %uint_98 %uint_9 %179 %uint_4
  4570. %245 = OpExtInst %void %2 DebugLocalVariable %244 %60 %64 %uint_95 %uint_40 %176 %uint_4 %uint_1
  4571. )"
  4572. R"( %247 = OpExtInst %void %2 DebugTypeMember %246 %58 %64 %uint_29 %uint_9 %uint_0 %uint_128 %uint_3
  4573. %250 = OpExtInst %void %2 DebugTypeMember %249 %58 %64 %uint_21 %uint_9 %uint_0 %uint_128 %uint_3
  4574. %253 = OpExtInst %void %2 DebugTypeMember %252 %58 %64 %uint_22 %uint_9 %uint_128 %uint_128 %uint_3
  4575. %256 = OpExtInst %void %2 DebugTypeMember %254 %58 %64 %uint_23 %uint_9 %uint_256 %uint_128 %uint_3
  4576. %258 = OpExtInst %void %2 DebugTypeArray %57 %uint_4 %uint_4
  4577. %262 = OpExtInst %void %2 DebugTypeMember %259 %258 %64 %uint_24 %uint_11 %uint_384 %uint_512 %uint_3
  4578. %265 = OpExtInst %void %2 DebugTypeComposite %263 %uint_1 %64 %uint_19 %uint_8 %65 %263 %uint_896 %uint_3 %250 %253 %256 %262
  4579. %266 = OpExtInst %void %2 DebugTypeArray %265 %uint_3
  4580. %269 = OpExtInst %void %2 DebugTypeMember %267 %266 %64 %uint_30 %uint_8 %uint_128 %uint_2688 %uint_3
  4581. %273 = OpExtInst %void %2 DebugTypeMember %271 %109 %64 %uint_31 %uint_6 %uint_2816 %uint_32 %uint_3
  4582. %277 = OpExtInst %void %2 DebugTypeMember %275 %109 %64 %uint_32 %uint_6 %uint_2848 %uint_32 %uint_3
  4583. %280 = OpExtInst %void %2 DebugTypeComposite %278 %uint_1 %64 %uint_27 %uint_8 %65 %278 %uint_2880 %uint_3 %247 %269 %273 %277
  4584. %284 = OpExtInst %void %2 DebugTypeMember %282 %280 %64 %uint_35 %uint_34 %uint_0 %uint_2944 %uint_3
  4585. %286 = OpExtInst %void %2 DebugTypeComposite %285 %uint_1 %64 %uint_35 %uint_9 %65 %285 %uint_2944 %uint_3 %284
  4586. %287 = OpExtInst %void %2 DebugGlobalVariable %282 %286 %64 %uint_35 %uint_9 %65 %282 %ubo %uint_8
  4587. %291 = OpExtInst %void %2 DebugTypeComposite %289 %uint_1 %64 %uint_0 %uint_0 %65 %290 %288 %uint_3
  4588. %293 = OpExtInst %void %2 DebugGlobalVariable %292 %291 %64 %uint_12 %uint_14 %65 %292 %samplerShadowMap %uint_8
  4589. %297 = OpExtInst %void %2 DebugTypeComposite %295 %uint_0 %64 %uint_0 %uint_0 %65 %296 %288 %uint_3
  4590. %299 = OpExtInst %void %2 DebugTypeTemplateParameter %298 %58 %288 %64 %uint_0 %uint_0
  4591. %300 = OpExtInst %void %2 DebugTypeTemplate %297 %299
  4592. %302 = OpExtInst %void %2 DebugGlobalVariable %301 %300 %64 %uint_11 %uint_16 %65 %301 %textureShadowMap %uint_8
  4593. %305 = OpExtInst %void %2 DebugGlobalVariable %304 %291 %64 %uint_8 %uint_14 %65 %304 %samplerAlbedo %uint_8
  4594. %308 = OpExtInst %void %2 DebugTypeComposite %306 %uint_0 %64 %uint_0 %uint_0 %65 %307 %288 %uint_3
  4595. %309 = OpExtInst %void %2 DebugTypeTemplateParameter %298 %58 %288 %64 %uint_0 %uint_0
  4596. %310 = OpExtInst %void %2 DebugTypeTemplate %308 %309
  4597. %312 = OpExtInst %void %2 DebugGlobalVariable %311 %310 %64 %uint_7 %uint_11 %65 %311 %textureAlbedo %uint_8
  4598. %314 = OpExtInst %void %2 DebugGlobalVariable %313 %291 %64 %uint_6 %uint_14 %65 %313 %samplerNormal %uint_8
  4599. %316 = OpExtInst %void %2 DebugGlobalVariable %315 %310 %64 %uint_5 %uint_11 %65 %315 %textureNormal %uint_8
  4600. %318 = OpExtInst %void %2 DebugGlobalVariable %317 %291 %64 %uint_4 %uint_14 %65 %317 %samplerposition %uint_8
  4601. %320 = OpExtInst %void %2 DebugGlobalVariable %319 %310 %64 %uint_3 %uint_11 %65 %319 %textureposition %uint_8
  4602. %1803 = OpExtInst %void %2 DebugInlinedAt %uint_1792 %180
  4603. %1885 = OpExtInst %void %2 DebugInlinedAt %uint_1869 %158 %1803
  4604. %2085 = OpExtInst %void %2 DebugInlinedAt %uint_2060 %106 %1885
  4605. )"
  4606. R"( %main = OpFunction %void None %321
  4607. %322 = OpLabel
  4608. %2083 = OpVariable %_ptr_Function_float Function
  4609. %2086 = OpVariable %_ptr_Function_v4float Function
  4610. %1883 = OpVariable %_ptr_Function_v2int Function
  4611. %1891 = OpVariable %_ptr_Function_float Function
  4612. %1892 = OpVariable %_ptr_Function_int Function
  4613. %1894 = OpVariable %_ptr_Function_int Function
  4614. %1895 = OpVariable %_ptr_Function_int Function
  4615. %1896 = OpVariable %_ptr_Function_v4float Function
  4616. %1801 = OpVariable %_ptr_Function_int Function
  4617. %1447 = OpVariable %_ptr_Function_v4float Function
  4618. %1448 = OpVariable %_ptr_Function_v3float Function
  4619. %1450 = OpVariable %_ptr_Function_int Function
  4620. %1451 = OpVariable %_ptr_Function_v3float Function
  4621. %1453 = OpVariable %_ptr_Function_v3float Function
  4622. %1466 = OpVariable %_ptr_Function_v3float Function
  4623. %param_var_inUV = OpVariable %_ptr_Function_v2float Function
  4624. %325 = OpExtInst %void %2 DebugFunctionDefinition %176 %main
  4625. %326 = OpLoad %v2float %in_var_TEXCOORD0
  4626. OpStore %param_var_inUV %326
  4627. %2290 = OpExtInst %void %2 DebugScope %176
  4628. %1620 = OpExtInst %void %2 DebugLine %64 %uint_95 %uint_95 %uint_33 %uint_40
  4629. %1470 = OpExtInst %void %2 DebugDeclare %245 %param_var_inUV %243
  4630. %2291 = OpExtInst %void %2 DebugScope %179
  4631. %1621 = OpExtInst %void %2 DebugLine %64 %uint_98 %uint_98 %uint_19 %uint_19
  4632. %1471 = OpLoad %type_2d_image %textureposition
  4633. %1622 = OpExtInst %void %2 DebugLine %64 %uint_98 %uint_98 %uint_42 %uint_42
  4634. %1472 = OpLoad %type_sampler %samplerposition
  4635. %1624 = OpExtInst %void %2 DebugLine %64 %uint_98 %uint_98 %uint_19 %uint_63
  4636. %1474 = OpSampledImage %type_sampled_image %1471 %1472
  4637. %1475 = OpImageSampleImplicitLod %v4float %1474 %326 None
  4638. %1626 = OpExtInst %void %2 DebugLine %64 %uint_98 %uint_98 %uint_19 %uint_65
  4639. %1476 = OpVectorShuffle %v3float %1475 %1475 0 1 2
  4640. %2241 = OpExtInst %void %2 DebugLine %64 %uint_98 %uint_98 %uint_2 %uint_65
  4641. %2240 = OpExtInst %void %2 DebugValue %241 %1476 %243
  4642. %1629 = OpExtInst %void %2 DebugLine %64 %uint_99 %uint_99 %uint_18 %uint_18
  4643. %1478 = OpLoad %type_2d_image %textureNormal
  4644. %1630 = OpExtInst %void %2 DebugLine %64 %uint_99 %uint_99 %uint_39 %uint_39
  4645. %1479 = OpLoad %type_sampler %samplerNormal
  4646. %1632 = OpExtInst %void %2 DebugLine %64 %uint_99 %uint_99 %uint_18 %uint_58
  4647. %1481 = OpSampledImage %type_sampled_image %1478 %1479
  4648. %1482 = OpImageSampleImplicitLod %v4float %1481 %326 None
  4649. %1634 = OpExtInst %void %2 DebugLine %64 %uint_99 %uint_99 %uint_18 %uint_60
  4650. %1483 = OpVectorShuffle %v3float %1482 %1482 0 1 2
  4651. %2244 = OpExtInst %void %2 DebugLine %64 %uint_99 %uint_99 %uint_2 %uint_60
  4652. %2243 = OpExtInst %void %2 DebugValue %239 %1483 %243
  4653. %1637 = OpExtInst %void %2 DebugLine %64 %uint_100 %uint_100 %uint_18 %uint_18
  4654. %1485 = OpLoad %type_2d_image %textureAlbedo
  4655. %1638 = OpExtInst %void %2 DebugLine %64 %uint_100 %uint_100 %uint_39 %uint_39
  4656. %1486 = OpLoad %type_sampler %samplerAlbedo
  4657. %1640 = OpExtInst %void %2 DebugLine %64 %uint_100 %uint_100 %uint_18 %uint_58
  4658. %1488 = OpSampledImage %type_sampled_image %1485 %1486
  4659. %1489 = OpImageSampleImplicitLod %v4float %1488 %326 None
  4660. %1642 = OpExtInst %void %2 DebugLine %64 %uint_100 %uint_100 %uint_2 %uint_58
  4661. OpStore %1447 %1489
  4662. %1490 = OpExtInst %void %2 DebugDeclare %236 %1447 %243
  4663. %1645 = OpExtInst %void %2 DebugLine %64 %uint_103 %uint_103 %uint_22 %uint_29
  4664. %1492 = OpVectorShuffle %v3float %1489 %1489 0 1 2
  4665. %1646 = OpExtInst %void %2 DebugLine %64 %uint_103 %uint_103 %uint_22 %uint_35
  4666. %1493 = OpVectorTimesScalar %v3float %1492 %float_0_100000001
  4667. %1647 = OpExtInst %void %2 DebugLine %64 %uint_103 %uint_103 %uint_2 %uint_35
  4668. OpStore %1448 %1493
  4669. %1494 = OpExtInst %void %2 DebugDeclare %233 %1448 %243
  4670. %1650 = OpExtInst %void %2 DebugLine %64 %uint_105 %uint_105 %uint_13 %uint_29
  4671. %1496 = OpExtInst %v3float %1 Normalize %1483
  4672. %2247 = OpExtInst %void %2 DebugLine %64 %uint_105 %uint_105 %uint_2 %uint_29
  4673. %2246 = OpExtInst %void %2 DebugValue %231 %1496 %243
  4674. %1653 = OpExtInst %void %2 DebugLine %64 %uint_107 %uint_107 %uint_6 %uint_14
  4675. OpStore %1450 %int_0
  4676. %1498 = OpExtInst %void %2 DebugDeclare %228 %1450 %243
  4677. %1655 = OpExtInst %void %2 DebugLine %64 %uint_107 %uint_107 %uint_6 %uint_15
  4678. OpBranch %1499
  4679. %1499 = OpLabel
  4680. %2292 = OpExtInst %void %2 DebugScope %179
  4681. %1656 = OpExtInst %void %2 DebugLine %64 %uint_107 %uint_107 %uint_17 %uint_17
  4682. %1500 = OpLoad %int %1450
  4683. %1657 = OpExtInst %void %2 DebugLine %64 %uint_107 %uint_107 %uint_17 %uint_21
  4684. %1501 = OpSLessThan %bool %1500 %int_3
  4685. %2293 = OpExtInst %void %2 DebugNoScope
  4686. OpLoopMerge %1605 %1602 None
  4687. OpBranchConditional %1501 %1502 %1605
  4688. %1502 = OpLabel
  4689. %2294 = OpExtInst %void %2 DebugScope %182
  4690. %1660 = OpExtInst %void %2 DebugLine %64 %uint_110 %uint_110 %uint_25 %uint_25
  4691. %1503 = OpLoad %int %1450
  4692. %1661 = OpExtInst %void %2 DebugLine %64 %uint_110 %uint_110 %uint_14 %uint_37
  4693. %1504 = OpAccessChain %_ptr_Uniform_UBO %ubo %int_0
  4694. %1505 = OpAccessChain %_ptr_Uniform_v4float %1504 %int_1 %1503 %int_0
  4695. %1663 = OpExtInst %void %2 DebugLine %64 %uint_110 %uint_110 %uint_14 %uint_28
  4696. %1506 = OpLoad %v4float %1505
  4697. %1664 = OpExtInst %void %2 DebugLine %64 %uint_110 %uint_110 %uint_14 %uint_37
  4698. %1507 = OpVectorShuffle %v3float %1506 %1506 0 1 2
  4699. %1666 = OpExtInst %void %2 DebugLine %64 %uint_110 %uint_110 %uint_14 %uint_43
  4700. %1509 = OpFSub %v3float %1507 %1476
  4701. %1667 = OpExtInst %void %2 DebugLine %64 %uint_110 %uint_110 %uint_3 %uint_43
  4702. OpStore %1451 %1509
  4703. %1510 = OpExtInst %void %2 DebugDeclare %226 %1451 %243
  4704. %1670 = OpExtInst %void %2 DebugLine %64 %uint_112 %uint_112 %uint_16 %uint_24
  4705. %1512 = OpExtInst %float %1 Length %1509
  4706. %2250 = OpExtInst %void %2 DebugLine %64 %uint_112 %uint_112 %uint_3 %uint_24
  4707. %2249 = OpExtInst %void %2 DebugValue %223 %1512 %243
  4708. %1674 = OpExtInst %void %2 DebugLine %64 %uint_113 %uint_113 %uint_7 %uint_18
  4709. %1515 = OpExtInst %v3float %1 Normalize %1509
  4710. %1675 = OpExtInst %void %2 DebugLine %64 %uint_113 %uint_113 %uint_3 %uint_18
  4711. OpStore %1451 %1515
  4712. %1676 = OpExtInst %void %2 DebugLine %64 %uint_116 %uint_116 %uint_14 %uint_26
  4713. %1516 = OpAccessChain %_ptr_Uniform_UBO %ubo %int_0
  4714. %1517 = OpAccessChain %_ptr_Uniform_v4float %1516 %int_0
  4715. %1678 = OpExtInst %void %2 DebugLine %64 %uint_116 %uint_116 %uint_14 %uint_18
  4716. %1518 = OpLoad %v4float %1517
  4717. %1679 = OpExtInst %void %2 DebugLine %64 %uint_116 %uint_116 %uint_14 %uint_26
  4718. %1519 = OpVectorShuffle %v3float %1518 %1518 0 1 2
  4719. %1681 = OpExtInst %void %2 DebugLine %64 %uint_116 %uint_116 %uint_14 %uint_32
  4720. %1521 = OpFSub %v3float %1519 %1476
  4721. %1682 = OpExtInst %void %2 DebugLine %64 %uint_116 %uint_116 %uint_3 %uint_32
  4722. OpStore %1453 %1521
  4723. %1522 = OpExtInst %void %2 DebugDeclare %221 %1453 %243
  4724. %1685 = OpExtInst %void %2 DebugLine %64 %uint_117 %uint_117 %uint_7 %uint_18
  4725. %1524 = OpExtInst %v3float %1 Normalize %1521
  4726. %1686 = OpExtInst %void %2 DebugLine %64 %uint_117 %uint_117 %uint_3 %uint_18
  4727. OpStore %1453 %1524
  4728. %1687 = OpExtInst %void %2 DebugLine %64 %uint_119 %uint_119 %uint_34 %uint_46
  4729. %1525 = OpExtInst %float %1 Radians %float_15
  4730. %1688 = OpExtInst %void %2 DebugLine %64 %uint_119 %uint_119 %uint_30 %uint_47
  4731. %1526 = OpExtInst %float %1 Cos %1525
  4732. %2253 = OpExtInst %void %2 DebugLine %64 %uint_119 %uint_119 %uint_3 %uint_47
  4733. %2252 = OpExtInst %void %2 DebugValue %218 %1526 %243
  4734. %1691 = OpExtInst %void %2 DebugLine %64 %uint_120 %uint_120 %uint_34 %uint_46
  4735. %1528 = OpExtInst %float %1 Radians %float_25
  4736. %1692 = OpExtInst %void %2 DebugLine %64 %uint_120 %uint_120 %uint_30 %uint_47
  4737. %1529 = OpExtInst %float %1 Cos %1528
  4738. %2256 = OpExtInst %void %2 DebugLine %64 %uint_120 %uint_120 %uint_3 %uint_47
  4739. %2255 = OpExtInst %void %2 DebugValue %215 %1529 %243
  4740. %2259 = OpExtInst %void %2 DebugLine %64 %uint_121 %uint_121 %uint_3 %uint_22
  4741. %2258 = OpExtInst %void %2 DebugValue %212 %float_100 %243
  4742. %1698 = OpExtInst %void %2 DebugLine %64 %uint_124 %uint_124 %uint_26 %uint_49
  4743. %1533 = OpAccessChain %_ptr_Uniform_UBO %ubo %int_0
  4744. %1534 = OpAccessChain %_ptr_Uniform_v4float %1533 %int_1 %1503 %int_0
  4745. %1700 = OpExtInst %void %2 DebugLine %64 %uint_124 %uint_124 %uint_26 %uint_40
  4746. %1535 = OpLoad %v4float %1534
  4747. %1701 = OpExtInst %void %2 DebugLine %64 %uint_124 %uint_124 %uint_26 %uint_49
  4748. %1536 = OpVectorShuffle %v3float %1535 %1535 0 1 2
  4749. %1703 = OpExtInst %void %2 DebugLine %64 %uint_124 %uint_124 %uint_55 %uint_76
  4750. %1538 = OpAccessChain %_ptr_Uniform_UBO %ubo %int_0
  4751. %1539 = OpAccessChain %_ptr_Uniform_v4float %1538 %int_1 %1503 %int_1
  4752. %1705 = OpExtInst %void %2 DebugLine %64 %uint_124 %uint_124 %uint_55 %uint_69
  4753. %1540 = OpLoad %v4float %1539
  4754. %1706 = OpExtInst %void %2 DebugLine %64 %uint_124 %uint_124 %uint_55 %uint_76
  4755. %1541 = OpVectorShuffle %v3float %1540 %1540 0 1 2
  4756. %1707 = OpExtInst %void %2 DebugLine %64 %uint_124 %uint_124 %uint_26 %uint_76
  4757. %1542 = OpFSub %v3float %1536 %1541
  4758. %1708 = OpExtInst %void %2 DebugLine %64 %uint_124 %uint_124 %uint_16 %uint_79
  4759. %1543 = OpExtInst %v3float %1 Normalize %1542
  4760. %2262 = OpExtInst %void %2 DebugLine %64 %uint_124 %uint_124 %uint_3 %uint_79
  4761. %2261 = OpExtInst %void %2 DebugValue %209 %1543 %243
  4762. %1713 = OpExtInst %void %2 DebugLine %64 %uint_127 %uint_127 %uint_18 %uint_28
  4763. %1547 = OpDot %float %1515 %1543
  4764. %2265 = OpExtInst %void %2 DebugLine %64 %uint_127 %uint_127 %uint_3 %uint_28
  4765. %2264 = OpExtInst %void %2 DebugValue %206 %1547 %243
  4766. %1719 = OpExtInst %void %2 DebugLine %64 %uint_128 %uint_128 %uint_22 %uint_79
  4767. %1552 = OpExtInst %float %1 SmoothStep %1529 %1526 %1547
  4768. %2268 = OpExtInst %void %2 DebugLine %64 %uint_128 %uint_128 %uint_3 %uint_79
  4769. %2267 = OpExtInst %void %2 DebugValue %203 %1552 %243
  4770. %1724 = OpExtInst %void %2 DebugLine %64 %uint_129 %uint_129 %uint_29 %uint_62
  4771. %1556 = OpExtInst %float %1 SmoothStep %float_100 %float_0 %1512
  4772. %2271 = OpExtInst %void %2 DebugLine %64 %uint_129 %uint_129 %uint_3 %uint_62
  4773. %2270 = OpExtInst %void %2 DebugValue %200 %1556 %243
  4774. %1729 = OpExtInst %void %2 DebugLine %64 %uint_132 %uint_132 %uint_26 %uint_34
  4775. %1560 = OpDot %float %1496 %1515
  4776. %1730 = OpExtInst %void %2 DebugLine %64 %uint_132 %uint_132 %uint_17 %uint_35
  4777. %1561 = OpExtInst %float %1 FMax %float_0 %1560
  4778. %2274 = OpExtInst %void %2 DebugLine %64 %uint_132 %uint_132 %uint_3 %uint_35
  4779. %2273 = OpExtInst %void %2 DebugValue %197 %1561 %243
  4780. %1734 = OpExtInst %void %2 DebugLine %64 %uint_133 %uint_133 %uint_17 %uint_23
  4781. %1564 = OpCompositeConstruct %v3float %1561 %1561 %1561
  4782. %2277 = OpExtInst %void %2 DebugLine %64 %uint_133 %uint_133 %uint_3 %uint_23
  4783. %2276 = OpExtInst %void %2 DebugValue %194 %1564 %243
  4784. %1738 = OpExtInst %void %2 DebugLine %64 %uint_136 %uint_136 %uint_22 %uint_23
  4785. %1567 = OpFNegate %v3float %1515
  4786. %1740 = OpExtInst %void %2 DebugLine %64 %uint_136 %uint_136 %uint_14 %uint_27
  4787. %1569 = OpExtInst %v3float %1 Reflect %1567 %1496
  4788. %2280 = OpExtInst %void %2 DebugLine %64 %uint_136 %uint_136 %uint_3 %uint_27
  4789. %2279 = OpExtInst %void %2 DebugValue %191 %1569 %243
  4790. %1745 = OpExtInst %void %2 DebugLine %64 %uint_137 %uint_137 %uint_26 %uint_34
  4791. %1573 = OpDot %float %1569 %1524
  4792. %1746 = OpExtInst %void %2 DebugLine %64 %uint_137 %uint_137 %uint_17 %uint_35
  4793. %1574 = OpExtInst %float %1 FMax %float_0 %1573
  4794. %2283 = OpExtInst %void %2 DebugLine %64 %uint_137 %uint_137 %uint_3 %uint_35
  4795. %2282 = OpExtInst %void %2 DebugValue %188 %1574 %243
  4796. %1750 = OpExtInst %void %2 DebugLine %64 %uint_138 %uint_138 %uint_18 %uint_33
  4797. %1577 = OpExtInst %float %1 Pow %1574 %float_16
  4798. %1751 = OpExtInst %void %2 DebugLine %64 %uint_138 %uint_138 %uint_37 %uint_44
  4799. %1578 = OpAccessChain %_ptr_Function_float %1447 %int_3
  4800. %1579 = OpLoad %float %1578
  4801. %1753 = OpExtInst %void %2 DebugLine %64 %uint_138 %uint_138 %uint_18 %uint_44
  4802. %1580 = OpFMul %float %1577 %1579
  4803. %1754 = OpExtInst %void %2 DebugLine %64 %uint_138 %uint_138 %uint_18 %uint_48
  4804. %1581 = OpFMul %float %1580 %float_2_5
  4805. %1755 = OpExtInst %void %2 DebugLine %64 %uint_138 %uint_138 %uint_17 %uint_53
  4806. %1582 = OpCompositeConstruct %v3float %1581 %1581 %1581
  4807. %2286 = OpExtInst %void %2 DebugLine %64 %uint_138 %uint_138 %uint_3 %uint_53
  4808. %2285 = OpExtInst %void %2 DebugValue %185 %1582 %243
  4809. %1760 = OpExtInst %void %2 DebugLine %64 %uint_140 %uint_140 %uint_24 %uint_31
  4810. %1586 = OpFAdd %v3float %1564 %1582
  4811. %1762 = OpExtInst %void %2 DebugLine %64 %uint_140 %uint_140 %uint_23 %uint_39
  4812. %1588 = OpVectorTimesScalar %v3float %1586 %1552
  4813. %1764 = OpExtInst %void %2 DebugLine %64 %uint_140 %uint_140 %uint_23 %uint_52
  4814. %1590 = OpVectorTimesScalar %v3float %1588 %1556
  4815. %1766 = OpExtInst %void %2 DebugLine %64 %uint_140 %uint_140 %uint_73 %uint_93
  4816. %1592 = OpAccessChain %_ptr_Uniform_UBO %ubo %int_0
  4817. %1593 = OpAccessChain %_ptr_Uniform_v4float %1592 %int_1 %1503 %int_2
  4818. %1768 = OpExtInst %void %2 DebugLine %64 %uint_140 %uint_140 %uint_73 %uint_87
  4819. %1594 = OpLoad %v4float %1593
  4820. %1769 = OpExtInst %void %2 DebugLine %64 %uint_140 %uint_140 %uint_73 %uint_93
  4821. %1595 = OpVectorShuffle %v3float %1594 %1594 0 1 2
  4822. %1770 = OpExtInst %void %2 DebugLine %64 %uint_140 %uint_140 %uint_16 %uint_93
  4823. %1596 = OpFMul %v3float %1590 %1595
  4824. %1772 = OpExtInst %void %2 DebugLine %64 %uint_140 %uint_140 %uint_99 %uint_106
  4825. %1598 = OpVectorShuffle %v3float %1489 %1489 0 1 2
  4826. %1773 = OpExtInst %void %2 DebugLine %64 %uint_140 %uint_140 %uint_16 %uint_106
  4827. %1599 = OpFMul %v3float %1596 %1598
  4828. %1774 = OpExtInst %void %2 DebugLine %64 %uint_140 %uint_140 %uint_3 %uint_3
  4829. %1600 = OpLoad %v3float %1448
  4830. %1775 = OpExtInst %void %2 DebugLine %64 %uint_140 %uint_140 %uint_3 %uint_106
  4831. %1601 = OpFAdd %v3float %1600 %1599
  4832. OpStore %1448 %1601
  4833. %2295 = OpExtInst %void %2 DebugScope %179
  4834. %1777 = OpExtInst %void %2 DebugLine %64 %uint_107 %uint_107 %uint_34 %uint_36
  4835. OpBranch %1602
  4836. %1602 = OpLabel
  4837. %2296 = OpExtInst %void %2 DebugScope %179
  4838. %1778 = OpExtInst %void %2 DebugLine %64 %uint_107 %uint_107 %uint_34 %uint_36
  4839. %1603 = OpLoad %int %1450
  4840. %1604 = OpIAdd %int %1603 %int_1
  4841. OpStore %1450 %1604
  4842. OpBranch %1499
  4843. %1605 = OpLabel
  4844. %2297 = OpExtInst %void %2 DebugScope %179
  4845. %1782 = OpExtInst %void %2 DebugLine %64 %uint_144 %uint_144 %uint_6 %uint_10
  4846. %1606 = OpAccessChain %_ptr_Uniform_UBO %ubo %int_0
  4847. %1607 = OpAccessChain %_ptr_Uniform_int %1606 %int_2
  4848. %1608 = OpLoad %int %1607
  4849. %1785 = OpExtInst %void %2 DebugLine %64 %uint_144 %uint_144 %uint_6 %uint_23
  4850. %1609 = OpSGreaterThan %bool %1608 %int_0
  4851. %2298 = OpExtInst %void %2 DebugNoScope
  4852. OpSelectionMerge %1614 None
  4853. OpBranchConditional %1609 %1610 %1614
  4854. )"
  4855. R"( %1610 = OpLabel
  4856. %2299 = OpExtInst %void %2 DebugScope %180
  4857. %1788 = OpExtInst %void %2 DebugLine %64 %uint_146 %uint_146 %uint_22 %uint_22
  4858. %1611 = OpLoad %v3float %1448
  4859. OpStore %1466 %1611
  4860. %2300 = OpExtInst %void %2 DebugScope %155 %1803
  4861. %1842 = OpExtInst %void %2 DebugLine %64 %uint_78 %uint_78 %uint_15 %uint_22
  4862. %1810 = OpExtInst %void %2 DebugDeclare %172 %1466 %243
  4863. %2301 = OpExtInst %void %2 DebugScope %180
  4864. %2289 = OpExtInst %void %2 DebugLine %64 %uint_146 %uint_146 %uint_33 %uint_33
  4865. %2288 = OpExtInst %void %2 DebugValue %170 %1476 %243
  4866. %2302 = OpExtInst %void %2 DebugScope %157 %1803
  4867. %1844 = OpExtInst %void %2 DebugLine %64 %uint_79 %uint_79 %uint_7 %uint_15
  4868. OpStore %1801 %int_0
  4869. %1813 = OpExtInst %void %2 DebugDeclare %167 %1801 %243
  4870. %1846 = OpExtInst %void %2 DebugLine %64 %uint_79 %uint_79 %uint_7 %uint_16
  4871. OpBranch %1814
  4872. %1814 = OpLabel
  4873. %2303 = OpExtInst %void %2 DebugScope %157 %1803
  4874. %1847 = OpExtInst %void %2 DebugLine %64 %uint_79 %uint_79 %uint_18 %uint_18
  4875. %1815 = OpLoad %int %1801
  4876. %1848 = OpExtInst %void %2 DebugLine %64 %uint_79 %uint_79 %uint_18 %uint_22
  4877. %1816 = OpSLessThan %bool %1815 %int_3
  4878. %2304 = OpExtInst %void %2 DebugNoScope
  4879. OpLoopMerge %1840 %1837 None
  4880. OpBranchConditional %1816 %1817 %1840
  4881. %1817 = OpLabel
  4882. %2305 = OpExtInst %void %2 DebugScope %158 %1803
  4883. %1851 = OpExtInst %void %2 DebugLine %64 %uint_81 %uint_81 %uint_38 %uint_38
  4884. %1818 = OpLoad %int %1801
  4885. %1852 = OpExtInst %void %2 DebugLine %64 %uint_81 %uint_81 %uint_27 %uint_41
  4886. %1819 = OpAccessChain %_ptr_Uniform_UBO %ubo %int_0
  4887. %1820 = OpAccessChain %_ptr_Uniform_mat4v4float %1819 %int_1 %1818 %int_3
  4888. %1821 = OpLoad %mat4v4float %1820
  4889. %1856 = OpExtInst %void %2 DebugLine %64 %uint_81 %uint_81 %uint_60 %uint_68
  4890. %1823 = OpCompositeExtract %float %1476 0
  4891. %1824 = OpCompositeExtract %float %1476 1
  4892. %1825 = OpCompositeExtract %float %1476 2
  4893. %1859 = OpExtInst %void %2 DebugLine %64 %uint_81 %uint_81 %uint_53 %uint_76
  4894. %1826 = OpCompositeConstruct %v4float %1823 %1824 %1825 %float_1
  4895. %1860 = OpExtInst %void %2 DebugLine %64 %uint_81 %uint_81 %uint_23 %uint_77
  4896. %1827 = OpVectorTimesMatrix %v4float %1826 %1821
  4897. %2229 = OpExtInst %void %2 DebugLine %64 %uint_81 %uint_81 %uint_3 %uint_77
  4898. %2228 = OpExtInst %void %2 DebugValue %163 %1827 %243
  4899. %1867 = OpExtInst %void %2 DebugLine %64 %uint_85 %uint_85 %uint_40 %uint_40
  4900. %1832 = OpConvertSToF %float %1818
  4901. %2235 = OpExtInst %void %2 DebugLine %64 %uint_85 %uint_85 %uint_28 %uint_28
  4902. %2234 = OpExtInst %void %2 DebugValue %151 %1827 %243
  4903. %2238 = OpExtInst %void %2 DebugLine %64 %uint_85 %uint_85 %uint_40 %uint_40
  4904. %2237 = OpExtInst %void %2 DebugValue %148 %1832 %243
  4905. %2306 = OpExtInst %void %2 DebugScope %103 %1885
  4906. %1983 = OpExtInst %void %2 DebugLine %64 %uint_56 %uint_56 %uint_2 %uint_7
  4907. %1904 = OpExtInst %void %2 DebugDeclare %146 %1883 %243
  4908. %1986 = OpExtInst %void %2 DebugLine %64 %uint_57 %uint_57 %uint_2 %uint_2
  4909. %1907 = OpLoad %type_2d_image_array %textureShadowMap
  4910. )"
  4911. R"( %1987 = OpExtInst %void %2 DebugLine %64 %uint_57 %uint_57 %uint_2 %uint_72
  4912. %1908 = OpImageQuerySizeLod %v3uint %1907 %uint_0
  4913. %1909 = OpCompositeExtract %uint %1908 0
  4914. %1910 = OpBitcast %int %1909
  4915. %1911 = OpAccessChain %_ptr_Function_int %1883 %int_0
  4916. OpStore %1911 %1910
  4917. %1912 = OpCompositeExtract %uint %1908 1
  4918. %1913 = OpBitcast %int %1912
  4919. %1914 = OpAccessChain %_ptr_Function_int %1883 %int_1
  4920. OpStore %1914 %1913
  4921. %1915 = OpCompositeExtract %uint %1908 2
  4922. %1916 = OpBitcast %int %1915
  4923. %2204 = OpExtInst %void %2 DebugValue %142 %1916 %243
  4924. %1999 = OpExtInst %void %2 DebugLine %64 %uint_57 %uint_57 %uint_19 %uint_19
  4925. %1917 = OpImageQueryLevels %uint %1907
  4926. %2000 = OpExtInst %void %2 DebugLine %64 %uint_57 %uint_57 %uint_2 %uint_72
  4927. %1918 = OpBitcast %int %1917
  4928. %2207 = OpExtInst %void %2 DebugValue %138 %1918 %243
  4929. %2211 = OpExtInst %void %2 DebugLine %64 %uint_58 %uint_58 %uint_2 %uint_16
  4930. %2210 = OpExtInst %void %2 DebugValue %135 %float_1_5 %243
  4931. %2005 = OpExtInst %void %2 DebugLine %64 %uint_59 %uint_59 %uint_13 %uint_21
  4932. %1921 = OpFMul %float %float_1_5 %float_1
  4933. %2006 = OpExtInst %void %2 DebugLine %64 %uint_59 %uint_59 %uint_33 %uint_40
  4934. %1922 = OpAccessChain %_ptr_Function_int %1883 %int_0
  4935. %1923 = OpLoad %int %1922
  4936. %1924 = OpConvertSToF %float %1923
  4937. %2009 = OpExtInst %void %2 DebugLine %64 %uint_59 %uint_59 %uint_13 %uint_41
  4938. %1925 = OpFDiv %float %1921 %1924
  4939. %2214 = OpExtInst %void %2 DebugLine %64 %uint_59 %uint_59 %uint_2 %uint_41
  4940. %2213 = OpExtInst %void %2 DebugValue %132 %1925 %243
  4941. %2013 = OpExtInst %void %2 DebugLine %64 %uint_60 %uint_60 %uint_13 %uint_21
  4942. %1928 = OpFMul %float %float_1_5 %float_1
  4943. %2014 = OpExtInst %void %2 DebugLine %64 %uint_60 %uint_60 %uint_33 %uint_40
  4944. %1929 = OpAccessChain %_ptr_Function_int %1883 %int_1
  4945. %1930 = OpLoad %int %1929
  4946. %1931 = OpConvertSToF %float %1930
  4947. %2017 = OpExtInst %void %2 DebugLine %64 %uint_60 %uint_60 %uint_13 %uint_41
  4948. %1932 = OpFDiv %float %1928 %1931
  4949. %2217 = OpExtInst %void %2 DebugLine %64 %uint_60 %uint_60 %uint_2 %uint_41
  4950. %2216 = OpExtInst %void %2 DebugValue %129 %1932 %243
  4951. %2020 = OpExtInst %void %2 DebugLine %64 %uint_62 %uint_62 %uint_2 %uint_23
  4952. OpStore %1891 %float_0
  4953. %1934 = OpExtInst %void %2 DebugDeclare %126 %1891 %243
  4954. %2022 = OpExtInst %void %2 DebugLine %64 %uint_63 %uint_63 %uint_2 %uint_14
  4955. OpStore %1892 %int_0
  4956. %1935 = OpExtInst %void %2 DebugDeclare %123 %1892 %243
  4957. %2220 = OpExtInst %void %2 DebugLine %64 %uint_64 %uint_64 %uint_2 %uint_14
  4958. %2219 = OpExtInst %void %2 DebugValue %119 %int_1 %243
  4959. %2027 = OpExtInst %void %2 DebugLine %64 %uint_66 %uint_66 %uint_15 %uint_16
  4960. %1938 = OpSNegate %int %int_1
  4961. %2028 = OpExtInst %void %2 DebugLine %64 %uint_66 %uint_66 %uint_7 %uint_16
  4962. OpStore %1894 %1938
  4963. %1939 = OpExtInst %void %2 DebugDeclare %115 %1894 %243
  4964. %2030 = OpExtInst %void %2 DebugLine %64 %uint_66 %uint_66 %uint_7 %uint_21
  4965. OpBranch %1940
  4966. %1940 = OpLabel
  4967. %2307 = OpExtInst %void %2 DebugScope %103 %1885
  4968. %2031 = OpExtInst %void %2 DebugLine %64 %uint_66 %uint_66 %uint_23 %uint_23
  4969. %1941 = OpLoad %int %1894
  4970. %2033 = OpExtInst %void %2 DebugLine %64 %uint_66 %uint_66 %uint_23 %uint_28
  4971. %1943 = OpSLessThanEqual %bool %1941 %int_1
  4972. %2308 = OpExtInst %void %2 DebugNoScope
  4973. OpLoopMerge %1976 %1973 None
  4974. OpBranchConditional %1943 %1944 %1976
  4975. %1944 = OpLabel
  4976. %2309 = OpExtInst %void %2 DebugScope %104 %1885
  4977. %2037 = OpExtInst %void %2 DebugLine %64 %uint_68 %uint_68 %uint_16 %uint_17
  4978. %1946 = OpSNegate %int %int_1
  4979. %2038 = OpExtInst %void %2 DebugLine %64 %uint_68 %uint_68 %uint_8 %uint_17
  4980. OpStore %1895 %1946
  4981. %1947 = OpExtInst %void %2 DebugDeclare %111 %1895 %243
  4982. %2040 = OpExtInst %void %2 DebugLine %64 %uint_68 %uint_68 %uint_8 %uint_22
  4983. OpBranch %1948
  4984. %1948 = OpLabel
  4985. %2310 = OpExtInst %void %2 DebugScope %104 %1885
  4986. %2041 = OpExtInst %void %2 DebugLine %64 %uint_68 %uint_68 %uint_24 %uint_24
  4987. %1949 = OpLoad %int %1895
  4988. %2043 = OpExtInst %void %2 DebugLine %64 %uint_68 %uint_68 %uint_24 %uint_29
  4989. %1951 = OpSLessThanEqual %bool %1949 %int_1
  4990. %2311 = OpExtInst %void %2 DebugNoScope
  4991. OpLoopMerge %1972 %1969 None
  4992. OpBranchConditional %1951 %1952 %1972
  4993. %1952 = OpLabel
  4994. %2312 = OpExtInst %void %2 DebugScope %106 %1885
  4995. %2047 = OpExtInst %void %2 DebugLine %64 %uint_70 %uint_70 %uint_32 %uint_32
  4996. OpStore %1896 %1827
  4997. %2051 = OpExtInst %void %2 DebugLine %64 %uint_70 %uint_70 %uint_53 %uint_53
  4998. %1956 = OpLoad %int %1894
  4999. %1957 = OpConvertSToF %float %1956
  5000. %2053 = OpExtInst %void %2 DebugLine %64 %uint_70 %uint_70 %uint_50 %uint_53
  5001. %1958 = OpFMul %float %1925 %1957
  5002. %2055 = OpExtInst %void %2 DebugLine %64 %uint_70 %uint_70 %uint_59 %uint_59
  5003. %1960 = OpLoad %int %1895
  5004. %1961 = OpConvertSToF %float %1960
  5005. %2057 = OpExtInst %void %2 DebugLine %64 %uint_70 %uint_70 %uint_56 %uint_59
  5006. %1962 = OpFMul %float %1932 %1961
  5007. %2058 = OpExtInst %void %2 DebugLine %64 %uint_70 %uint_70 %uint_43 %uint_60
  5008. %1963 = OpCompositeConstruct %v2float %1958 %1962
  5009. %2313 = OpExtInst %void %2 DebugScope %70 %2085
  5010. %2141 = OpExtInst %void %2 DebugLine %64 %uint_37 %uint_37 %uint_19 %uint_26
  5011. %2090 = OpExtInst %void %2 DebugDeclare %96 %1896 %243
  5012. %2314 = OpExtInst %void %2 DebugScope %106 %1885
  5013. %2223 = OpExtInst %void %2 DebugLine %64 %uint_70 %uint_70 %uint_36 %uint_36
  5014. %2222 = OpExtInst %void %2 DebugValue %93 %1832 %243
  5015. %2226 = OpExtInst %void %2 DebugLine %64 %uint_70 %uint_70 %uint_43 %uint_60
  5016. %2225 = OpExtInst %void %2 DebugValue %90 %1963 %243
  5017. %2315 = OpExtInst %void %2 DebugScope %73 %2085
  5018. %2144 = OpExtInst %void %2 DebugLine %64 %uint_39 %uint_39 %uint_2 %uint_17
  5019. OpStore %2083 %float_1
  5020. %2094 = OpExtInst %void %2 DebugDeclare %86 %2083 %243
  5021. %2147 = OpExtInst %void %2 DebugLine %64 %uint_40 %uint_40 %uint_27 %uint_29
  5022. %2096 = OpAccessChain %_ptr_Function_float %1896 %int_3
  5023. %2097 = OpLoad %float %2096
  5024. %2098 = OpCompositeConstruct %v4float %2097 %2097 %2097 %2097
  5025. %2150 = OpExtInst %void %2 DebugLine %64 %uint_40 %uint_40 %uint_23 %uint_29
  5026. %2099 = OpFDiv %v4float %1827 %2098
  5027. %2151 = OpExtInst %void %2 DebugLine %64 %uint_40 %uint_40 %uint_2 %uint_29
  5028. OpStore %2086 %2099
  5029. %2100 = OpExtInst %void %2 DebugDeclare %83 %2086 %243
  5030. %2154 = OpExtInst %void %2 DebugLine %64 %uint_41 %uint_41 %uint_19 %uint_31
  5031. %2102 = OpVectorShuffle %v2float %2099 %2099 0 1
  5032. %2155 = OpExtInst %void %2 DebugLine %64 %uint_41 %uint_41 %uint_19 %uint_36
  5033. %2103 = OpVectorTimesScalar %v2float %2102 %float_0_5
  5034. %2156 = OpExtInst %void %2 DebugLine %64 %uint_41 %uint_41 %uint_19 %uint_42
  5035. %2104 = OpFAdd %v2float %2103 %35
  5036. %2158 = OpExtInst %void %2 DebugLine %64 %uint_41 %uint_41 %uint_2 %uint_42
  5037. %2106 = OpVectorShuffle %v4float %2099 %2104 4 5 2 3
  5038. OpStore %2086 %2106
  5039. %2160 = OpExtInst %void %2 DebugLine %64 %uint_43 %uint_43 %uint_6 %uint_18
  5040. %2107 = OpAccessChain %_ptr_Function_float %2086 %int_2
  5041. %2108 = OpLoad %float %2107
  5042. %2162 = OpExtInst %void %2 DebugLine %64 %uint_43 %uint_43 %uint_6 %uint_23
  5043. %2109 = OpFOrdGreaterThan %bool %2108 %float_n1
  5044. %2163 = OpExtInst %void %2 DebugLine %64 %uint_43 %uint_43 %uint_30 %uint_42
  5045. %2110 = OpAccessChain %_ptr_Function_float %2086 %int_2
  5046. %2111 = OpLoad %float %2110
  5047. %2165 = OpExtInst %void %2 DebugLine %64 %uint_43 %uint_43 %uint_30 %uint_46
  5048. %2112 = OpFOrdLessThan %bool %2111 %float_1
  5049. %2166 = OpExtInst %void %2 DebugLine %64 %uint_43 %uint_43 %uint_6 %uint_46
  5050. %2113 = OpLogicalAnd %bool %2109 %2112
  5051. %2316 = OpExtInst %void %2 DebugNoScope
  5052. OpSelectionMerge %2139 None
  5053. OpBranchConditional %2113 %2114 %2139
  5054. %2114 = OpLabel
  5055. %2317 = OpExtInst %void %2 DebugScope %74 %2085
  5056. %2169 = OpExtInst %void %2 DebugLine %64 %uint_45 %uint_45 %uint_16 %uint_16
  5057. %2115 = OpLoad %type_2d_image_array %textureShadowMap
  5058. %2170 = OpExtInst %void %2 DebugLine %64 %uint_45 %uint_45 %uint_40 %uint_40
  5059. %2116 = OpLoad %type_sampler %samplerShadowMap
  5060. %2171 = OpExtInst %void %2 DebugLine %64 %uint_45 %uint_45 %uint_65 %uint_65
  5061. %2117 = OpLoad %v4float %2086
  5062. %2172 = OpExtInst %void %2 DebugLine %64 %uint_45 %uint_45 %uint_65 %uint_77
  5063. %2118 = OpVectorShuffle %v2float %2117 %2117 0 1
  5064. %2174 = OpExtInst %void %2 DebugLine %64 %uint_45 %uint_45 %uint_65 %uint_82
  5065. %2120 = OpFAdd %v2float %2118 %1963
  5066. %2122 = OpCompositeExtract %float %2120 0
  5067. %2123 = OpCompositeExtract %float %2120 1
  5068. %2178 = OpExtInst %void %2 DebugLine %64 %uint_45 %uint_45 %uint_58 %uint_95
  5069. %2124 = OpCompositeConstruct %v3float %2122 %2123 %1832
  5070. %2179 = OpExtInst %void %2 DebugLine %64 %uint_45 %uint_45 %uint_16 %uint_96
  5071. %2125 = OpSampledImage %type_sampled_image_0 %2115 %2116
  5072. %2126 = OpImageSampleImplicitLod %v4float %2125 %2124 None
  5073. %2181 = OpExtInst %void %2 DebugLine %64 %uint_45 %uint_45 %uint_16 %uint_98
  5074. %2127 = OpCompositeExtract %float %2126 0
  5075. %2202 = OpExtInst %void %2 DebugLine %64 %uint_45 %uint_45 %uint_3 %uint_98
  5076. %2201 = OpExtInst %void %2 DebugValue %79 %2127 %243
  5077. %2184 = OpExtInst %void %2 DebugLine %64 %uint_46 %uint_46 %uint_7 %uint_19
  5078. %2129 = OpAccessChain %_ptr_Function_float %2086 %int_3
  5079. %2130 = OpLoad %float %2129
  5080. %2186 = OpExtInst %void %2 DebugLine %64 %uint_46 %uint_46 %uint_7 %uint_23
  5081. %2131 = OpFOrdGreaterThan %bool %2130 %float_0
  5082. %2188 = OpExtInst %void %2 DebugLine %64 %uint_46 %uint_46 %uint_37 %uint_49
  5083. %2133 = OpAccessChain %_ptr_Function_float %2086 %int_2
  5084. %2134 = OpLoad %float %2133
  5085. %2190 = OpExtInst %void %2 DebugLine %64 %uint_46 %uint_46 %uint_30 %uint_49
  5086. %2135 = OpFOrdLessThan %bool %2127 %2134
  5087. %2191 = OpExtInst %void %2 DebugLine %64 %uint_46 %uint_46 %uint_7 %uint_49
  5088. %2136 = OpLogicalAnd %bool %2131 %2135
  5089. %2318 = OpExtInst %void %2 DebugNoScope
  5090. OpSelectionMerge %2138 None
  5091. OpBranchConditional %2136 %2137 %2138
  5092. %2137 = OpLabel
  5093. %2319 = OpExtInst %void %2 DebugScope %76 %2085
  5094. %2194 = OpExtInst %void %2 DebugLine %64 %uint_48 %uint_48 %uint_4 %uint_13
  5095. OpStore %2083 %float_0_25
  5096. %2320 = OpExtInst %void %2 DebugScope %74 %2085
  5097. %2195 = OpExtInst %void %2 DebugLine %64 %uint_49 %uint_49 %uint_3 %uint_3
  5098. OpBranch %2138
  5099. %2138 = OpLabel
  5100. %2321 = OpExtInst %void %2 DebugScope %73 %2085
  5101. %2196 = OpExtInst %void %2 DebugLine %64 %uint_50 %uint_50 %uint_2 %uint_2
  5102. OpBranch %2139
  5103. %2139 = OpLabel
  5104. %2322 = OpExtInst %void %2 DebugScope %73 %2085
  5105. %2197 = OpExtInst %void %2 DebugLine %64 %uint_51 %uint_51 %uint_9 %uint_9
  5106. %2140 = OpLoad %float %2083
  5107. %2323 = OpExtInst %void %2 DebugScope %106 %1885
  5108. %2061 = OpExtInst %void %2 DebugLine %64 %uint_70 %uint_70 %uint_4 %uint_4
  5109. %1965 = OpLoad %float %1891
  5110. %2062 = OpExtInst %void %2 DebugLine %64 %uint_70 %uint_70 %uint_4 %uint_61
  5111. %1966 = OpFAdd %float %1965 %2140
  5112. OpStore %1891 %1966
  5113. %2064 = OpExtInst %void %2 DebugLine %64 %uint_71 %uint_71 %uint_4 %uint_9
  5114. %1967 = OpLoad %int %1892
  5115. %1968 = OpIAdd %int %1967 %int_1
  5116. OpStore %1892 %1968
  5117. %2324 = OpExtInst %void %2 DebugScope %104 %1885
  5118. %2067 = OpExtInst %void %2 DebugLine %64 %uint_68 %uint_68 %uint_36 %uint_37
  5119. OpBranch %1969
  5120. %1969 = OpLabel
  5121. %2325 = OpExtInst %void %2 DebugScope %104 %1885
  5122. %2068 = OpExtInst %void %2 DebugLine %64 %uint_68 %uint_68 %uint_36 %uint_37
  5123. %1970 = OpLoad %int %1895
  5124. %1971 = OpIAdd %int %1970 %int_1
  5125. OpStore %1895 %1971
  5126. OpBranch %1948
  5127. %1972 = OpLabel
  5128. %2326 = OpExtInst %void %2 DebugScope %103 %1885
  5129. %2072 = OpExtInst %void %2 DebugLine %64 %uint_66 %uint_66 %uint_35 %uint_36
  5130. OpBranch %1973
  5131. %1973 = OpLabel
  5132. %2327 = OpExtInst %void %2 DebugScope %103 %1885
  5133. %2073 = OpExtInst %void %2 DebugLine %64 %uint_66 %uint_66 %uint_35 %uint_36
  5134. %1974 = OpLoad %int %1894
  5135. %1975 = OpIAdd %int %1974 %int_1
  5136. OpStore %1894 %1975
  5137. OpBranch %1940
  5138. %1976 = OpLabel
  5139. %2328 = OpExtInst %void %2 DebugScope %103 %1885
  5140. %2077 = OpExtInst %void %2 DebugLine %64 %uint_75 %uint_75 %uint_9 %uint_9
  5141. %1977 = OpLoad %float %1891
  5142. %2078 = OpExtInst %void %2 DebugLine %64 %uint_75 %uint_75 %uint_24 %uint_24
  5143. %1978 = OpLoad %int %1892
  5144. %1979 = OpConvertSToF %float %1978
  5145. %2080 = OpExtInst %void %2 DebugLine %64 %uint_75 %uint_75 %uint_9 %uint_24
  5146. %1980 = OpFDiv %float %1977 %1979
  5147. %2329 = OpExtInst %void %2 DebugScope %158 %1803
  5148. %2232 = OpExtInst %void %2 DebugLine %64 %uint_85 %uint_85 %uint_4 %uint_41
  5149. %2231 = OpExtInst %void %2 DebugValue %160 %1980 %243
  5150. %1872 = OpExtInst %void %2 DebugLine %64 %uint_90 %uint_90 %uint_3 %uint_3
  5151. %1835 = OpLoad %v3float %1466
  5152. %1873 = OpExtInst %void %2 DebugLine %64 %uint_90 %uint_90 %uint_3 %uint_16
  5153. %1836 = OpVectorTimesScalar %v3float %1835 %1980
  5154. OpStore %1466 %1836
  5155. %2330 = OpExtInst %void %2 DebugScope %157 %1803
  5156. %1875 = OpExtInst %void %2 DebugLine %64 %uint_79 %uint_79 %uint_35 %uint_37
  5157. OpBranch %1837
  5158. %1837 = OpLabel
  5159. %2331 = OpExtInst %void %2 DebugScope %157 %1803
  5160. %1876 = OpExtInst %void %2 DebugLine %64 %uint_79 %uint_79 %uint_35 %uint_37
  5161. %1838 = OpLoad %int %1801
  5162. %1839 = OpIAdd %int %1838 %int_1
  5163. OpStore %1801 %1839
  5164. OpBranch %1814
  5165. %1840 = OpLabel
  5166. %2332 = OpExtInst %void %2 DebugScope %157 %1803
  5167. %1880 = OpExtInst %void %2 DebugLine %64 %uint_92 %uint_92 %uint_9 %uint_9
  5168. %1841 = OpLoad %v3float %1466
  5169. %2333 = OpExtInst %void %2 DebugScope %180
  5170. %1793 = OpExtInst %void %2 DebugLine %64 %uint_146 %uint_146 %uint_3 %uint_40
  5171. OpStore %1448 %1841
  5172. %2334 = OpExtInst %void %2 DebugScope %179
  5173. %1794 = OpExtInst %void %2 DebugLine %64 %uint_147 %uint_147 %uint_2 %uint_2
  5174. OpBranch %1614
  5175. %1614 = OpLabel
  5176. ;CHECK: %1614 = OpLabel
  5177. ;CHECK-NEXT: [[phi:%\w+]] = OpPhi
  5178. ;CHECK-NEXT: {{%\w+}} = OpExtInst %void {{%\w+}} DebugValue %233
  5179. %2335 = OpExtInst %void %2 DebugScope %179
  5180. %1795 = OpExtInst %void %2 DebugLine %64 %uint_149 %uint_149 %uint_16 %uint_16
  5181. %1615 = OpLoad %v3float %1448
  5182. %1616 = OpCompositeExtract %float %1615 0
  5183. %1617 = OpCompositeExtract %float %1615 1
  5184. %1618 = OpCompositeExtract %float %1615 2
  5185. %1799 = OpExtInst %void %2 DebugLine %64 %uint_149 %uint_149 %uint_9 %uint_28
  5186. %1619 = OpCompositeConstruct %v4float %1616 %1617 %1618 %float_1
  5187. %2336 = OpExtInst %void %2 DebugNoLine
  5188. %2337 = OpExtInst %void %2 DebugNoScope
  5189. OpStore %out_var_SV_TARGET %1619
  5190. %329 = OpExtInst %void %2 DebugLine %64 %uint_150 %uint_150 %uint_1 %uint_1
  5191. OpReturn
  5192. OpFunctionEnd
  5193. )";
  5194. SetTargetEnv(SPV_ENV_VULKAN_1_2);
  5195. SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
  5196. SinglePassRunAndMatch<SSARewritePass>(text, true);
  5197. }
  5198. // TODO(greg-lunarg): Add tests to verify handling of these cases:
  5199. //
  5200. // No optimization in the presence of
  5201. // access chains
  5202. // function calls
  5203. // OpCopyMemory?
  5204. // unsupported extensions
  5205. // Others?
  5206. } // namespace
  5207. } // namespace opt
  5208. } // namespace spvtools