| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489 |
- // Copyright (c) 2018 Google LLC.
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- #include "source/opt/loop_fission.h"
- #include <memory>
- #include <vector>
- #include "gmock/gmock.h"
- #include "source/opt/loop_utils.h"
- #include "test/opt/assembly_builder.h"
- #include "test/opt/function_utils.h"
- #include "test/opt/pass_fixture.h"
- #include "test/opt/pass_utils.h"
- namespace spvtools {
- namespace opt {
- namespace {
- using ::testing::UnorderedElementsAre;
- using FissionClassTest = PassTest<::testing::Test>;
- /*
- Generated from the following GLSL
- #version 430
- void main(void) {
- float A[10];
- float B[10];
- for (int i = 0; i < 10; i++) {
- A[i] = B[i];
- B[i] = A[i];
- }
- }
- Result should be equivalent to:
- void main(void) {
- float A[10];
- float B[10];
- for (int i = 0; i < 10; i++) {
- A[i] = B[i];
- }
- for (int i = 0; i < 10; i++) {
- B[i] = A[i];
- }
- }
- */
- TEST_F(FissionClassTest, SimpleFission) {
- // clang-format off
- // With LocalMultiStoreElimPass
- const std::string source = R"(OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %2 "main"
- OpExecutionMode %2 OriginUpperLeft
- OpSource GLSL 430
- OpName %2 "main"
- OpName %3 "i"
- OpName %4 "A"
- OpName %5 "B"
- %6 = OpTypeVoid
- %7 = OpTypeFunction %6
- %8 = OpTypeInt 32 1
- %9 = OpTypePointer Function %8
- %10 = OpConstant %8 0
- %11 = OpConstant %8 10
- %12 = OpTypeBool
- %13 = OpTypeFloat 32
- %14 = OpTypeInt 32 0
- %15 = OpConstant %14 10
- %16 = OpTypeArray %13 %15
- %17 = OpTypePointer Function %16
- %18 = OpTypePointer Function %13
- %19 = OpConstant %8 1
- %2 = OpFunction %6 None %7
- %20 = OpLabel
- %3 = OpVariable %9 Function
- %4 = OpVariable %17 Function
- %5 = OpVariable %17 Function
- OpBranch %21
- %21 = OpLabel
- %22 = OpPhi %8 %10 %20 %23 %24
- OpLoopMerge %25 %24 None
- OpBranch %26
- %26 = OpLabel
- %27 = OpSLessThan %12 %22 %11
- OpBranchConditional %27 %28 %25
- %28 = OpLabel
- %29 = OpAccessChain %18 %5 %22
- %30 = OpLoad %13 %29
- %31 = OpAccessChain %18 %4 %22
- OpStore %31 %30
- %32 = OpAccessChain %18 %4 %22
- %33 = OpLoad %13 %32
- %34 = OpAccessChain %18 %5 %22
- OpStore %34 %33
- OpBranch %24
- %24 = OpLabel
- %23 = OpIAdd %8 %22 %19
- OpBranch %21
- %25 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const std::string expected = R"(OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %2 "main"
- OpExecutionMode %2 OriginUpperLeft
- OpSource GLSL 430
- OpName %2 "main"
- OpName %3 "i"
- OpName %4 "A"
- OpName %5 "B"
- %6 = OpTypeVoid
- %7 = OpTypeFunction %6
- %8 = OpTypeInt 32 1
- %9 = OpTypePointer Function %8
- %10 = OpConstant %8 0
- %11 = OpConstant %8 10
- %12 = OpTypeBool
- %13 = OpTypeFloat 32
- %14 = OpTypeInt 32 0
- %15 = OpConstant %14 10
- %16 = OpTypeArray %13 %15
- %17 = OpTypePointer Function %16
- %18 = OpTypePointer Function %13
- %19 = OpConstant %8 1
- %2 = OpFunction %6 None %7
- %20 = OpLabel
- %3 = OpVariable %9 Function
- %4 = OpVariable %17 Function
- %5 = OpVariable %17 Function
- OpBranch %35
- %35 = OpLabel
- %36 = OpPhi %8 %10 %20 %47 %46
- OpLoopMerge %48 %46 None
- OpBranch %37
- %37 = OpLabel
- %38 = OpSLessThan %12 %36 %11
- OpBranchConditional %38 %39 %48
- %39 = OpLabel
- %40 = OpAccessChain %18 %5 %36
- %41 = OpLoad %13 %40
- %42 = OpAccessChain %18 %4 %36
- OpStore %42 %41
- OpBranch %46
- %46 = OpLabel
- %47 = OpIAdd %8 %36 %19
- OpBranch %35
- %48 = OpLabel
- OpBranch %21
- %21 = OpLabel
- %22 = OpPhi %8 %10 %48 %23 %24
- OpLoopMerge %25 %24 None
- OpBranch %26
- %26 = OpLabel
- %27 = OpSLessThan %12 %22 %11
- OpBranchConditional %27 %28 %25
- %28 = OpLabel
- %32 = OpAccessChain %18 %4 %22
- %33 = OpLoad %13 %32
- %34 = OpAccessChain %18 %5 %22
- OpStore %34 %33
- OpBranch %24
- %24 = OpLabel
- %23 = OpIAdd %8 %22 %19
- OpBranch %21
- %25 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- // clang-format on
- std::unique_ptr<IRContext> context =
- BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, source,
- SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- Module* module = context->module();
- EXPECT_NE(nullptr, module) << "Assembling failed for shader:\n"
- << source << std::endl;
- SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_NO_HEADER);
- SinglePassRunAndCheck<LoopFissionPass>(source, expected, true);
- // Check that the loop will NOT be split when provided with a pass-through
- // register pressure functor which just returns false.
- SinglePassRunAndCheck<LoopFissionPass>(
- source, source, true,
- [](const RegisterLiveness::RegionRegisterLiveness&) { return false; });
- }
- /*
- Generated from the following GLSL
- #version 430
- void main(void) {
- float A[10];
- float B[10];
- for (int i = 0; i < 10; i++) {
- A[i] = B[i];
- B[i] = A[i+1];
- }
- }
- This loop should not be split, as the i+1 dependence would be broken by
- splitting the loop.
- */
- TEST_F(FissionClassTest, FissionInterdependency) {
- // clang-format off
- // With LocalMultiStoreElimPass
- const std::string source = R"(OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %2 "main"
- OpExecutionMode %2 OriginUpperLeft
- OpSource GLSL 430
- OpName %2 "main"
- OpName %3 "i"
- OpName %4 "A"
- OpName %5 "B"
- %6 = OpTypeVoid
- %7 = OpTypeFunction %6
- %8 = OpTypeInt 32 1
- %9 = OpTypePointer Function %8
- %10 = OpConstant %8 0
- %11 = OpConstant %8 10
- %12 = OpTypeBool
- %13 = OpTypeFloat 32
- %14 = OpTypeInt 32 0
- %15 = OpConstant %14 10
- %16 = OpTypeArray %13 %15
- %17 = OpTypePointer Function %16
- %18 = OpTypePointer Function %13
- %19 = OpConstant %8 1
- %2 = OpFunction %6 None %7
- %20 = OpLabel
- %3 = OpVariable %9 Function
- %4 = OpVariable %17 Function
- %5 = OpVariable %17 Function
- OpBranch %21
- %21 = OpLabel
- %22 = OpPhi %8 %10 %20 %23 %24
- OpLoopMerge %25 %24 None
- OpBranch %26
- %26 = OpLabel
- %27 = OpSLessThan %12 %22 %11
- OpBranchConditional %27 %28 %25
- %28 = OpLabel
- %29 = OpAccessChain %18 %5 %22
- %30 = OpLoad %13 %29
- %31 = OpAccessChain %18 %4 %22
- OpStore %31 %30
- %32 = OpIAdd %8 %22 %19
- %33 = OpAccessChain %18 %4 %32
- %34 = OpLoad %13 %33
- %35 = OpAccessChain %18 %5 %22
- OpStore %35 %34
- OpBranch %24
- %24 = OpLabel
- %23 = OpIAdd %8 %22 %19
- OpBranch %21
- %25 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- // clang-format on
- std::unique_ptr<IRContext> context =
- BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, source,
- SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- Module* module = context->module();
- EXPECT_NE(nullptr, module) << "Assembling failed for ushader:\n"
- << source << std::endl;
- SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_NO_HEADER);
- SinglePassRunAndCheck<LoopFissionPass>(source, source, true);
- }
- /*
- Generated from the following GLSL
- #version 430
- void main(void) {
- float A[10];
- float B[10];
- for (int i = 0; i < 10; i++) {
- A[i] = B[i];
- B[i+1] = A[i];
- }
- }
- This should not be split as the load B[i] is dependent on the store B[i+1]
- */
- TEST_F(FissionClassTest, FissionInterdependency2) {
- // clang-format off
- // With LocalMultiStoreElimPass
- const std::string source = R"(OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %2 "main"
- OpExecutionMode %2 OriginUpperLeft
- OpSource GLSL 430
- OpName %2 "main"
- OpName %3 "i"
- OpName %4 "A"
- OpName %5 "B"
- %6 = OpTypeVoid
- %7 = OpTypeFunction %6
- %8 = OpTypeInt 32 1
- %9 = OpTypePointer Function %8
- %10 = OpConstant %8 0
- %11 = OpConstant %8 10
- %12 = OpTypeBool
- %13 = OpTypeFloat 32
- %14 = OpTypeInt 32 0
- %15 = OpConstant %14 10
- %16 = OpTypeArray %13 %15
- %17 = OpTypePointer Function %16
- %18 = OpTypePointer Function %13
- %19 = OpConstant %8 1
- %2 = OpFunction %6 None %7
- %20 = OpLabel
- %3 = OpVariable %9 Function
- %4 = OpVariable %17 Function
- %5 = OpVariable %17 Function
- OpBranch %21
- %21 = OpLabel
- %22 = OpPhi %8 %10 %20 %23 %24
- OpLoopMerge %25 %24 None
- OpBranch %26
- %26 = OpLabel
- %27 = OpSLessThan %12 %22 %11
- OpBranchConditional %27 %28 %25
- %28 = OpLabel
- %29 = OpAccessChain %18 %5 %22
- %30 = OpLoad %13 %29
- %31 = OpAccessChain %18 %4 %22
- OpStore %31 %30
- %32 = OpIAdd %8 %22 %19
- %33 = OpAccessChain %18 %4 %22
- %34 = OpLoad %13 %33
- %35 = OpAccessChain %18 %5 %32
- OpStore %35 %34
- OpBranch %24
- %24 = OpLabel
- %23 = OpIAdd %8 %22 %19
- OpBranch %21
- %25 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- // clang-format on
- std::unique_ptr<IRContext> context =
- BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, source,
- SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- Module* module = context->module();
- EXPECT_NE(nullptr, module) << "Assembling failed for shader:\n"
- << source << std::endl;
- SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_NO_HEADER);
- SinglePassRunAndCheck<LoopFissionPass>(source, source, true);
- }
- /*
- #version 430
- void main(void) {
- float A[10];
- float B[10];
- float C[10]
- float D[10]
- for (int i = 0; i < 10; i++) {
- A[i] = B[i];
- B[i] = A[i];
- C[i] = D[i];
- D[i] = C[i];
- }
- }
- This should be split into the equivalent of:
- for (int i = 0; i < 10; i++) {
- A[i] = B[i];
- B[i] = A[i];
- }
- for (int i = 0; i < 10; i++) {
- C[i] = D[i];
- D[i] = C[i];
- }
- We then check that the loop is broken into four for loops like so, if the pass
- is run twice:
- for (int i = 0; i < 10; i++)
- A[i] = B[i];
- for (int i = 0; i < 10; i++)
- B[i] = A[i];
- for (int i = 0; i < 10; i++)
- C[i] = D[i];
- for (int i = 0; i < 10; i++)
- D[i] = C[i];
- */
- TEST_F(FissionClassTest, FissionMultipleLoadStores) {
- // clang-format off
- // With LocalMultiStoreElimPass
- const std::string source = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %2 "main"
- OpExecutionMode %2 OriginUpperLeft
- OpSource GLSL 430
- OpName %2 "main"
- OpName %3 "i"
- OpName %4 "A"
- OpName %5 "B"
- OpName %6 "C"
- OpName %7 "D"
- %8 = OpTypeVoid
- %9 = OpTypeFunction %8
- %10 = OpTypeInt 32 1
- %11 = OpTypePointer Function %10
- %12 = OpConstant %10 0
- %13 = OpConstant %10 10
- %14 = OpTypeBool
- %15 = OpTypeFloat 32
- %16 = OpTypeInt 32 0
- %17 = OpConstant %16 10
- %18 = OpTypeArray %15 %17
- %19 = OpTypePointer Function %18
- %20 = OpTypePointer Function %15
- %21 = OpConstant %10 1
- %2 = OpFunction %8 None %9
- %22 = OpLabel
- %3 = OpVariable %11 Function
- %4 = OpVariable %19 Function
- %5 = OpVariable %19 Function
- %6 = OpVariable %19 Function
- %7 = OpVariable %19 Function
- OpBranch %23
- %23 = OpLabel
- %24 = OpPhi %10 %12 %22 %25 %26
- OpLoopMerge %27 %26 None
- OpBranch %28
- %28 = OpLabel
- %29 = OpSLessThan %14 %24 %13
- OpBranchConditional %29 %30 %27
- %30 = OpLabel
- %31 = OpAccessChain %20 %5 %24
- %32 = OpLoad %15 %31
- %33 = OpAccessChain %20 %4 %24
- OpStore %33 %32
- %34 = OpAccessChain %20 %4 %24
- %35 = OpLoad %15 %34
- %36 = OpAccessChain %20 %5 %24
- OpStore %36 %35
- %37 = OpAccessChain %20 %7 %24
- %38 = OpLoad %15 %37
- %39 = OpAccessChain %20 %6 %24
- OpStore %39 %38
- %40 = OpAccessChain %20 %6 %24
- %41 = OpLoad %15 %40
- %42 = OpAccessChain %20 %7 %24
- OpStore %42 %41
- OpBranch %26
- %26 = OpLabel
- %25 = OpIAdd %10 %24 %21
- OpBranch %23
- %27 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const std::string expected = R"(OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %2 "main"
- OpExecutionMode %2 OriginUpperLeft
- OpSource GLSL 430
- OpName %2 "main"
- OpName %3 "i"
- OpName %4 "A"
- OpName %5 "B"
- OpName %6 "C"
- OpName %7 "D"
- %8 = OpTypeVoid
- %9 = OpTypeFunction %8
- %10 = OpTypeInt 32 1
- %11 = OpTypePointer Function %10
- %12 = OpConstant %10 0
- %13 = OpConstant %10 10
- %14 = OpTypeBool
- %15 = OpTypeFloat 32
- %16 = OpTypeInt 32 0
- %17 = OpConstant %16 10
- %18 = OpTypeArray %15 %17
- %19 = OpTypePointer Function %18
- %20 = OpTypePointer Function %15
- %21 = OpConstant %10 1
- %2 = OpFunction %8 None %9
- %22 = OpLabel
- %3 = OpVariable %11 Function
- %4 = OpVariable %19 Function
- %5 = OpVariable %19 Function
- %6 = OpVariable %19 Function
- %7 = OpVariable %19 Function
- OpBranch %43
- %43 = OpLabel
- %44 = OpPhi %10 %12 %22 %61 %60
- OpLoopMerge %62 %60 None
- OpBranch %45
- %45 = OpLabel
- %46 = OpSLessThan %14 %44 %13
- OpBranchConditional %46 %47 %62
- %47 = OpLabel
- %48 = OpAccessChain %20 %5 %44
- %49 = OpLoad %15 %48
- %50 = OpAccessChain %20 %4 %44
- OpStore %50 %49
- %51 = OpAccessChain %20 %4 %44
- %52 = OpLoad %15 %51
- %53 = OpAccessChain %20 %5 %44
- OpStore %53 %52
- OpBranch %60
- %60 = OpLabel
- %61 = OpIAdd %10 %44 %21
- OpBranch %43
- %62 = OpLabel
- OpBranch %23
- %23 = OpLabel
- %24 = OpPhi %10 %12 %62 %25 %26
- OpLoopMerge %27 %26 None
- OpBranch %28
- %28 = OpLabel
- %29 = OpSLessThan %14 %24 %13
- OpBranchConditional %29 %30 %27
- %30 = OpLabel
- %37 = OpAccessChain %20 %7 %24
- %38 = OpLoad %15 %37
- %39 = OpAccessChain %20 %6 %24
- OpStore %39 %38
- %40 = OpAccessChain %20 %6 %24
- %41 = OpLoad %15 %40
- %42 = OpAccessChain %20 %7 %24
- OpStore %42 %41
- OpBranch %26
- %26 = OpLabel
- %25 = OpIAdd %10 %24 %21
- OpBranch %23
- %27 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const std::string expected_multiple_passes = R"(OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %2 "main"
- OpExecutionMode %2 OriginUpperLeft
- OpSource GLSL 430
- OpName %2 "main"
- OpName %3 "i"
- OpName %4 "A"
- OpName %5 "B"
- OpName %6 "C"
- OpName %7 "D"
- %8 = OpTypeVoid
- %9 = OpTypeFunction %8
- %10 = OpTypeInt 32 1
- %11 = OpTypePointer Function %10
- %12 = OpConstant %10 0
- %13 = OpConstant %10 10
- %14 = OpTypeBool
- %15 = OpTypeFloat 32
- %16 = OpTypeInt 32 0
- %17 = OpConstant %16 10
- %18 = OpTypeArray %15 %17
- %19 = OpTypePointer Function %18
- %20 = OpTypePointer Function %15
- %21 = OpConstant %10 1
- %2 = OpFunction %8 None %9
- %22 = OpLabel
- %3 = OpVariable %11 Function
- %4 = OpVariable %19 Function
- %5 = OpVariable %19 Function
- %6 = OpVariable %19 Function
- %7 = OpVariable %19 Function
- OpBranch %63
- %63 = OpLabel
- %64 = OpPhi %10 %12 %22 %75 %74
- OpLoopMerge %76 %74 None
- OpBranch %65
- %65 = OpLabel
- %66 = OpSLessThan %14 %64 %13
- OpBranchConditional %66 %67 %76
- %67 = OpLabel
- %68 = OpAccessChain %20 %5 %64
- %69 = OpLoad %15 %68
- %70 = OpAccessChain %20 %4 %64
- OpStore %70 %69
- OpBranch %74
- %74 = OpLabel
- %75 = OpIAdd %10 %64 %21
- OpBranch %63
- %76 = OpLabel
- OpBranch %43
- %43 = OpLabel
- %44 = OpPhi %10 %12 %76 %61 %60
- OpLoopMerge %62 %60 None
- OpBranch %45
- %45 = OpLabel
- %46 = OpSLessThan %14 %44 %13
- OpBranchConditional %46 %47 %62
- %47 = OpLabel
- %51 = OpAccessChain %20 %4 %44
- %52 = OpLoad %15 %51
- %53 = OpAccessChain %20 %5 %44
- OpStore %53 %52
- OpBranch %60
- %60 = OpLabel
- %61 = OpIAdd %10 %44 %21
- OpBranch %43
- %62 = OpLabel
- OpBranch %77
- %77 = OpLabel
- %78 = OpPhi %10 %12 %62 %89 %88
- OpLoopMerge %90 %88 None
- OpBranch %79
- %79 = OpLabel
- %80 = OpSLessThan %14 %78 %13
- OpBranchConditional %80 %81 %90
- %81 = OpLabel
- %82 = OpAccessChain %20 %7 %78
- %83 = OpLoad %15 %82
- %84 = OpAccessChain %20 %6 %78
- OpStore %84 %83
- OpBranch %88
- %88 = OpLabel
- %89 = OpIAdd %10 %78 %21
- OpBranch %77
- %90 = OpLabel
- OpBranch %23
- %23 = OpLabel
- %24 = OpPhi %10 %12 %90 %25 %26
- OpLoopMerge %27 %26 None
- OpBranch %28
- %28 = OpLabel
- %29 = OpSLessThan %14 %24 %13
- OpBranchConditional %29 %30 %27
- %30 = OpLabel
- %40 = OpAccessChain %20 %6 %24
- %41 = OpLoad %15 %40
- %42 = OpAccessChain %20 %7 %24
- OpStore %42 %41
- OpBranch %26
- %26 = OpLabel
- %25 = OpIAdd %10 %24 %21
- OpBranch %23
- %27 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- // clang-format on
- std::unique_ptr<IRContext> context =
- BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, source,
- SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- Module* module = context->module();
- EXPECT_NE(nullptr, module) << "Assembling failed for shader:\n"
- << source << std::endl;
- SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_NO_HEADER);
- SinglePassRunAndCheck<LoopFissionPass>(source, expected, true);
- // By passing 1 as argument we are using the constructor which makes the
- // criteria to split the loop be if the registers in the loop exceede 1. By
- // using this constructor we are also enabling multiple passes (disabled by
- // default).
- SinglePassRunAndCheck<LoopFissionPass>(source, expected_multiple_passes, true,
- 1);
- }
- /*
- #version 430
- void main(void) {
- int accumulator = 0;
- float X[10];
- float Y[10];
- for (int i = 0; i < 10; i++) {
- X[i] = Y[i];
- Y[i] = X[i];
- accumulator += i;
- }
- }
- This should be split into the equivalent of:
- #version 430
- void main(void) {
- int accumulator = 0;
- float X[10];
- float Y[10];
- for (int i = 0; i < 10; i++) {
- X[i] = Y[i];
- }
- for (int i = 0; i < 10; i++) {
- Y[i] = X[i];
- accumulator += i;
- }
- }
- */
- TEST_F(FissionClassTest, FissionWithAccumulator) {
- // clang-format off
- // With LocalMultiStoreElimPass
- const std::string source = R"(OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %2 "main"
- OpExecutionMode %2 OriginUpperLeft
- OpSource GLSL 430
- OpName %2 "main"
- OpName %3 "accumulator"
- OpName %4 "i"
- OpName %5 "X"
- OpName %6 "Y"
- %7 = OpTypeVoid
- %8 = OpTypeFunction %7
- %9 = OpTypeInt 32 1
- %10 = OpTypePointer Function %9
- %11 = OpConstant %9 0
- %12 = OpConstant %9 10
- %13 = OpTypeBool
- %14 = OpTypeFloat 32
- %15 = OpTypeInt 32 0
- %16 = OpConstant %15 10
- %17 = OpTypeArray %14 %16
- %18 = OpTypePointer Function %17
- %19 = OpTypePointer Function %14
- %20 = OpConstant %9 1
- %2 = OpFunction %7 None %8
- %21 = OpLabel
- %3 = OpVariable %10 Function
- %4 = OpVariable %10 Function
- %5 = OpVariable %18 Function
- %6 = OpVariable %18 Function
- OpBranch %22
- %22 = OpLabel
- %23 = OpPhi %9 %11 %21 %24 %25
- %26 = OpPhi %9 %11 %21 %27 %25
- OpLoopMerge %28 %25 None
- OpBranch %29
- %29 = OpLabel
- %30 = OpSLessThan %13 %26 %12
- OpBranchConditional %30 %31 %28
- %31 = OpLabel
- %32 = OpAccessChain %19 %6 %26
- %33 = OpLoad %14 %32
- %34 = OpAccessChain %19 %5 %26
- OpStore %34 %33
- %35 = OpAccessChain %19 %5 %26
- %36 = OpLoad %14 %35
- %37 = OpAccessChain %19 %6 %26
- OpStore %37 %36
- %24 = OpIAdd %9 %23 %26
- OpBranch %25
- %25 = OpLabel
- %27 = OpIAdd %9 %26 %20
- OpBranch %22
- %28 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const std::string expected = R"(OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %2 "main"
- OpExecutionMode %2 OriginUpperLeft
- OpSource GLSL 430
- OpName %2 "main"
- OpName %3 "accumulator"
- OpName %4 "i"
- OpName %5 "X"
- OpName %6 "Y"
- %7 = OpTypeVoid
- %8 = OpTypeFunction %7
- %9 = OpTypeInt 32 1
- %10 = OpTypePointer Function %9
- %11 = OpConstant %9 0
- %12 = OpConstant %9 10
- %13 = OpTypeBool
- %14 = OpTypeFloat 32
- %15 = OpTypeInt 32 0
- %16 = OpConstant %15 10
- %17 = OpTypeArray %14 %16
- %18 = OpTypePointer Function %17
- %19 = OpTypePointer Function %14
- %20 = OpConstant %9 1
- %2 = OpFunction %7 None %8
- %21 = OpLabel
- %3 = OpVariable %10 Function
- %4 = OpVariable %10 Function
- %5 = OpVariable %18 Function
- %6 = OpVariable %18 Function
- OpBranch %38
- %38 = OpLabel
- %40 = OpPhi %9 %11 %21 %52 %51
- OpLoopMerge %53 %51 None
- OpBranch %41
- %41 = OpLabel
- %42 = OpSLessThan %13 %40 %12
- OpBranchConditional %42 %43 %53
- %43 = OpLabel
- %44 = OpAccessChain %19 %6 %40
- %45 = OpLoad %14 %44
- %46 = OpAccessChain %19 %5 %40
- OpStore %46 %45
- OpBranch %51
- %51 = OpLabel
- %52 = OpIAdd %9 %40 %20
- OpBranch %38
- %53 = OpLabel
- OpBranch %22
- %22 = OpLabel
- %23 = OpPhi %9 %11 %53 %24 %25
- %26 = OpPhi %9 %11 %53 %27 %25
- OpLoopMerge %28 %25 None
- OpBranch %29
- %29 = OpLabel
- %30 = OpSLessThan %13 %26 %12
- OpBranchConditional %30 %31 %28
- %31 = OpLabel
- %35 = OpAccessChain %19 %5 %26
- %36 = OpLoad %14 %35
- %37 = OpAccessChain %19 %6 %26
- OpStore %37 %36
- %24 = OpIAdd %9 %23 %26
- OpBranch %25
- %25 = OpLabel
- %27 = OpIAdd %9 %26 %20
- OpBranch %22
- %28 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- // clang-format on
- std::unique_ptr<IRContext> context =
- BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, source,
- SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- Module* module = context->module();
- EXPECT_NE(nullptr, module) << "Assembling failed for shader:\n"
- << source << std::endl;
- SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_NO_HEADER);
- SinglePassRunAndCheck<LoopFissionPass>(source, expected, true);
- }
- /*
- Generated from the following glsl:
- #version 430
- layout(location=0) out float x;
- layout(location=1) out float y;
- void main(void) {
- float accumulator_1 = 0;
- float accumulator_2 = 0;
- for (int i = 0; i < 10; i++) {
- accumulator_1 += i;
- accumulator_2 += i;
- }
- x = accumulator_1;
- y = accumulator_2;
- }
- Should be split into equivalent of:
- void main(void) {
- float accumulator_1 = 0;
- float accumulator_2 = 0;
- for (int i = 0; i < 10; i++) {
- accumulator_1 += i;
- }
- for (int i = 0; i < 10; i++) {
- accumulator_2 += i;
- }
- x = accumulator_1;
- y = accumulator_2;
- }
- */
- TEST_F(FissionClassTest, FissionWithPhisUsedOutwithLoop) {
- // clang-format off
- // With LocalMultiStoreElimPass
- const std::string source = R"(OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %2 "main" %3 %4
- OpExecutionMode %2 OriginUpperLeft
- OpSource GLSL 430
- OpName %2 "main"
- OpName %5 "accumulator_1"
- OpName %6 "accumulator_2"
- OpName %7 "i"
- OpName %3 "x"
- OpName %4 "y"
- OpDecorate %3 Location 0
- OpDecorate %4 Location 1
- %8 = OpTypeVoid
- %9 = OpTypeFunction %8
- %10 = OpTypeFloat 32
- %11 = OpTypePointer Function %10
- %12 = OpConstant %10 0
- %13 = OpTypeInt 32 1
- %14 = OpTypePointer Function %13
- %15 = OpConstant %13 0
- %16 = OpConstant %13 10
- %17 = OpTypeBool
- %18 = OpConstant %13 1
- %19 = OpTypePointer Output %10
- %3 = OpVariable %19 Output
- %4 = OpVariable %19 Output
- %2 = OpFunction %8 None %9
- %20 = OpLabel
- %5 = OpVariable %11 Function
- %6 = OpVariable %11 Function
- %7 = OpVariable %14 Function
- OpBranch %21
- %21 = OpLabel
- %22 = OpPhi %10 %12 %20 %23 %24
- %25 = OpPhi %10 %12 %20 %26 %24
- %27 = OpPhi %13 %15 %20 %28 %24
- OpLoopMerge %29 %24 None
- OpBranch %30
- %30 = OpLabel
- %31 = OpSLessThan %17 %27 %16
- OpBranchConditional %31 %32 %29
- %32 = OpLabel
- %33 = OpConvertSToF %10 %27
- %26 = OpFAdd %10 %25 %33
- %34 = OpConvertSToF %10 %27
- %23 = OpFAdd %10 %22 %34
- OpBranch %24
- %24 = OpLabel
- %28 = OpIAdd %13 %27 %18
- OpStore %7 %28
- OpBranch %21
- %29 = OpLabel
- OpStore %3 %25
- OpStore %4 %22
- OpReturn
- OpFunctionEnd
- )";
- const std::string expected = R"(OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %2 "main" %3 %4
- OpExecutionMode %2 OriginUpperLeft
- OpSource GLSL 430
- OpName %2 "main"
- OpName %5 "accumulator_1"
- OpName %6 "accumulator_2"
- OpName %7 "i"
- OpName %3 "x"
- OpName %4 "y"
- OpDecorate %3 Location 0
- OpDecorate %4 Location 1
- %8 = OpTypeVoid
- %9 = OpTypeFunction %8
- %10 = OpTypeFloat 32
- %11 = OpTypePointer Function %10
- %12 = OpConstant %10 0
- %13 = OpTypeInt 32 1
- %14 = OpTypePointer Function %13
- %15 = OpConstant %13 0
- %16 = OpConstant %13 10
- %17 = OpTypeBool
- %18 = OpConstant %13 1
- %19 = OpTypePointer Output %10
- %3 = OpVariable %19 Output
- %4 = OpVariable %19 Output
- %2 = OpFunction %8 None %9
- %20 = OpLabel
- %5 = OpVariable %11 Function
- %6 = OpVariable %11 Function
- %7 = OpVariable %14 Function
- OpBranch %35
- %35 = OpLabel
- %37 = OpPhi %10 %12 %20 %43 %46
- %38 = OpPhi %13 %15 %20 %47 %46
- OpLoopMerge %48 %46 None
- OpBranch %39
- %39 = OpLabel
- %40 = OpSLessThan %17 %38 %16
- OpBranchConditional %40 %41 %48
- %41 = OpLabel
- %42 = OpConvertSToF %10 %38
- %43 = OpFAdd %10 %37 %42
- OpBranch %46
- %46 = OpLabel
- %47 = OpIAdd %13 %38 %18
- OpStore %7 %47
- OpBranch %35
- %48 = OpLabel
- OpBranch %21
- %21 = OpLabel
- %22 = OpPhi %10 %12 %48 %23 %24
- %27 = OpPhi %13 %15 %48 %28 %24
- OpLoopMerge %29 %24 None
- OpBranch %30
- %30 = OpLabel
- %31 = OpSLessThan %17 %27 %16
- OpBranchConditional %31 %32 %29
- %32 = OpLabel
- %34 = OpConvertSToF %10 %27
- %23 = OpFAdd %10 %22 %34
- OpBranch %24
- %24 = OpLabel
- %28 = OpIAdd %13 %27 %18
- OpStore %7 %28
- OpBranch %21
- %29 = OpLabel
- OpStore %3 %37
- OpStore %4 %22
- OpReturn
- OpFunctionEnd
- )";
- // clang-format on
- std::unique_ptr<IRContext> context =
- BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, source,
- SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- Module* module = context->module();
- EXPECT_NE(nullptr, module) << "Assembling failed for shader:\n"
- << source << std::endl;
- SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_NO_HEADER);
- SinglePassRunAndCheck<LoopFissionPass>(source, expected, true);
- }
- /*
- #version 430
- void main(void) {
- float A[10][10];
- float B[10][10];
- for (int i = 0; i < 10; i++) {
- for (int j = 0; j < 10; j++) {
- A[i][j] = B[i][j];
- B[i][j] = A[i][j];
- }
- }
- }
- Should be split into equivalent of:
- #version 430
- void main(void) {
- float A[10][10];
- float B[10][10];
- for (int i = 0; i < 10; i++) {
- for (int j = 0; j < 10; j++) {
- A[i][j] = B[i][j];
- }
- for (int j = 0; j < 10; j++) {
- B[i][j] = A[i][j];
- }
- }
- }
- */
- TEST_F(FissionClassTest, FissionNested) {
- // clang-format off
- // With LocalMultiStoreElimPass
- const std::string source = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %2 "main"
- OpExecutionMode %2 OriginUpperLeft
- OpSource GLSL 430
- OpName %2 "main"
- OpName %3 "i"
- OpName %4 "j"
- OpName %5 "A"
- OpName %6 "B"
- %7 = OpTypeVoid
- %8 = OpTypeFunction %7
- %9 = OpTypeInt 32 1
- %10 = OpTypePointer Function %9
- %11 = OpConstant %9 0
- %12 = OpConstant %9 10
- %13 = OpTypeBool
- %14 = OpTypeFloat 32
- %15 = OpTypeInt 32 0
- %16 = OpConstant %15 10
- %17 = OpTypeArray %14 %16
- %18 = OpTypeArray %17 %16
- %19 = OpTypePointer Function %18
- %20 = OpTypePointer Function %14
- %21 = OpConstant %9 1
- %2 = OpFunction %7 None %8
- %22 = OpLabel
- %3 = OpVariable %10 Function
- %4 = OpVariable %10 Function
- %5 = OpVariable %19 Function
- %6 = OpVariable %19 Function
- OpStore %3 %11
- OpBranch %23
- %23 = OpLabel
- %24 = OpPhi %9 %11 %22 %25 %26
- OpLoopMerge %27 %26 None
- OpBranch %28
- %28 = OpLabel
- %29 = OpSLessThan %13 %24 %12
- OpBranchConditional %29 %30 %27
- %30 = OpLabel
- OpStore %4 %11
- OpBranch %31
- %31 = OpLabel
- %32 = OpPhi %9 %11 %30 %33 %34
- OpLoopMerge %35 %34 None
- OpBranch %36
- %36 = OpLabel
- %37 = OpSLessThan %13 %32 %12
- OpBranchConditional %37 %38 %35
- %38 = OpLabel
- %39 = OpAccessChain %20 %6 %24 %32
- %40 = OpLoad %14 %39
- %41 = OpAccessChain %20 %5 %24 %32
- OpStore %41 %40
- %42 = OpAccessChain %20 %5 %24 %32
- %43 = OpLoad %14 %42
- %44 = OpAccessChain %20 %6 %24 %32
- OpStore %44 %43
- OpBranch %34
- %34 = OpLabel
- %33 = OpIAdd %9 %32 %21
- OpStore %4 %33
- OpBranch %31
- %35 = OpLabel
- OpBranch %26
- %26 = OpLabel
- %25 = OpIAdd %9 %24 %21
- OpStore %3 %25
- OpBranch %23
- %27 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const std::string expected = R"(OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %2 "main"
- OpExecutionMode %2 OriginUpperLeft
- OpSource GLSL 430
- OpName %2 "main"
- OpName %3 "i"
- OpName %4 "j"
- OpName %5 "A"
- OpName %6 "B"
- %7 = OpTypeVoid
- %8 = OpTypeFunction %7
- %9 = OpTypeInt 32 1
- %10 = OpTypePointer Function %9
- %11 = OpConstant %9 0
- %12 = OpConstant %9 10
- %13 = OpTypeBool
- %14 = OpTypeFloat 32
- %15 = OpTypeInt 32 0
- %16 = OpConstant %15 10
- %17 = OpTypeArray %14 %16
- %18 = OpTypeArray %17 %16
- %19 = OpTypePointer Function %18
- %20 = OpTypePointer Function %14
- %21 = OpConstant %9 1
- %2 = OpFunction %7 None %8
- %22 = OpLabel
- %3 = OpVariable %10 Function
- %4 = OpVariable %10 Function
- %5 = OpVariable %19 Function
- %6 = OpVariable %19 Function
- OpStore %3 %11
- OpBranch %23
- %23 = OpLabel
- %24 = OpPhi %9 %11 %22 %25 %26
- OpLoopMerge %27 %26 None
- OpBranch %28
- %28 = OpLabel
- %29 = OpSLessThan %13 %24 %12
- OpBranchConditional %29 %30 %27
- %30 = OpLabel
- OpStore %4 %11
- OpBranch %45
- %45 = OpLabel
- %46 = OpPhi %9 %11 %30 %57 %56
- OpLoopMerge %58 %56 None
- OpBranch %47
- %47 = OpLabel
- %48 = OpSLessThan %13 %46 %12
- OpBranchConditional %48 %49 %58
- %49 = OpLabel
- %50 = OpAccessChain %20 %6 %24 %46
- %51 = OpLoad %14 %50
- %52 = OpAccessChain %20 %5 %24 %46
- OpStore %52 %51
- OpBranch %56
- %56 = OpLabel
- %57 = OpIAdd %9 %46 %21
- OpStore %4 %57
- OpBranch %45
- %58 = OpLabel
- OpBranch %31
- %31 = OpLabel
- %32 = OpPhi %9 %11 %58 %33 %34
- OpLoopMerge %35 %34 None
- OpBranch %36
- %36 = OpLabel
- %37 = OpSLessThan %13 %32 %12
- OpBranchConditional %37 %38 %35
- %38 = OpLabel
- %42 = OpAccessChain %20 %5 %24 %32
- %43 = OpLoad %14 %42
- %44 = OpAccessChain %20 %6 %24 %32
- OpStore %44 %43
- OpBranch %34
- %34 = OpLabel
- %33 = OpIAdd %9 %32 %21
- OpStore %4 %33
- OpBranch %31
- %35 = OpLabel
- OpBranch %26
- %26 = OpLabel
- %25 = OpIAdd %9 %24 %21
- OpStore %3 %25
- OpBranch %23
- %27 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- // clang-format on
- std::unique_ptr<IRContext> context =
- BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, source,
- SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- Module* module = context->module();
- EXPECT_NE(nullptr, module) << "Assembling failed for shader:\n"
- << source << std::endl;
- SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_NO_HEADER);
- SinglePassRunAndCheck<LoopFissionPass>(source, expected, true);
- }
- /*
- #version 430
- void main(void) {
- int accumulator = 0;
- float A[10];
- float B[10];
- float C[10];
- for (int i = 0; i < 10; i++) {
- int c = C[i];
- A[i] = B[i];
- B[i] = A[i] + c;
- }
- }
- This loop should not be split as we would have to break the order of the loads
- to do so. It would be grouped into two sets:
- 1
- int c = C[i];
- B[i] = A[i] + c;
- 2
- A[i] = B[i];
- To keep the load C[i] in the same order we would need to put B[i] ahead of that
- */
- TEST_F(FissionClassTest, FissionLoad) {
- // clang-format off
- // With LocalMultiStoreElimPass
- const std::string source = R"(OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %2 "main"
- OpExecutionMode %2 OriginUpperLeft
- OpSource GLSL 430
- OpName %2 "main"
- OpName %3 "i"
- OpName %4 "c"
- OpName %5 "C"
- OpName %6 "A"
- OpName %7 "B"
- %8 = OpTypeVoid
- %9 = OpTypeFunction %8
- %10 = OpTypeInt 32 1
- %11 = OpTypePointer Function %10
- %12 = OpConstant %10 0
- %13 = OpConstant %10 10
- %14 = OpTypeBool
- %15 = OpTypeFloat 32
- %16 = OpTypePointer Function %15
- %17 = OpTypeInt 32 0
- %18 = OpConstant %17 10
- %19 = OpTypeArray %15 %18
- %20 = OpTypePointer Function %19
- %21 = OpConstant %10 1
- %2 = OpFunction %8 None %9
- %22 = OpLabel
- %3 = OpVariable %11 Function
- %4 = OpVariable %16 Function
- %5 = OpVariable %20 Function
- %6 = OpVariable %20 Function
- %7 = OpVariable %20 Function
- OpBranch %23
- %23 = OpLabel
- %24 = OpPhi %10 %12 %22 %25 %26
- OpLoopMerge %27 %26 None
- OpBranch %28
- %28 = OpLabel
- %29 = OpSLessThan %14 %24 %13
- OpBranchConditional %29 %30 %27
- %30 = OpLabel
- %31 = OpAccessChain %16 %5 %24
- %32 = OpLoad %15 %31
- OpStore %4 %32
- %33 = OpAccessChain %16 %7 %24
- %34 = OpLoad %15 %33
- %35 = OpAccessChain %16 %6 %24
- OpStore %35 %34
- %36 = OpAccessChain %16 %6 %24
- %37 = OpLoad %15 %36
- %38 = OpFAdd %15 %37 %32
- %39 = OpAccessChain %16 %7 %24
- OpStore %39 %38
- OpBranch %26
- %26 = OpLabel
- %25 = OpIAdd %10 %24 %21
- OpBranch %23
- %27 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- // clang-format on
- std::unique_ptr<IRContext> context =
- BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, source,
- SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- Module* module = context->module();
- EXPECT_NE(nullptr, module) << "Assembling failed for shader:\n"
- << source << std::endl;
- SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_NO_HEADER);
- SinglePassRunAndCheck<LoopFissionPass>(source, source, true);
- }
- /*
- #version 430
- layout(location=0) flat in int condition;
- void main(void) {
- float A[10];
- float B[10];
- for (int i = 0; i < 10; i++) {
- if (condition == 1)
- A[i] = B[i];
- else
- B[i] = A[i];
- }
- }
- When this is split we leave the condition check and control flow inplace and
- leave its removal for dead code elimination.
- #version 430
- layout(location=0) flat in int condition;
- void main(void) {
- float A[10];
- float B[10];
- for (int i = 0; i < 10; i++) {
- if (condition == 1)
- A[i] = B[i];
- else
- ;
- }
- for (int i = 0; i < 10; i++) {
- if (condition == 1)
- ;
- else
- B[i] = A[i];
- }
- }
- */
- TEST_F(FissionClassTest, FissionControlFlow) {
- // clang-format off
- // With LocalMultiStoreElimPass
- const std::string source = R"(
- OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %2 "main" %3
- OpExecutionMode %2 OriginUpperLeft
- OpSource GLSL 430
- OpName %2 "main"
- OpName %4 "i"
- OpName %3 "condition"
- OpName %5 "A"
- OpName %6 "B"
- OpDecorate %3 Flat
- OpDecorate %3 Location 0
- %7 = OpTypeVoid
- %8 = OpTypeFunction %7
- %9 = OpTypeInt 32 1
- %10 = OpTypePointer Function %9
- %11 = OpConstant %9 0
- %12 = OpConstant %9 10
- %13 = OpTypeBool
- %14 = OpTypePointer Input %9
- %3 = OpVariable %14 Input
- %15 = OpConstant %9 1
- %16 = OpTypeFloat 32
- %17 = OpTypeInt 32 0
- %18 = OpConstant %17 10
- %19 = OpTypeArray %16 %18
- %20 = OpTypePointer Function %19
- %21 = OpTypePointer Function %16
- %2 = OpFunction %7 None %8
- %22 = OpLabel
- %4 = OpVariable %10 Function
- %5 = OpVariable %20 Function
- %6 = OpVariable %20 Function
- %31 = OpLoad %9 %3
- OpStore %4 %11
- OpBranch %23
- %23 = OpLabel
- %24 = OpPhi %9 %11 %22 %25 %26
- OpLoopMerge %27 %26 None
- OpBranch %28
- %28 = OpLabel
- %29 = OpSLessThan %13 %24 %12
- OpBranchConditional %29 %30 %27
- %30 = OpLabel
- %32 = OpIEqual %13 %31 %15
- OpSelectionMerge %33 None
- OpBranchConditional %32 %34 %35
- %34 = OpLabel
- %36 = OpAccessChain %21 %6 %24
- %37 = OpLoad %16 %36
- %38 = OpAccessChain %21 %5 %24
- OpStore %38 %37
- OpBranch %33
- %35 = OpLabel
- %39 = OpAccessChain %21 %5 %24
- %40 = OpLoad %16 %39
- %41 = OpAccessChain %21 %6 %24
- OpStore %41 %40
- OpBranch %33
- %33 = OpLabel
- OpBranch %26
- %26 = OpLabel
- %25 = OpIAdd %9 %24 %15
- OpStore %4 %25
- OpBranch %23
- %27 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const std::string expected = R"(OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %2 "main" %3
- OpExecutionMode %2 OriginUpperLeft
- OpSource GLSL 430
- OpName %2 "main"
- OpName %4 "i"
- OpName %3 "condition"
- OpName %5 "A"
- OpName %6 "B"
- OpDecorate %3 Flat
- OpDecorate %3 Location 0
- %7 = OpTypeVoid
- %8 = OpTypeFunction %7
- %9 = OpTypeInt 32 1
- %10 = OpTypePointer Function %9
- %11 = OpConstant %9 0
- %12 = OpConstant %9 10
- %13 = OpTypeBool
- %14 = OpTypePointer Input %9
- %3 = OpVariable %14 Input
- %15 = OpConstant %9 1
- %16 = OpTypeFloat 32
- %17 = OpTypeInt 32 0
- %18 = OpConstant %17 10
- %19 = OpTypeArray %16 %18
- %20 = OpTypePointer Function %19
- %21 = OpTypePointer Function %16
- %2 = OpFunction %7 None %8
- %22 = OpLabel
- %4 = OpVariable %10 Function
- %5 = OpVariable %20 Function
- %6 = OpVariable %20 Function
- %23 = OpLoad %9 %3
- OpStore %4 %11
- OpBranch %42
- %42 = OpLabel
- %43 = OpPhi %9 %11 %22 %58 %57
- OpLoopMerge %59 %57 None
- OpBranch %44
- %44 = OpLabel
- %45 = OpSLessThan %13 %43 %12
- OpBranchConditional %45 %46 %59
- %46 = OpLabel
- %47 = OpIEqual %13 %23 %15
- OpSelectionMerge %56 None
- OpBranchConditional %47 %52 %48
- %48 = OpLabel
- OpBranch %56
- %52 = OpLabel
- %53 = OpAccessChain %21 %6 %43
- %54 = OpLoad %16 %53
- %55 = OpAccessChain %21 %5 %43
- OpStore %55 %54
- OpBranch %56
- %56 = OpLabel
- OpBranch %57
- %57 = OpLabel
- %58 = OpIAdd %9 %43 %15
- OpStore %4 %58
- OpBranch %42
- %59 = OpLabel
- OpBranch %24
- %24 = OpLabel
- %25 = OpPhi %9 %11 %59 %26 %27
- OpLoopMerge %28 %27 None
- OpBranch %29
- %29 = OpLabel
- %30 = OpSLessThan %13 %25 %12
- OpBranchConditional %30 %31 %28
- %31 = OpLabel
- %32 = OpIEqual %13 %23 %15
- OpSelectionMerge %33 None
- OpBranchConditional %32 %34 %35
- %34 = OpLabel
- OpBranch %33
- %35 = OpLabel
- %39 = OpAccessChain %21 %5 %25
- %40 = OpLoad %16 %39
- %41 = OpAccessChain %21 %6 %25
- OpStore %41 %40
- OpBranch %33
- %33 = OpLabel
- OpBranch %27
- %27 = OpLabel
- %26 = OpIAdd %9 %25 %15
- OpStore %4 %26
- OpBranch %24
- %28 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- // clang-format on
- std::unique_ptr<IRContext> context =
- BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, source,
- SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- Module* module = context->module();
- EXPECT_NE(nullptr, module) << "Assembling failed for shader:\n"
- << source << std::endl;
- SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_NO_HEADER);
- SinglePassRunAndCheck<LoopFissionPass>(source, expected, true);
- }
- /*
- #version 430
- void main(void) {
- float A[10];
- float B[10];
- for (int i = 0; i < 10; i++) {
- if (i == 1)
- B[i] = A[i];
- else if (i == 2)
- A[i] = B[i];
- else
- A[i] = 0;
- }
- }
- After running the pass with multiple splits enabled (via register threshold of
- 1) we expect the equivalent of:
- #version 430
- void main(void) {
- float A[10];
- float B[10];
- for (int i = 0; i < 10; i++) {
- if (i == 1)
- B[i] = A[i];
- else if (i == 2)
- else
- }
- for (int i = 0; i < 10; i++) {
- if (i == 1)
- else if (i == 2)
- A[i] = B[i];
- else
- }
- for (int i = 0; i < 10; i++) {
- if (i == 1)
- else if (i == 2)
- else
- A[i] = 0;
- }
- }
- */
- TEST_F(FissionClassTest, FissionControlFlow2) {
- // clang-format off
- // With LocalMultiStoreElimPass
- const std::string source = R"(OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %2 "main"
- OpExecutionMode %2 OriginUpperLeft
- OpSource GLSL 430
- OpName %2 "main"
- OpName %3 "i"
- OpName %4 "B"
- OpName %5 "A"
- %6 = OpTypeVoid
- %7 = OpTypeFunction %6
- %8 = OpTypeInt 32 1
- %9 = OpTypePointer Function %8
- %10 = OpConstant %8 0
- %11 = OpConstant %8 10
- %12 = OpTypeBool
- %13 = OpConstant %8 1
- %14 = OpTypeFloat 32
- %15 = OpTypeInt 32 0
- %16 = OpConstant %15 10
- %17 = OpTypeArray %14 %16
- %18 = OpTypePointer Function %17
- %19 = OpTypePointer Function %14
- %20 = OpConstant %8 2
- %21 = OpConstant %14 0
- %2 = OpFunction %6 None %7
- %22 = OpLabel
- %3 = OpVariable %9 Function
- %4 = OpVariable %18 Function
- %5 = OpVariable %18 Function
- OpStore %3 %10
- OpBranch %23
- %23 = OpLabel
- %24 = OpPhi %8 %10 %22 %25 %26
- OpLoopMerge %27 %26 None
- OpBranch %28
- %28 = OpLabel
- %29 = OpSLessThan %12 %24 %11
- OpBranchConditional %29 %30 %27
- %30 = OpLabel
- %31 = OpIEqual %12 %24 %13
- OpSelectionMerge %32 None
- OpBranchConditional %31 %33 %34
- %33 = OpLabel
- %35 = OpAccessChain %19 %5 %24
- %36 = OpLoad %14 %35
- %37 = OpAccessChain %19 %4 %24
- OpStore %37 %36
- OpBranch %32
- %34 = OpLabel
- %38 = OpIEqual %12 %24 %20
- OpSelectionMerge %39 None
- OpBranchConditional %38 %40 %41
- %40 = OpLabel
- %42 = OpAccessChain %19 %4 %24
- %43 = OpLoad %14 %42
- %44 = OpAccessChain %19 %5 %24
- OpStore %44 %43
- OpBranch %39
- %41 = OpLabel
- %45 = OpAccessChain %19 %5 %24
- OpStore %45 %21
- OpBranch %39
- %39 = OpLabel
- OpBranch %32
- %32 = OpLabel
- OpBranch %26
- %26 = OpLabel
- %25 = OpIAdd %8 %24 %13
- OpStore %3 %25
- OpBranch %23
- %27 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const std::string expected = R"(OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %2 "main"
- OpExecutionMode %2 OriginUpperLeft
- OpSource GLSL 430
- OpName %2 "main"
- OpName %3 "i"
- OpName %4 "B"
- OpName %5 "A"
- %6 = OpTypeVoid
- %7 = OpTypeFunction %6
- %8 = OpTypeInt 32 1
- %9 = OpTypePointer Function %8
- %10 = OpConstant %8 0
- %11 = OpConstant %8 10
- %12 = OpTypeBool
- %13 = OpConstant %8 1
- %14 = OpTypeFloat 32
- %15 = OpTypeInt 32 0
- %16 = OpConstant %15 10
- %17 = OpTypeArray %14 %16
- %18 = OpTypePointer Function %17
- %19 = OpTypePointer Function %14
- %20 = OpConstant %8 2
- %21 = OpConstant %14 0
- %2 = OpFunction %6 None %7
- %22 = OpLabel
- %3 = OpVariable %9 Function
- %4 = OpVariable %18 Function
- %5 = OpVariable %18 Function
- OpStore %3 %10
- OpBranch %46
- %46 = OpLabel
- %47 = OpPhi %8 %10 %22 %67 %66
- OpLoopMerge %68 %66 None
- OpBranch %48
- %48 = OpLabel
- %49 = OpSLessThan %12 %47 %11
- OpBranchConditional %49 %50 %68
- %50 = OpLabel
- %51 = OpIEqual %12 %47 %13
- OpSelectionMerge %65 None
- OpBranchConditional %51 %61 %52
- %52 = OpLabel
- %53 = OpIEqual %12 %47 %20
- OpSelectionMerge %60 None
- OpBranchConditional %53 %56 %54
- %54 = OpLabel
- OpBranch %60
- %56 = OpLabel
- OpBranch %60
- %60 = OpLabel
- OpBranch %65
- %61 = OpLabel
- %62 = OpAccessChain %19 %5 %47
- %63 = OpLoad %14 %62
- %64 = OpAccessChain %19 %4 %47
- OpStore %64 %63
- OpBranch %65
- %65 = OpLabel
- OpBranch %66
- %66 = OpLabel
- %67 = OpIAdd %8 %47 %13
- OpStore %3 %67
- OpBranch %46
- %68 = OpLabel
- OpBranch %69
- %69 = OpLabel
- %70 = OpPhi %8 %10 %68 %87 %86
- OpLoopMerge %88 %86 None
- OpBranch %71
- %71 = OpLabel
- %72 = OpSLessThan %12 %70 %11
- OpBranchConditional %72 %73 %88
- %73 = OpLabel
- %74 = OpIEqual %12 %70 %13
- OpSelectionMerge %85 None
- OpBranchConditional %74 %84 %75
- %75 = OpLabel
- %76 = OpIEqual %12 %70 %20
- OpSelectionMerge %83 None
- OpBranchConditional %76 %79 %77
- %77 = OpLabel
- OpBranch %83
- %79 = OpLabel
- %80 = OpAccessChain %19 %4 %70
- %81 = OpLoad %14 %80
- %82 = OpAccessChain %19 %5 %70
- OpStore %82 %81
- OpBranch %83
- %83 = OpLabel
- OpBranch %85
- %84 = OpLabel
- OpBranch %85
- %85 = OpLabel
- OpBranch %86
- %86 = OpLabel
- %87 = OpIAdd %8 %70 %13
- OpStore %3 %87
- OpBranch %69
- %88 = OpLabel
- OpBranch %23
- %23 = OpLabel
- %24 = OpPhi %8 %10 %88 %25 %26
- OpLoopMerge %27 %26 None
- OpBranch %28
- %28 = OpLabel
- %29 = OpSLessThan %12 %24 %11
- OpBranchConditional %29 %30 %27
- %30 = OpLabel
- %31 = OpIEqual %12 %24 %13
- OpSelectionMerge %32 None
- OpBranchConditional %31 %33 %34
- %33 = OpLabel
- OpBranch %32
- %34 = OpLabel
- %38 = OpIEqual %12 %24 %20
- OpSelectionMerge %39 None
- OpBranchConditional %38 %40 %41
- %40 = OpLabel
- OpBranch %39
- %41 = OpLabel
- %45 = OpAccessChain %19 %5 %24
- OpStore %45 %21
- OpBranch %39
- %39 = OpLabel
- OpBranch %32
- %32 = OpLabel
- OpBranch %26
- %26 = OpLabel
- %25 = OpIAdd %8 %24 %13
- OpStore %3 %25
- OpBranch %23
- %27 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- // clang-format on
- std::unique_ptr<IRContext> context =
- BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, source,
- SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- Module* module = context->module();
- EXPECT_NE(nullptr, module) << "Assembling failed for shader:\n"
- << source << std::endl;
- SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_NO_HEADER);
- SinglePassRunAndCheck<LoopFissionPass>(source, expected, true, 1);
- }
- /*
- #version 430
- layout(location=0) flat in int condition;
- void main(void) {
- float A[10];
- float B[10];
- for (int i = 0; i < 10; i++) {
- B[i] = A[i];
- memoryBarrier();
- A[i] = B[i];
- }
- }
- This should not be split due to the memory barrier.
- */
- TEST_F(FissionClassTest, FissionBarrier) {
- // clang-format off
- // With LocalMultiStoreElimPass
- const std::string source = R"(OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %2 "main" %3
- OpExecutionMode %2 OriginUpperLeft
- OpSource GLSL 430
- OpName %2 "main"
- OpName %4 "i"
- OpName %5 "B"
- OpName %6 "A"
- OpName %3 "condition"
- OpDecorate %3 Flat
- OpDecorate %3 Location 0
- %7 = OpTypeVoid
- %8 = OpTypeFunction %7
- %9 = OpTypeInt 32 1
- %10 = OpTypePointer Function %9
- %11 = OpConstant %9 0
- %12 = OpConstant %9 10
- %13 = OpTypeBool
- %14 = OpTypeFloat 32
- %15 = OpTypeInt 32 0
- %16 = OpConstant %15 10
- %17 = OpTypeArray %14 %16
- %18 = OpTypePointer Function %17
- %19 = OpTypePointer Function %14
- %20 = OpConstant %15 1
- %21 = OpConstant %15 4048
- %22 = OpConstant %9 1
- %23 = OpTypePointer Input %9
- %3 = OpVariable %23 Input
- %2 = OpFunction %7 None %8
- %24 = OpLabel
- %4 = OpVariable %10 Function
- %5 = OpVariable %18 Function
- %6 = OpVariable %18 Function
- OpStore %4 %11
- OpBranch %25
- %25 = OpLabel
- %26 = OpPhi %9 %11 %24 %27 %28
- OpLoopMerge %29 %28 None
- OpBranch %30
- %30 = OpLabel
- %31 = OpSLessThan %13 %26 %12
- OpBranchConditional %31 %32 %29
- %32 = OpLabel
- %33 = OpAccessChain %19 %6 %26
- %34 = OpLoad %14 %33
- %35 = OpAccessChain %19 %5 %26
- OpStore %35 %34
- OpMemoryBarrier %20 %21
- %36 = OpAccessChain %19 %5 %26
- %37 = OpLoad %14 %36
- %38 = OpAccessChain %19 %6 %26
- OpStore %38 %37
- OpBranch %28
- %28 = OpLabel
- %27 = OpIAdd %9 %26 %22
- OpStore %4 %27
- OpBranch %25
- %29 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- // clang-format on
- std::unique_ptr<IRContext> context =
- BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, source,
- SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- Module* module = context->module();
- EXPECT_NE(nullptr, module) << "Assembling failed for shader:\n"
- << source << std::endl;
- SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_NO_HEADER);
- SinglePassRunAndCheck<LoopFissionPass>(source, source, true);
- }
- /*
- #version 430
- void main(void) {
- float A[10];
- float B[10];
- for (int i = 0; i < 10; i++) {
- B[i] = A[i];
- if ( i== 1)
- break;
- A[i] = B[i];
- }
- }
- This should not be split due to the break.
- */
- TEST_F(FissionClassTest, FissionBreak) {
- // clang-format off
- // With LocalMultiStoreElimPass
- const std::string source = R"(OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %2 "main"
- OpExecutionMode %2 OriginUpperLeft
- OpSource GLSL 430
- OpName %2 "main"
- OpName %3 "i"
- OpName %4 "B"
- OpName %5 "A"
- %6 = OpTypeVoid
- %7 = OpTypeFunction %6
- %8 = OpTypeInt 32 1
- %9 = OpTypePointer Function %8
- %10 = OpConstant %8 0
- %11 = OpConstant %8 10
- %12 = OpTypeBool
- %13 = OpTypeFloat 32
- %14 = OpTypeInt 32 0
- %15 = OpConstant %14 10
- %16 = OpTypeArray %13 %15
- %17 = OpTypePointer Function %16
- %18 = OpTypePointer Function %13
- %19 = OpConstant %8 1
- %2 = OpFunction %6 None %7
- %20 = OpLabel
- %3 = OpVariable %9 Function
- %4 = OpVariable %17 Function
- %5 = OpVariable %17 Function
- OpStore %3 %10
- OpBranch %21
- %21 = OpLabel
- %22 = OpPhi %8 %10 %20 %23 %24
- OpLoopMerge %25 %24 None
- OpBranch %26
- %26 = OpLabel
- %27 = OpSLessThan %12 %22 %11
- OpBranchConditional %27 %28 %25
- %28 = OpLabel
- %29 = OpAccessChain %18 %5 %22
- %30 = OpLoad %13 %29
- %31 = OpAccessChain %18 %4 %22
- OpStore %31 %30
- %32 = OpIEqual %12 %22 %19
- OpSelectionMerge %33 None
- OpBranchConditional %32 %34 %33
- %34 = OpLabel
- OpBranch %25
- %33 = OpLabel
- %35 = OpAccessChain %18 %4 %22
- %36 = OpLoad %13 %35
- %37 = OpAccessChain %18 %5 %22
- OpStore %37 %36
- OpBranch %24
- %24 = OpLabel
- %23 = OpIAdd %8 %22 %19
- OpStore %3 %23
- OpBranch %21
- %25 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- // clang-format on
- std::unique_ptr<IRContext> context =
- BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, source,
- SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- Module* module = context->module();
- EXPECT_NE(nullptr, module) << "Assembling failed for shader:\n"
- << source << std::endl;
- SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_NO_HEADER);
- SinglePassRunAndCheck<LoopFissionPass>(source, source, true);
- }
- /*
- #version 430
- void main(void) {
- float A[10];
- float B[10];
- for (int i = 0; i < 10; i++) {
- B[i] = A[i];
- if ( i== 1)
- continue;
- A[i] = B[i];
- }
- }
- This loop should be split into:
- for (int i = 0; i < 10; i++) {
- B[i] = A[i];
- if ( i== 1)
- continue;
- }
- for (int i = 0; i < 10; i++) {
- if ( i== 1)
- continue;
- A[i] = B[i];
- }
- The continue block in the first loop is left to DCE.
- }
- */
- TEST_F(FissionClassTest, FissionContinue) {
- // clang-format off
- // With LocalMultiStoreElimPass
- const std::string source = R"(OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %2 "main"
- OpExecutionMode %2 OriginUpperLeft
- OpSource GLSL 430
- OpName %2 "main"
- OpName %3 "i"
- OpName %4 "B"
- OpName %5 "A"
- %6 = OpTypeVoid
- %7 = OpTypeFunction %6
- %8 = OpTypeInt 32 1
- %9 = OpTypePointer Function %8
- %10 = OpConstant %8 0
- %11 = OpConstant %8 10
- %12 = OpTypeBool
- %13 = OpTypeFloat 32
- %14 = OpTypeInt 32 0
- %15 = OpConstant %14 10
- %16 = OpTypeArray %13 %15
- %17 = OpTypePointer Function %16
- %18 = OpTypePointer Function %13
- %19 = OpConstant %8 1
- %2 = OpFunction %6 None %7
- %20 = OpLabel
- %3 = OpVariable %9 Function
- %4 = OpVariable %17 Function
- %5 = OpVariable %17 Function
- OpStore %3 %10
- OpBranch %21
- %21 = OpLabel
- %22 = OpPhi %8 %10 %20 %23 %24
- OpLoopMerge %25 %24 None
- OpBranch %26
- %26 = OpLabel
- %27 = OpSLessThan %12 %22 %11
- OpBranchConditional %27 %28 %25
- %28 = OpLabel
- %29 = OpAccessChain %18 %5 %22
- %30 = OpLoad %13 %29
- %31 = OpAccessChain %18 %4 %22
- OpStore %31 %30
- %32 = OpIEqual %12 %22 %19
- OpSelectionMerge %33 None
- OpBranchConditional %32 %34 %33
- %34 = OpLabel
- OpBranch %24
- %33 = OpLabel
- %35 = OpAccessChain %18 %4 %22
- %36 = OpLoad %13 %35
- %37 = OpAccessChain %18 %5 %22
- OpStore %37 %36
- OpBranch %24
- %24 = OpLabel
- %23 = OpIAdd %8 %22 %19
- OpStore %3 %23
- OpBranch %21
- %25 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const std::string expected = R"(OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %2 "main"
- OpExecutionMode %2 OriginUpperLeft
- OpSource GLSL 430
- OpName %2 "main"
- OpName %3 "i"
- OpName %4 "B"
- OpName %5 "A"
- %6 = OpTypeVoid
- %7 = OpTypeFunction %6
- %8 = OpTypeInt 32 1
- %9 = OpTypePointer Function %8
- %10 = OpConstant %8 0
- %11 = OpConstant %8 10
- %12 = OpTypeBool
- %13 = OpTypeFloat 32
- %14 = OpTypeInt 32 0
- %15 = OpConstant %14 10
- %16 = OpTypeArray %13 %15
- %17 = OpTypePointer Function %16
- %18 = OpTypePointer Function %13
- %19 = OpConstant %8 1
- %2 = OpFunction %6 None %7
- %20 = OpLabel
- %3 = OpVariable %9 Function
- %4 = OpVariable %17 Function
- %5 = OpVariable %17 Function
- OpStore %3 %10
- OpBranch %38
- %38 = OpLabel
- %39 = OpPhi %8 %10 %20 %53 %52
- OpLoopMerge %54 %52 None
- OpBranch %40
- %40 = OpLabel
- %41 = OpSLessThan %12 %39 %11
- OpBranchConditional %41 %42 %54
- %42 = OpLabel
- %43 = OpAccessChain %18 %5 %39
- %44 = OpLoad %13 %43
- %45 = OpAccessChain %18 %4 %39
- OpStore %45 %44
- %46 = OpIEqual %12 %39 %19
- OpSelectionMerge %48 None
- OpBranchConditional %46 %47 %48
- %47 = OpLabel
- OpBranch %52
- %48 = OpLabel
- OpBranch %52
- %52 = OpLabel
- %53 = OpIAdd %8 %39 %19
- OpStore %3 %53
- OpBranch %38
- %54 = OpLabel
- OpBranch %21
- %21 = OpLabel
- %22 = OpPhi %8 %10 %54 %23 %24
- OpLoopMerge %25 %24 None
- OpBranch %26
- %26 = OpLabel
- %27 = OpSLessThan %12 %22 %11
- OpBranchConditional %27 %28 %25
- %28 = OpLabel
- %32 = OpIEqual %12 %22 %19
- OpSelectionMerge %33 None
- OpBranchConditional %32 %34 %33
- %34 = OpLabel
- OpBranch %24
- %33 = OpLabel
- %35 = OpAccessChain %18 %4 %22
- %36 = OpLoad %13 %35
- %37 = OpAccessChain %18 %5 %22
- OpStore %37 %36
- OpBranch %24
- %24 = OpLabel
- %23 = OpIAdd %8 %22 %19
- OpStore %3 %23
- OpBranch %21
- %25 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- // clang-format on
- std::unique_ptr<IRContext> context =
- BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, source,
- SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- Module* module = context->module();
- EXPECT_NE(nullptr, module) << "Assembling failed for shader:\n"
- << source << std::endl;
- SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_NO_HEADER);
- SinglePassRunAndCheck<LoopFissionPass>(source, expected, true);
- }
- /*
- #version 430
- void main(void) {
- float A[10];
- float B[10];
- int i = 0;
- do {
- B[i] = A[i];
- A[i] = B[i];
- ++i;
- } while (i < 10);
- }
- Check that this is split into:
- int i = 0;
- do {
- B[i] = A[i];
- ++i;
- } while (i < 10);
- i = 0;
- do {
- A[i] = B[i];
- ++i;
- } while (i < 10);
- */
- TEST_F(FissionClassTest, FissionDoWhile) {
- // clang-format off
- // With LocalMultiStoreElimPass
- const std::string source = R"(OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %2 "main"
- OpExecutionMode %2 OriginUpperLeft
- OpSource GLSL 430
- OpName %2 "main"
- OpName %3 "i"
- OpName %4 "B"
- OpName %5 "A"
- %6 = OpTypeVoid
- %7 = OpTypeFunction %6
- %8 = OpTypeInt 32 1
- %9 = OpTypePointer Function %8
- %10 = OpConstant %8 0
- %11 = OpTypeFloat 32
- %12 = OpTypeInt 32 0
- %13 = OpConstant %12 10
- %14 = OpTypeArray %11 %13
- %15 = OpTypePointer Function %14
- %16 = OpTypePointer Function %11
- %17 = OpConstant %8 1
- %18 = OpConstant %8 10
- %19 = OpTypeBool
- %2 = OpFunction %6 None %7
- %20 = OpLabel
- %3 = OpVariable %9 Function
- %4 = OpVariable %15 Function
- %5 = OpVariable %15 Function
- OpStore %3 %10
- OpBranch %21
- %21 = OpLabel
- %22 = OpPhi %8 %10 %20 %23 %24
- OpLoopMerge %25 %24 None
- OpBranch %26
- %26 = OpLabel
- %27 = OpAccessChain %16 %5 %22
- %28 = OpLoad %11 %27
- %29 = OpAccessChain %16 %4 %22
- OpStore %29 %28
- %30 = OpAccessChain %16 %4 %22
- %31 = OpLoad %11 %30
- %32 = OpAccessChain %16 %5 %22
- OpStore %32 %31
- %23 = OpIAdd %8 %22 %17
- OpStore %3 %23
- OpBranch %24
- %24 = OpLabel
- %33 = OpSLessThan %19 %23 %18
- OpBranchConditional %33 %21 %25
- %25 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const std::string expected = R"(OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %2 "main"
- OpExecutionMode %2 OriginUpperLeft
- OpSource GLSL 430
- OpName %2 "main"
- OpName %3 "i"
- OpName %4 "B"
- OpName %5 "A"
- %6 = OpTypeVoid
- %7 = OpTypeFunction %6
- %8 = OpTypeInt 32 1
- %9 = OpTypePointer Function %8
- %10 = OpConstant %8 0
- %11 = OpTypeFloat 32
- %12 = OpTypeInt 32 0
- %13 = OpConstant %12 10
- %14 = OpTypeArray %11 %13
- %15 = OpTypePointer Function %14
- %16 = OpTypePointer Function %11
- %17 = OpConstant %8 1
- %18 = OpConstant %8 10
- %19 = OpTypeBool
- %2 = OpFunction %6 None %7
- %20 = OpLabel
- %3 = OpVariable %9 Function
- %4 = OpVariable %15 Function
- %5 = OpVariable %15 Function
- OpStore %3 %10
- OpBranch %34
- %34 = OpLabel
- %35 = OpPhi %8 %10 %20 %43 %44
- OpLoopMerge %46 %44 None
- OpBranch %36
- %36 = OpLabel
- %37 = OpAccessChain %16 %5 %35
- %38 = OpLoad %11 %37
- %39 = OpAccessChain %16 %4 %35
- OpStore %39 %38
- %43 = OpIAdd %8 %35 %17
- OpStore %3 %43
- OpBranch %44
- %44 = OpLabel
- %45 = OpSLessThan %19 %43 %18
- OpBranchConditional %45 %34 %46
- %46 = OpLabel
- OpBranch %21
- %21 = OpLabel
- %22 = OpPhi %8 %10 %46 %23 %24
- OpLoopMerge %25 %24 None
- OpBranch %26
- %26 = OpLabel
- %30 = OpAccessChain %16 %4 %22
- %31 = OpLoad %11 %30
- %32 = OpAccessChain %16 %5 %22
- OpStore %32 %31
- %23 = OpIAdd %8 %22 %17
- OpStore %3 %23
- OpBranch %24
- %24 = OpLabel
- %33 = OpSLessThan %19 %23 %18
- OpBranchConditional %33 %21 %25
- %25 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- // clang-format on
- std::unique_ptr<IRContext> context =
- BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, source,
- SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- Module* module = context->module();
- EXPECT_NE(nullptr, module) << "Assembling failed for shader:\n"
- << source << std::endl;
- SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_NO_HEADER);
- SinglePassRunAndCheck<LoopFissionPass>(source, expected, true);
- }
- /*
- #version 430
- void main(void) {
- float A[10][10];
- float B[10][10];
- for (int j = 0; j < 10; ++j) {
- for (int i = 0; i < 10; ++i) {
- B[i][j] = A[i][i];
- A[i][i] = B[i][j + 1];
- }
- }
- }
- This loop can't be split because the load B[i][j + 1] is dependent on the store
- B[i][j].
- */
- TEST_F(FissionClassTest, FissionNestedDependency) {
- // clang-format off
- // With LocalMultiStoreElimPass
- const std::string source = R"(OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %2 "main"
- OpExecutionMode %2 OriginUpperLeft
- OpSource GLSL 430
- OpName %2 "main"
- OpName %3 "j"
- OpName %4 "i"
- OpName %5 "B"
- OpName %6 "A"
- %7 = OpTypeVoid
- %8 = OpTypeFunction %7
- %9 = OpTypeInt 32 1
- %10 = OpTypePointer Function %9
- %11 = OpConstant %9 0
- %12 = OpConstant %9 10
- %13 = OpTypeBool
- %14 = OpTypeFloat 32
- %15 = OpTypeInt 32 0
- %16 = OpConstant %15 10
- %17 = OpTypeArray %14 %16
- %18 = OpTypeArray %17 %16
- %19 = OpTypePointer Function %18
- %20 = OpTypePointer Function %14
- %21 = OpConstant %9 1
- %2 = OpFunction %7 None %8
- %22 = OpLabel
- %3 = OpVariable %10 Function
- %4 = OpVariable %10 Function
- %5 = OpVariable %19 Function
- %6 = OpVariable %19 Function
- OpBranch %23
- %23 = OpLabel
- %24 = OpPhi %9 %11 %22 %25 %26
- OpLoopMerge %27 %26 None
- OpBranch %28
- %28 = OpLabel
- %29 = OpSLessThan %13 %24 %12
- OpBranchConditional %29 %30 %27
- %30 = OpLabel
- OpBranch %31
- %31 = OpLabel
- %32 = OpPhi %9 %11 %30 %33 %34
- OpLoopMerge %35 %34 None
- OpBranch %36
- %36 = OpLabel
- %37 = OpSLessThan %13 %32 %12
- OpBranchConditional %37 %38 %35
- %38 = OpLabel
- %39 = OpAccessChain %20 %6 %32 %32
- %40 = OpLoad %14 %39
- %41 = OpAccessChain %20 %5 %32 %24
- OpStore %41 %40
- %42 = OpIAdd %9 %24 %21
- %43 = OpAccessChain %20 %5 %32 %42
- %44 = OpLoad %14 %43
- %45 = OpAccessChain %20 %6 %32 %32
- OpStore %45 %44
- OpBranch %34
- %34 = OpLabel
- %33 = OpIAdd %9 %32 %21
- OpBranch %31
- %35 = OpLabel
- OpBranch %26
- %26 = OpLabel
- %25 = OpIAdd %9 %24 %21
- OpBranch %23
- %27 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- // clang-format on
- std::unique_ptr<IRContext> context =
- BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, source,
- SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- Module* module = context->module();
- EXPECT_NE(nullptr, module) << "Assembling failed for shader:\n"
- << source << std::endl;
- SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_NO_HEADER);
- SinglePassRunAndCheck<LoopFissionPass>(source, source, true);
- }
- /*
- #version 430
- void main(void) {
- float A[10][10];
- float B[10][10];
- for (int j = 0; j < 10; ++j) {
- for (int i = 0; i < 10; ++i) {
- B[i][i] = A[i][j];
- A[i][j+1] = B[i][i];
- }
- }
- }
- This loop should not be split as the load A[i][j+1] would be reading a value
- written in the store A[i][j] which would be hit before A[i][j+1] if the loops
- where split but would not get hit before the read currently.
- */
- TEST_F(FissionClassTest, FissionNestedDependency2) {
- // clang-format off
- // With LocalMultiStoreElimPass
- const std::string source = R"(OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %2 "main"
- OpExecutionMode %2 OriginUpperLeft
- OpSource GLSL 430
- OpName %2 "main"
- OpName %3 "j"
- OpName %4 "i"
- OpName %5 "B"
- OpName %6 "A"
- %7 = OpTypeVoid
- %8 = OpTypeFunction %7
- %9 = OpTypeInt 32 1
- %10 = OpTypePointer Function %9
- %11 = OpConstant %9 0
- %12 = OpConstant %9 10
- %13 = OpTypeBool
- %14 = OpTypeFloat 32
- %15 = OpTypeInt 32 0
- %16 = OpConstant %15 10
- %17 = OpTypeArray %14 %16
- %18 = OpTypeArray %17 %16
- %19 = OpTypePointer Function %18
- %20 = OpTypePointer Function %14
- %21 = OpConstant %9 1
- %2 = OpFunction %7 None %8
- %22 = OpLabel
- %3 = OpVariable %10 Function
- %4 = OpVariable %10 Function
- %5 = OpVariable %19 Function
- %6 = OpVariable %19 Function
- OpStore %3 %11
- OpBranch %23
- %23 = OpLabel
- %24 = OpPhi %9 %11 %22 %25 %26
- OpLoopMerge %27 %26 None
- OpBranch %28
- %28 = OpLabel
- %29 = OpSLessThan %13 %24 %12
- OpBranchConditional %29 %30 %27
- %30 = OpLabel
- OpStore %4 %11
- OpBranch %31
- %31 = OpLabel
- %32 = OpPhi %9 %11 %30 %33 %34
- OpLoopMerge %35 %34 None
- OpBranch %36
- %36 = OpLabel
- %37 = OpSLessThan %13 %32 %12
- OpBranchConditional %37 %38 %35
- %38 = OpLabel
- %39 = OpAccessChain %20 %6 %32 %24
- %40 = OpLoad %14 %39
- %41 = OpAccessChain %20 %5 %32 %32
- OpStore %41 %40
- %42 = OpIAdd %9 %24 %21
- %43 = OpAccessChain %20 %5 %32 %32
- %44 = OpLoad %14 %43
- %45 = OpAccessChain %20 %6 %32 %42
- OpStore %45 %44
- OpBranch %34
- %34 = OpLabel
- %33 = OpIAdd %9 %32 %21
- OpStore %4 %33
- OpBranch %31
- %35 = OpLabel
- OpBranch %26
- %26 = OpLabel
- %25 = OpIAdd %9 %24 %21
- OpStore %3 %25
- OpBranch %23
- %27 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- // clang-format on
- std::unique_ptr<IRContext> context =
- BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, source,
- SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- Module* module = context->module();
- EXPECT_NE(nullptr, module) << "Assembling failed for shader:\n"
- << source << std::endl;
- SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_NO_HEADER);
- SinglePassRunAndCheck<LoopFissionPass>(source, source, true);
- }
- /*
- #version 430
- void main(void) {
- float A[10][10];
- float B[10][10];
- for (int j = 0; j < 10; ++j) {
- for (int i = 0; i < 10; ++i) {
- B[i][j] = A[i][j];
- A[i][j] = B[i][j];
- }
- for (int i = 0; i < 10; ++i) {
- B[i][j] = A[i][j];
- A[i][j] = B[i][j];
- }
- }
- }
- Should be split into:
- for (int j = 0; j < 10; ++j) {
- for (int i = 0; i < 10; ++i)
- B[i][j] = A[i][j];
- for (int i = 0; i < 10; ++i)
- A[i][j] = B[i][j];
- for (int i = 0; i < 10; ++i)
- B[i][j] = A[i][j];
- for (int i = 0; i < 10; ++i)
- A[i][j] = B[i][j];
- */
- TEST_F(FissionClassTest, FissionMultipleLoopsNested) {
- // clang-format off
- // With LocalMultiStoreElimPass
- const std::string source = R"(OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %2 "main"
- OpExecutionMode %2 OriginUpperLeft
- OpSource GLSL 430
- OpName %2 "main"
- OpName %3 "j"
- OpName %4 "i"
- OpName %5 "B"
- OpName %6 "A"
- OpName %7 "i"
- %8 = OpTypeVoid
- %9 = OpTypeFunction %8
- %10 = OpTypeInt 32 1
- %11 = OpTypePointer Function %10
- %12 = OpConstant %10 0
- %13 = OpConstant %10 10
- %14 = OpTypeBool
- %15 = OpTypeFloat 32
- %16 = OpTypeInt 32 0
- %17 = OpConstant %16 10
- %18 = OpTypeArray %15 %17
- %19 = OpTypeArray %18 %17
- %20 = OpTypePointer Function %19
- %21 = OpTypePointer Function %15
- %22 = OpConstant %10 1
- %2 = OpFunction %8 None %9
- %23 = OpLabel
- %3 = OpVariable %11 Function
- %4 = OpVariable %11 Function
- %5 = OpVariable %20 Function
- %6 = OpVariable %20 Function
- %7 = OpVariable %11 Function
- OpStore %3 %12
- OpBranch %24
- %24 = OpLabel
- %25 = OpPhi %10 %12 %23 %26 %27
- OpLoopMerge %28 %27 None
- OpBranch %29
- %29 = OpLabel
- %30 = OpSLessThan %14 %25 %13
- OpBranchConditional %30 %31 %28
- %31 = OpLabel
- OpStore %4 %12
- OpBranch %32
- %32 = OpLabel
- %33 = OpPhi %10 %12 %31 %34 %35
- OpLoopMerge %36 %35 None
- OpBranch %37
- %37 = OpLabel
- %38 = OpSLessThan %14 %33 %13
- OpBranchConditional %38 %39 %36
- %39 = OpLabel
- %40 = OpAccessChain %21 %6 %33 %25
- %41 = OpLoad %15 %40
- %42 = OpAccessChain %21 %5 %33 %25
- OpStore %42 %41
- %43 = OpAccessChain %21 %5 %33 %25
- %44 = OpLoad %15 %43
- %45 = OpAccessChain %21 %6 %33 %25
- OpStore %45 %44
- OpBranch %35
- %35 = OpLabel
- %34 = OpIAdd %10 %33 %22
- OpStore %4 %34
- OpBranch %32
- %36 = OpLabel
- OpStore %7 %12
- OpBranch %46
- %46 = OpLabel
- %47 = OpPhi %10 %12 %36 %48 %49
- OpLoopMerge %50 %49 None
- OpBranch %51
- %51 = OpLabel
- %52 = OpSLessThan %14 %47 %13
- OpBranchConditional %52 %53 %50
- %53 = OpLabel
- %54 = OpAccessChain %21 %6 %47 %25
- %55 = OpLoad %15 %54
- %56 = OpAccessChain %21 %5 %47 %25
- OpStore %56 %55
- %57 = OpAccessChain %21 %5 %47 %25
- %58 = OpLoad %15 %57
- %59 = OpAccessChain %21 %6 %47 %25
- OpStore %59 %58
- OpBranch %49
- %49 = OpLabel
- %48 = OpIAdd %10 %47 %22
- OpStore %7 %48
- OpBranch %46
- %50 = OpLabel
- OpBranch %27
- %27 = OpLabel
- %26 = OpIAdd %10 %25 %22
- OpStore %3 %26
- OpBranch %24
- %28 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const std::string expected = R"(OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %2 "main"
- OpExecutionMode %2 OriginUpperLeft
- OpSource GLSL 430
- OpName %2 "main"
- OpName %3 "j"
- OpName %4 "i"
- OpName %5 "B"
- OpName %6 "A"
- OpName %7 "i"
- %8 = OpTypeVoid
- %9 = OpTypeFunction %8
- %10 = OpTypeInt 32 1
- %11 = OpTypePointer Function %10
- %12 = OpConstant %10 0
- %13 = OpConstant %10 10
- %14 = OpTypeBool
- %15 = OpTypeFloat 32
- %16 = OpTypeInt 32 0
- %17 = OpConstant %16 10
- %18 = OpTypeArray %15 %17
- %19 = OpTypeArray %18 %17
- %20 = OpTypePointer Function %19
- %21 = OpTypePointer Function %15
- %22 = OpConstant %10 1
- %2 = OpFunction %8 None %9
- %23 = OpLabel
- %3 = OpVariable %11 Function
- %4 = OpVariable %11 Function
- %5 = OpVariable %20 Function
- %6 = OpVariable %20 Function
- %7 = OpVariable %11 Function
- OpStore %3 %12
- OpBranch %24
- %24 = OpLabel
- %25 = OpPhi %10 %12 %23 %26 %27
- OpLoopMerge %28 %27 None
- OpBranch %29
- %29 = OpLabel
- %30 = OpSLessThan %14 %25 %13
- OpBranchConditional %30 %31 %28
- %31 = OpLabel
- OpStore %4 %12
- OpBranch %60
- %60 = OpLabel
- %61 = OpPhi %10 %12 %31 %72 %71
- OpLoopMerge %73 %71 None
- OpBranch %62
- %62 = OpLabel
- %63 = OpSLessThan %14 %61 %13
- OpBranchConditional %63 %64 %73
- %64 = OpLabel
- %65 = OpAccessChain %21 %6 %61 %25
- %66 = OpLoad %15 %65
- %67 = OpAccessChain %21 %5 %61 %25
- OpStore %67 %66
- OpBranch %71
- %71 = OpLabel
- %72 = OpIAdd %10 %61 %22
- OpStore %4 %72
- OpBranch %60
- %73 = OpLabel
- OpBranch %32
- %32 = OpLabel
- %33 = OpPhi %10 %12 %73 %34 %35
- OpLoopMerge %36 %35 None
- OpBranch %37
- %37 = OpLabel
- %38 = OpSLessThan %14 %33 %13
- OpBranchConditional %38 %39 %36
- %39 = OpLabel
- %43 = OpAccessChain %21 %5 %33 %25
- %44 = OpLoad %15 %43
- %45 = OpAccessChain %21 %6 %33 %25
- OpStore %45 %44
- OpBranch %35
- %35 = OpLabel
- %34 = OpIAdd %10 %33 %22
- OpStore %4 %34
- OpBranch %32
- %36 = OpLabel
- OpStore %7 %12
- OpBranch %74
- %74 = OpLabel
- %75 = OpPhi %10 %12 %36 %86 %85
- OpLoopMerge %87 %85 None
- OpBranch %76
- %76 = OpLabel
- %77 = OpSLessThan %14 %75 %13
- OpBranchConditional %77 %78 %87
- %78 = OpLabel
- %79 = OpAccessChain %21 %6 %75 %25
- %80 = OpLoad %15 %79
- %81 = OpAccessChain %21 %5 %75 %25
- OpStore %81 %80
- OpBranch %85
- %85 = OpLabel
- %86 = OpIAdd %10 %75 %22
- OpStore %7 %86
- OpBranch %74
- %87 = OpLabel
- OpBranch %46
- %46 = OpLabel
- %47 = OpPhi %10 %12 %87 %48 %49
- OpLoopMerge %50 %49 None
- OpBranch %51
- %51 = OpLabel
- %52 = OpSLessThan %14 %47 %13
- OpBranchConditional %52 %53 %50
- %53 = OpLabel
- %57 = OpAccessChain %21 %5 %47 %25
- %58 = OpLoad %15 %57
- %59 = OpAccessChain %21 %6 %47 %25
- OpStore %59 %58
- OpBranch %49
- %49 = OpLabel
- %48 = OpIAdd %10 %47 %22
- OpStore %7 %48
- OpBranch %46
- %50 = OpLabel
- OpBranch %27
- %27 = OpLabel
- %26 = OpIAdd %10 %25 %22
- OpStore %3 %26
- OpBranch %24
- %28 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- // clang-format on
- std::unique_ptr<IRContext> context =
- BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, source,
- SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- Module* module = context->module();
- EXPECT_NE(nullptr, module) << "Assembling failed for shader:\n"
- << source << std::endl;
- const Function* function = spvtest::GetFunction(module, 2);
- LoopDescriptor& pre_pass_descriptor = *context->GetLoopDescriptor(function);
- EXPECT_EQ(pre_pass_descriptor.NumLoops(), 3u);
- EXPECT_EQ(pre_pass_descriptor.pre_begin()->NumImmediateChildren(), 2u);
- // Test that the pass transforms the ir into the expected output.
- SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_NO_HEADER);
- SinglePassRunAndCheck<LoopFissionPass>(source, expected, true);
- // Test that the loop descriptor is correctly maintained and updated by the
- // pass.
- LoopFissionPass loop_fission;
- loop_fission.SetContextForTesting(context.get());
- loop_fission.Process();
- function = spvtest::GetFunction(module, 2);
- LoopDescriptor& post_pass_descriptor = *context->GetLoopDescriptor(function);
- EXPECT_EQ(post_pass_descriptor.NumLoops(), 5u);
- EXPECT_EQ(post_pass_descriptor.pre_begin()->NumImmediateChildren(), 4u);
- }
- /*
- #version 430
- void main(void) {
- float A[10][10];
- float B[10][10];
- for (int i = 0; i < 10; ++i) {
- B[i][i] = A[i][i];
- A[i][i] = B[i][i];
- }
- for (int i = 0; i < 10; ++i) {
- B[i][i] = A[i][i];
- A[i][i] = B[i][i]
- }
- }
- Should be split into:
- for (int i = 0; i < 10; ++i)
- B[i][i] = A[i][i];
- for (int i = 0; i < 10; ++i)
- A[i][i] = B[i][i];
- for (int i = 0; i < 10; ++i)
- B[i][i] = A[i][i];
- for (int i = 0; i < 10; ++i)
- A[i][i] = B[i][i];
- */
- TEST_F(FissionClassTest, FissionMultipleLoops) {
- // clang-format off
- // With LocalMultiStoreElimPass
- const std::string source = R"(OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %2 "main"
- OpExecutionMode %2 OriginUpperLeft
- OpSource GLSL 430
- OpName %2 "main"
- OpName %3 "i"
- OpName %4 "B"
- OpName %5 "A"
- OpName %6 "i"
- %7 = OpTypeVoid
- %8 = OpTypeFunction %7
- %9 = OpTypeInt 32 1
- %10 = OpTypePointer Function %9
- %11 = OpConstant %9 0
- %12 = OpConstant %9 10
- %13 = OpTypeBool
- %14 = OpTypeFloat 32
- %15 = OpTypeInt 32 0
- %16 = OpConstant %15 10
- %17 = OpTypeArray %14 %16
- %18 = OpTypePointer Function %17
- %19 = OpTypePointer Function %14
- %20 = OpConstant %9 1
- %2 = OpFunction %7 None %8
- %21 = OpLabel
- %3 = OpVariable %10 Function
- %4 = OpVariable %18 Function
- %5 = OpVariable %18 Function
- %6 = OpVariable %10 Function
- OpStore %3 %11
- OpBranch %22
- %22 = OpLabel
- %23 = OpPhi %9 %11 %21 %24 %25
- OpLoopMerge %26 %25 None
- OpBranch %27
- %27 = OpLabel
- %28 = OpSLessThan %13 %23 %12
- OpBranchConditional %28 %29 %26
- %29 = OpLabel
- %30 = OpAccessChain %19 %5 %23
- %31 = OpLoad %14 %30
- %32 = OpAccessChain %19 %4 %23
- OpStore %32 %31
- %33 = OpAccessChain %19 %4 %23
- %34 = OpLoad %14 %33
- %35 = OpAccessChain %19 %5 %23
- OpStore %35 %34
- OpBranch %25
- %25 = OpLabel
- %24 = OpIAdd %9 %23 %20
- OpStore %3 %24
- OpBranch %22
- %26 = OpLabel
- OpStore %6 %11
- OpBranch %36
- %36 = OpLabel
- %37 = OpPhi %9 %11 %26 %38 %39
- OpLoopMerge %40 %39 None
- OpBranch %41
- %41 = OpLabel
- %42 = OpSLessThan %13 %37 %12
- OpBranchConditional %42 %43 %40
- %43 = OpLabel
- %44 = OpAccessChain %19 %5 %37
- %45 = OpLoad %14 %44
- %46 = OpAccessChain %19 %4 %37
- OpStore %46 %45
- %47 = OpAccessChain %19 %4 %37
- %48 = OpLoad %14 %47
- %49 = OpAccessChain %19 %5 %37
- OpStore %49 %48
- OpBranch %39
- %39 = OpLabel
- %38 = OpIAdd %9 %37 %20
- OpStore %6 %38
- OpBranch %36
- %40 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const std::string expected = R"(OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %2 "main"
- OpExecutionMode %2 OriginUpperLeft
- OpSource GLSL 430
- OpName %2 "main"
- OpName %3 "i"
- OpName %4 "B"
- OpName %5 "A"
- OpName %6 "i"
- %7 = OpTypeVoid
- %8 = OpTypeFunction %7
- %9 = OpTypeInt 32 1
- %10 = OpTypePointer Function %9
- %11 = OpConstant %9 0
- %12 = OpConstant %9 10
- %13 = OpTypeBool
- %14 = OpTypeFloat 32
- %15 = OpTypeInt 32 0
- %16 = OpConstant %15 10
- %17 = OpTypeArray %14 %16
- %18 = OpTypePointer Function %17
- %19 = OpTypePointer Function %14
- %20 = OpConstant %9 1
- %2 = OpFunction %7 None %8
- %21 = OpLabel
- %3 = OpVariable %10 Function
- %4 = OpVariable %18 Function
- %5 = OpVariable %18 Function
- %6 = OpVariable %10 Function
- OpStore %3 %11
- OpBranch %64
- %64 = OpLabel
- %65 = OpPhi %9 %11 %21 %76 %75
- OpLoopMerge %77 %75 None
- OpBranch %66
- %66 = OpLabel
- %67 = OpSLessThan %13 %65 %12
- OpBranchConditional %67 %68 %77
- %68 = OpLabel
- %69 = OpAccessChain %19 %5 %65
- %70 = OpLoad %14 %69
- %71 = OpAccessChain %19 %4 %65
- OpStore %71 %70
- OpBranch %75
- %75 = OpLabel
- %76 = OpIAdd %9 %65 %20
- OpStore %3 %76
- OpBranch %64
- %77 = OpLabel
- OpBranch %22
- %22 = OpLabel
- %23 = OpPhi %9 %11 %77 %24 %25
- OpLoopMerge %26 %25 None
- OpBranch %27
- %27 = OpLabel
- %28 = OpSLessThan %13 %23 %12
- OpBranchConditional %28 %29 %26
- %29 = OpLabel
- %33 = OpAccessChain %19 %4 %23
- %34 = OpLoad %14 %33
- %35 = OpAccessChain %19 %5 %23
- OpStore %35 %34
- OpBranch %25
- %25 = OpLabel
- %24 = OpIAdd %9 %23 %20
- OpStore %3 %24
- OpBranch %22
- %26 = OpLabel
- OpStore %6 %11
- OpBranch %50
- %50 = OpLabel
- %51 = OpPhi %9 %11 %26 %62 %61
- OpLoopMerge %63 %61 None
- OpBranch %52
- %52 = OpLabel
- %53 = OpSLessThan %13 %51 %12
- OpBranchConditional %53 %54 %63
- %54 = OpLabel
- %55 = OpAccessChain %19 %5 %51
- %56 = OpLoad %14 %55
- %57 = OpAccessChain %19 %4 %51
- OpStore %57 %56
- OpBranch %61
- %61 = OpLabel
- %62 = OpIAdd %9 %51 %20
- OpStore %6 %62
- OpBranch %50
- %63 = OpLabel
- OpBranch %36
- %36 = OpLabel
- %37 = OpPhi %9 %11 %63 %38 %39
- OpLoopMerge %40 %39 None
- OpBranch %41
- %41 = OpLabel
- %42 = OpSLessThan %13 %37 %12
- OpBranchConditional %42 %43 %40
- %43 = OpLabel
- %47 = OpAccessChain %19 %4 %37
- %48 = OpLoad %14 %47
- %49 = OpAccessChain %19 %5 %37
- OpStore %49 %48
- OpBranch %39
- %39 = OpLabel
- %38 = OpIAdd %9 %37 %20
- OpStore %6 %38
- OpBranch %36
- %40 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- // clang-format on
- std::unique_ptr<IRContext> context =
- BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, source,
- SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- Module* module = context->module();
- EXPECT_NE(nullptr, module) << "Assembling failed for shader:\n"
- << source << std::endl;
- SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_NO_HEADER);
- SinglePassRunAndCheck<LoopFissionPass>(source, expected, true);
- const Function* function = spvtest::GetFunction(module, 2);
- LoopDescriptor& pre_pass_descriptor = *context->GetLoopDescriptor(function);
- EXPECT_EQ(pre_pass_descriptor.NumLoops(), 2u);
- EXPECT_EQ(pre_pass_descriptor.pre_begin()->NumImmediateChildren(), 0u);
- // Test that the pass transforms the ir into the expected output.
- SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_NO_HEADER);
- SinglePassRunAndCheck<LoopFissionPass>(source, expected, true);
- // Test that the loop descriptor is correctly maintained and updated by the
- // pass.
- LoopFissionPass loop_fission;
- loop_fission.SetContextForTesting(context.get());
- loop_fission.Process();
- function = spvtest::GetFunction(module, 2);
- LoopDescriptor& post_pass_descriptor = *context->GetLoopDescriptor(function);
- EXPECT_EQ(post_pass_descriptor.NumLoops(), 4u);
- EXPECT_EQ(post_pass_descriptor.pre_begin()->NumImmediateChildren(), 0u);
- }
- /*
- #version 430
- int foo() { return 1; }
- void main(void) {
- float A[10];
- float B[10];
- for (int i = 0; i < 10; ++i) {
- B[i] = A[i];
- foo();
- A[i] = B[i];
- }
- }
- This should not be split as it has a function call in it so we can't determine
- if it has side effects.
- */
- TEST_F(FissionClassTest, FissionFunctionCall) {
- // clang-format off
- // With LocalMultiStoreElimPass
- const std::string source = R"(OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %2 "main"
- OpExecutionMode %2 OriginUpperLeft
- OpSource GLSL 430
- OpName %2 "main"
- OpName %3 "foo("
- OpName %4 "i"
- OpName %5 "B"
- OpName %6 "A"
- %7 = OpTypeVoid
- %8 = OpTypeFunction %7
- %9 = OpTypeInt 32 1
- %10 = OpTypeFunction %9
- %11 = OpConstant %9 1
- %12 = OpTypePointer Function %9
- %13 = OpConstant %9 0
- %14 = OpConstant %9 10
- %15 = OpTypeBool
- %16 = OpTypeFloat 32
- %17 = OpTypeInt 32 0
- %18 = OpConstant %17 10
- %19 = OpTypeArray %16 %18
- %20 = OpTypePointer Function %19
- %21 = OpTypePointer Function %16
- %2 = OpFunction %7 None %8
- %22 = OpLabel
- %4 = OpVariable %12 Function
- %5 = OpVariable %20 Function
- %6 = OpVariable %20 Function
- OpStore %4 %13
- OpBranch %23
- %23 = OpLabel
- %24 = OpPhi %9 %13 %22 %25 %26
- OpLoopMerge %27 %26 None
- OpBranch %28
- %28 = OpLabel
- %29 = OpSLessThan %15 %24 %14
- OpBranchConditional %29 %30 %27
- %30 = OpLabel
- %31 = OpAccessChain %21 %6 %24
- %32 = OpLoad %16 %31
- %33 = OpAccessChain %21 %5 %24
- OpStore %33 %32
- %34 = OpFunctionCall %9 %3
- %35 = OpAccessChain %21 %5 %24
- %36 = OpLoad %16 %35
- %37 = OpAccessChain %21 %6 %24
- OpStore %37 %36
- OpBranch %26
- %26 = OpLabel
- %25 = OpIAdd %9 %24 %11
- OpStore %4 %25
- OpBranch %23
- %27 = OpLabel
- OpReturn
- OpFunctionEnd
- %3 = OpFunction %9 None %10
- %38 = OpLabel
- OpReturnValue %11
- OpFunctionEnd
- )";
- // clang-format on
- std::unique_ptr<IRContext> context =
- BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, source,
- SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- Module* module = context->module();
- EXPECT_NE(nullptr, module) << "Assembling failed for shader:\n"
- << source << std::endl;
- SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_NO_HEADER);
- SinglePassRunAndCheck<LoopFissionPass>(source, source, true);
- }
- /*
- #version 430
- void main(void) {
- float A[10];
- float B[10];
- for (int i = 0; i < 10; ++i) {
- switch (i) {
- case 1:
- B[i] = A[i];
- break;
- default:
- A[i] = B[i];
- }
- }
- }
- This should be split into:
- for (int i = 0; i < 10; ++i) {
- switch (i) {
- case 1:
- break;
- default:
- A[i] = B[i];
- }
- }
- for (int i = 0; i < 10; ++i) {
- switch (i) {
- case 1:
- B[i] = A[i];
- break;
- default:
- break;
- }
- }
- */
- TEST_F(FissionClassTest, FissionSwitchStatement) {
- // clang-format off
- // With LocalMultiStoreElimPass
- const std::string source = R"(OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %2 "main"
- OpExecutionMode %2 OriginUpperLeft
- OpSource GLSL 430
- OpName %2 "main"
- OpName %3 "i"
- OpName %4 "B"
- OpName %5 "A"
- %6 = OpTypeVoid
- %7 = OpTypeFunction %6
- %8 = OpTypeInt 32 1
- %9 = OpTypePointer Function %8
- %10 = OpConstant %8 0
- %11 = OpConstant %8 10
- %12 = OpTypeBool
- %13 = OpTypeFloat 32
- %14 = OpTypeInt 32 0
- %15 = OpConstant %14 10
- %16 = OpTypeArray %13 %15
- %17 = OpTypePointer Function %16
- %18 = OpTypePointer Function %13
- %19 = OpConstant %8 1
- %2 = OpFunction %6 None %7
- %20 = OpLabel
- %3 = OpVariable %9 Function
- %4 = OpVariable %17 Function
- %5 = OpVariable %17 Function
- OpStore %3 %10
- OpBranch %21
- %21 = OpLabel
- %22 = OpPhi %8 %10 %20 %23 %24
- OpLoopMerge %25 %24 None
- OpBranch %26
- %26 = OpLabel
- %27 = OpSLessThan %12 %22 %11
- OpBranchConditional %27 %28 %25
- %28 = OpLabel
- OpSelectionMerge %29 None
- OpSwitch %22 %30 1 %31
- %30 = OpLabel
- %32 = OpAccessChain %18 %4 %22
- %33 = OpLoad %13 %32
- %34 = OpAccessChain %18 %5 %22
- OpStore %34 %33
- OpBranch %29
- %31 = OpLabel
- %35 = OpAccessChain %18 %5 %22
- %36 = OpLoad %13 %35
- %37 = OpAccessChain %18 %4 %22
- OpStore %37 %36
- OpBranch %29
- %29 = OpLabel
- OpBranch %24
- %24 = OpLabel
- %23 = OpIAdd %8 %22 %19
- OpStore %3 %23
- OpBranch %21
- %25 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- const std::string expected = R"(OpCapability Shader
- %1 = OpExtInstImport "GLSL.std.450"
- OpMemoryModel Logical GLSL450
- OpEntryPoint Fragment %2 "main"
- OpExecutionMode %2 OriginUpperLeft
- OpSource GLSL 430
- OpName %2 "main"
- OpName %3 "i"
- OpName %4 "B"
- OpName %5 "A"
- %6 = OpTypeVoid
- %7 = OpTypeFunction %6
- %8 = OpTypeInt 32 1
- %9 = OpTypePointer Function %8
- %10 = OpConstant %8 0
- %11 = OpConstant %8 10
- %12 = OpTypeBool
- %13 = OpTypeFloat 32
- %14 = OpTypeInt 32 0
- %15 = OpConstant %14 10
- %16 = OpTypeArray %13 %15
- %17 = OpTypePointer Function %16
- %18 = OpTypePointer Function %13
- %19 = OpConstant %8 1
- %2 = OpFunction %6 None %7
- %20 = OpLabel
- %3 = OpVariable %9 Function
- %4 = OpVariable %17 Function
- %5 = OpVariable %17 Function
- OpStore %3 %10
- OpBranch %38
- %38 = OpLabel
- %39 = OpPhi %8 %10 %20 %53 %52
- OpLoopMerge %54 %52 None
- OpBranch %40
- %40 = OpLabel
- %41 = OpSLessThan %12 %39 %11
- OpBranchConditional %41 %42 %54
- %42 = OpLabel
- OpSelectionMerge %51 None
- OpSwitch %39 %47 1 %43
- %43 = OpLabel
- OpBranch %51
- %47 = OpLabel
- %48 = OpAccessChain %18 %4 %39
- %49 = OpLoad %13 %48
- %50 = OpAccessChain %18 %5 %39
- OpStore %50 %49
- OpBranch %51
- %51 = OpLabel
- OpBranch %52
- %52 = OpLabel
- %53 = OpIAdd %8 %39 %19
- OpStore %3 %53
- OpBranch %38
- %54 = OpLabel
- OpBranch %21
- %21 = OpLabel
- %22 = OpPhi %8 %10 %54 %23 %24
- OpLoopMerge %25 %24 None
- OpBranch %26
- %26 = OpLabel
- %27 = OpSLessThan %12 %22 %11
- OpBranchConditional %27 %28 %25
- %28 = OpLabel
- OpSelectionMerge %29 None
- OpSwitch %22 %30 1 %31
- %30 = OpLabel
- OpBranch %29
- %31 = OpLabel
- %35 = OpAccessChain %18 %5 %22
- %36 = OpLoad %13 %35
- %37 = OpAccessChain %18 %4 %22
- OpStore %37 %36
- OpBranch %29
- %29 = OpLabel
- OpBranch %24
- %24 = OpLabel
- %23 = OpIAdd %8 %22 %19
- OpStore %3 %23
- OpBranch %21
- %25 = OpLabel
- OpReturn
- OpFunctionEnd
- )";
- // clang-format on
- std::unique_ptr<IRContext> context =
- BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, source,
- SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
- Module* module = context->module();
- EXPECT_NE(nullptr, module) << "Assembling failed for shader:\n"
- << source << std::endl;
- SetDisassembleOptions(SPV_BINARY_TO_TEXT_OPTION_NO_HEADER);
- SinglePassRunAndCheck<LoopFissionPass>(source, expected, true);
- }
- } // namespace
- } // namespace opt
- } // namespace spvtools
|