123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277 |
- #include "AArch64ISelLowering.h"
- #include "AArch64CallingConvention.h"
- #include "AArch64ExpandImm.h"
- #include "AArch64MachineFunctionInfo.h"
- #include "AArch64PerfectShuffle.h"
- #include "AArch64RegisterInfo.h"
- #include "AArch64Subtarget.h"
- #include "MCTargetDesc/AArch64AddressingModes.h"
- #include "Utils/AArch64BaseInfo.h"
- #include "llvm/ADT/APFloat.h"
- #include "llvm/ADT/APInt.h"
- #include "llvm/ADT/ArrayRef.h"
- #include "llvm/ADT/STLExtras.h"
- #include "llvm/ADT/SmallSet.h"
- #include "llvm/ADT/SmallVector.h"
- #include "llvm/ADT/Statistic.h"
- #include "llvm/ADT/StringRef.h"
- #include "llvm/ADT/Triple.h"
- #include "llvm/ADT/Twine.h"
- #include "llvm/Analysis/VectorUtils.h"
- #include "llvm/CodeGen/CallingConvLower.h"
- #include "llvm/CodeGen/MachineBasicBlock.h"
- #include "llvm/CodeGen/MachineFrameInfo.h"
- #include "llvm/CodeGen/MachineFunction.h"
- #include "llvm/CodeGen/MachineInstr.h"
- #include "llvm/CodeGen/MachineInstrBuilder.h"
- #include "llvm/CodeGen/MachineMemOperand.h"
- #include "llvm/CodeGen/MachineRegisterInfo.h"
- #include "llvm/CodeGen/RuntimeLibcalls.h"
- #include "llvm/CodeGen/SelectionDAG.h"
- #include "llvm/CodeGen/SelectionDAGNodes.h"
- #include "llvm/CodeGen/TargetCallingConv.h"
- #include "llvm/CodeGen/TargetInstrInfo.h"
- #include "llvm/CodeGen/ValueTypes.h"
- #include "llvm/IR/Attributes.h"
- #include "llvm/IR/Constants.h"
- #include "llvm/IR/DataLayout.h"
- #include "llvm/IR/DebugLoc.h"
- #include "llvm/IR/DerivedTypes.h"
- #include "llvm/IR/Function.h"
- #include "llvm/IR/GetElementPtrTypeIterator.h"
- #include "llvm/IR/GlobalValue.h"
- #include "llvm/IR/IRBuilder.h"
- #include "llvm/IR/Instruction.h"
- #include "llvm/IR/Instructions.h"
- #include "llvm/IR/IntrinsicInst.h"
- #include "llvm/IR/Intrinsics.h"
- #include "llvm/IR/IntrinsicsAArch64.h"
- #include "llvm/IR/Module.h"
- #include "llvm/IR/OperandTraits.h"
- #include "llvm/IR/PatternMatch.h"
- #include "llvm/IR/Type.h"
- #include "llvm/IR/Use.h"
- #include "llvm/IR/Value.h"
- #include "llvm/MC/MCRegisterInfo.h"
- #include "llvm/Support/Casting.h"
- #include "llvm/Support/CodeGen.h"
- #include "llvm/Support/CommandLine.h"
- #include "llvm/Support/Compiler.h"
- #include "llvm/Support/Debug.h"
- #include "llvm/Support/ErrorHandling.h"
- #include "llvm/Support/KnownBits.h"
- #include "llvm/Support/MachineValueType.h"
- #include "llvm/Support/MathExtras.h"
- #include "llvm/Support/raw_ostream.h"
- #include "llvm/Target/TargetMachine.h"
- #include "llvm/Target/TargetOptions.h"
- #include <algorithm>
- #include <bitset>
- #include <cassert>
- #include <cctype>
- #include <cstdint>
- #include <cstdlib>
- #include <iterator>
- #include <limits>
- #include <tuple>
- #include <utility>
- #include <vector>
- using namespace llvm;
- using namespace llvm::PatternMatch;
- #define DEBUG_TYPE "aarch64-lower"
- STATISTIC(NumTailCalls, "Number of tail calls");
- STATISTIC(NumShiftInserts, "Number of vector shift inserts");
- STATISTIC(NumOptimizedImms, "Number of times immediates were optimized");
- cl::opt<bool> EnableAArch64ELFLocalDynamicTLSGeneration(
- "aarch64-elf-ldtls-generation", cl::Hidden,
- cl::desc("Allow AArch64 Local Dynamic TLS code generation"),
- cl::init(false));
- static cl::opt<bool>
- EnableOptimizeLogicalImm("aarch64-enable-logical-imm", cl::Hidden,
- cl::desc("Enable AArch64 logical imm instruction "
- "optimization"),
- cl::init(true));
- static cl::opt<bool>
- EnableCombineMGatherIntrinsics("aarch64-enable-mgather-combine", cl::Hidden,
- cl::desc("Combine extends of AArch64 masked "
- "gather intrinsics"),
- cl::init(true));
- static const MVT MVT_CC = MVT::i32;
- static inline EVT getPackedSVEVectorVT(EVT VT) {
- switch (VT.getSimpleVT().SimpleTy) {
- default:
- llvm_unreachable("unexpected element type for vector");
- case MVT::i8:
- return MVT::nxv16i8;
- case MVT::i16:
- return MVT::nxv8i16;
- case MVT::i32:
- return MVT::nxv4i32;
- case MVT::i64:
- return MVT::nxv2i64;
- case MVT::f16:
- return MVT::nxv8f16;
- case MVT::f32:
- return MVT::nxv4f32;
- case MVT::f64:
- return MVT::nxv2f64;
- case MVT::bf16:
- return MVT::nxv8bf16;
- }
- }
- static inline EVT getPackedSVEVectorVT(ElementCount EC) {
- switch (EC.getKnownMinValue()) {
- default:
- llvm_unreachable("unexpected element count for vector");
- case 16:
- return MVT::nxv16i8;
- case 8:
- return MVT::nxv8i16;
- case 4:
- return MVT::nxv4i32;
- case 2:
- return MVT::nxv2i64;
- }
- }
- static inline EVT getPromotedVTForPredicate(EVT VT) {
- assert(VT.isScalableVector() && (VT.getVectorElementType() == MVT::i1) &&
- "Expected scalable predicate vector type!");
- switch (VT.getVectorMinNumElements()) {
- default:
- llvm_unreachable("unexpected element count for vector");
- case 2:
- return MVT::nxv2i64;
- case 4:
- return MVT::nxv4i32;
- case 8:
- return MVT::nxv8i16;
- case 16:
- return MVT::nxv16i8;
- }
- }
- static inline bool isPackedVectorType(EVT VT, SelectionDAG &DAG) {
- assert(VT.isVector() && DAG.getTargetLoweringInfo().isTypeLegal(VT) &&
- "Expected legal vector type!");
- return VT.isFixedLengthVector() ||
- VT.getSizeInBits().getKnownMinSize() == AArch64::SVEBitsPerBlock;
- }
- static bool isMergePassthruOpcode(unsigned Opc) {
- switch (Opc) {
- default:
- return false;
- case AArch64ISD::BITREVERSE_MERGE_PASSTHRU:
- case AArch64ISD::BSWAP_MERGE_PASSTHRU:
- case AArch64ISD::CTLZ_MERGE_PASSTHRU:
- case AArch64ISD::CTPOP_MERGE_PASSTHRU:
- case AArch64ISD::DUP_MERGE_PASSTHRU:
- case AArch64ISD::ABS_MERGE_PASSTHRU:
- case AArch64ISD::NEG_MERGE_PASSTHRU:
- case AArch64ISD::FNEG_MERGE_PASSTHRU:
- case AArch64ISD::SIGN_EXTEND_INREG_MERGE_PASSTHRU:
- case AArch64ISD::ZERO_EXTEND_INREG_MERGE_PASSTHRU:
- case AArch64ISD::FCEIL_MERGE_PASSTHRU:
- case AArch64ISD::FFLOOR_MERGE_PASSTHRU:
- case AArch64ISD::FNEARBYINT_MERGE_PASSTHRU:
- case AArch64ISD::FRINT_MERGE_PASSTHRU:
- case AArch64ISD::FROUND_MERGE_PASSTHRU:
- case AArch64ISD::FROUNDEVEN_MERGE_PASSTHRU:
- case AArch64ISD::FTRUNC_MERGE_PASSTHRU:
- case AArch64ISD::FP_ROUND_MERGE_PASSTHRU:
- case AArch64ISD::FP_EXTEND_MERGE_PASSTHRU:
- case AArch64ISD::SINT_TO_FP_MERGE_PASSTHRU:
- case AArch64ISD::UINT_TO_FP_MERGE_PASSTHRU:
- case AArch64ISD::FCVTZU_MERGE_PASSTHRU:
- case AArch64ISD::FCVTZS_MERGE_PASSTHRU:
- case AArch64ISD::FSQRT_MERGE_PASSTHRU:
- case AArch64ISD::FRECPX_MERGE_PASSTHRU:
- case AArch64ISD::FABS_MERGE_PASSTHRU:
- return true;
- }
- }
- AArch64TargetLowering::AArch64TargetLowering(const TargetMachine &TM,
- const AArch64Subtarget &STI)
- : TargetLowering(TM), Subtarget(&STI) {
-
-
- setBooleanContents(ZeroOrOneBooleanContent);
-
-
- setBooleanVectorContents(ZeroOrNegativeOneBooleanContent);
-
- addRegisterClass(MVT::i32, &AArch64::GPR32allRegClass);
- addRegisterClass(MVT::i64, &AArch64::GPR64allRegClass);
- if (Subtarget->hasFPARMv8()) {
- addRegisterClass(MVT::f16, &AArch64::FPR16RegClass);
- addRegisterClass(MVT::bf16, &AArch64::FPR16RegClass);
- addRegisterClass(MVT::f32, &AArch64::FPR32RegClass);
- addRegisterClass(MVT::f64, &AArch64::FPR64RegClass);
- addRegisterClass(MVT::f128, &AArch64::FPR128RegClass);
- }
- if (Subtarget->hasNEON()) {
- addRegisterClass(MVT::v16i8, &AArch64::FPR8RegClass);
- addRegisterClass(MVT::v8i16, &AArch64::FPR16RegClass);
-
- addDRTypeForNEON(MVT::v2f32);
- addDRTypeForNEON(MVT::v8i8);
- addDRTypeForNEON(MVT::v4i16);
- addDRTypeForNEON(MVT::v2i32);
- addDRTypeForNEON(MVT::v1i64);
- addDRTypeForNEON(MVT::v1f64);
- addDRTypeForNEON(MVT::v4f16);
- if (Subtarget->hasBF16())
- addDRTypeForNEON(MVT::v4bf16);
- addQRTypeForNEON(MVT::v4f32);
- addQRTypeForNEON(MVT::v2f64);
- addQRTypeForNEON(MVT::v16i8);
- addQRTypeForNEON(MVT::v8i16);
- addQRTypeForNEON(MVT::v4i32);
- addQRTypeForNEON(MVT::v2i64);
- addQRTypeForNEON(MVT::v8f16);
- if (Subtarget->hasBF16())
- addQRTypeForNEON(MVT::v8bf16);
- }
- if (Subtarget->hasSVE()) {
-
- addRegisterClass(MVT::nxv2i1, &AArch64::PPRRegClass);
- addRegisterClass(MVT::nxv4i1, &AArch64::PPRRegClass);
- addRegisterClass(MVT::nxv8i1, &AArch64::PPRRegClass);
- addRegisterClass(MVT::nxv16i1, &AArch64::PPRRegClass);
-
- addRegisterClass(MVT::nxv16i8, &AArch64::ZPRRegClass);
- addRegisterClass(MVT::nxv8i16, &AArch64::ZPRRegClass);
- addRegisterClass(MVT::nxv4i32, &AArch64::ZPRRegClass);
- addRegisterClass(MVT::nxv2i64, &AArch64::ZPRRegClass);
- addRegisterClass(MVT::nxv2f16, &AArch64::ZPRRegClass);
- addRegisterClass(MVT::nxv4f16, &AArch64::ZPRRegClass);
- addRegisterClass(MVT::nxv8f16, &AArch64::ZPRRegClass);
- addRegisterClass(MVT::nxv2f32, &AArch64::ZPRRegClass);
- addRegisterClass(MVT::nxv4f32, &AArch64::ZPRRegClass);
- addRegisterClass(MVT::nxv2f64, &AArch64::ZPRRegClass);
- if (Subtarget->hasBF16()) {
- addRegisterClass(MVT::nxv2bf16, &AArch64::ZPRRegClass);
- addRegisterClass(MVT::nxv4bf16, &AArch64::ZPRRegClass);
- addRegisterClass(MVT::nxv8bf16, &AArch64::ZPRRegClass);
- }
- if (Subtarget->useSVEForFixedLengthVectors()) {
- for (MVT VT : MVT::integer_fixedlen_vector_valuetypes())
- if (useSVEForFixedLengthVectorVT(VT))
- addRegisterClass(VT, &AArch64::ZPRRegClass);
- for (MVT VT : MVT::fp_fixedlen_vector_valuetypes())
- if (useSVEForFixedLengthVectorVT(VT))
- addRegisterClass(VT, &AArch64::ZPRRegClass);
- }
- for (auto VT : { MVT::nxv16i8, MVT::nxv8i16, MVT::nxv4i32, MVT::nxv2i64 }) {
- setOperationAction(ISD::SADDSAT, VT, Legal);
- setOperationAction(ISD::UADDSAT, VT, Legal);
- setOperationAction(ISD::SSUBSAT, VT, Legal);
- setOperationAction(ISD::USUBSAT, VT, Legal);
- setOperationAction(ISD::UREM, VT, Expand);
- setOperationAction(ISD::SREM, VT, Expand);
- setOperationAction(ISD::SDIVREM, VT, Expand);
- setOperationAction(ISD::UDIVREM, VT, Expand);
- }
- for (auto VT :
- { MVT::nxv2i8, MVT::nxv2i16, MVT::nxv2i32, MVT::nxv2i64, MVT::nxv4i8,
- MVT::nxv4i16, MVT::nxv4i32, MVT::nxv8i8, MVT::nxv8i16 })
- setOperationAction(ISD::SIGN_EXTEND_INREG, VT, Legal);
- for (auto VT :
- { MVT::nxv2f16, MVT::nxv4f16, MVT::nxv8f16, MVT::nxv2f32, MVT::nxv4f32,
- MVT::nxv2f64 }) {
- setCondCodeAction(ISD::SETO, VT, Expand);
- setCondCodeAction(ISD::SETOLT, VT, Expand);
- setCondCodeAction(ISD::SETLT, VT, Expand);
- setCondCodeAction(ISD::SETOLE, VT, Expand);
- setCondCodeAction(ISD::SETLE, VT, Expand);
- setCondCodeAction(ISD::SETULT, VT, Expand);
- setCondCodeAction(ISD::SETULE, VT, Expand);
- setCondCodeAction(ISD::SETUGE, VT, Expand);
- setCondCodeAction(ISD::SETUGT, VT, Expand);
- setCondCodeAction(ISD::SETUEQ, VT, Expand);
- setCondCodeAction(ISD::SETUNE, VT, Expand);
- }
- }
-
- computeRegisterProperties(Subtarget->getRegisterInfo());
-
- setOperationAction(ISD::GlobalAddress, MVT::i64, Custom);
- setOperationAction(ISD::GlobalTLSAddress, MVT::i64, Custom);
- setOperationAction(ISD::SETCC, MVT::i32, Custom);
- setOperationAction(ISD::SETCC, MVT::i64, Custom);
- setOperationAction(ISD::SETCC, MVT::f16, Custom);
- setOperationAction(ISD::SETCC, MVT::f32, Custom);
- setOperationAction(ISD::SETCC, MVT::f64, Custom);
- setOperationAction(ISD::STRICT_FSETCC, MVT::f16, Custom);
- setOperationAction(ISD::STRICT_FSETCC, MVT::f32, Custom);
- setOperationAction(ISD::STRICT_FSETCC, MVT::f64, Custom);
- setOperationAction(ISD::STRICT_FSETCCS, MVT::f16, Custom);
- setOperationAction(ISD::STRICT_FSETCCS, MVT::f32, Custom);
- setOperationAction(ISD::STRICT_FSETCCS, MVT::f64, Custom);
- setOperationAction(ISD::BITREVERSE, MVT::i32, Legal);
- setOperationAction(ISD::BITREVERSE, MVT::i64, Legal);
- setOperationAction(ISD::BRCOND, MVT::Other, Expand);
- setOperationAction(ISD::BR_CC, MVT::i32, Custom);
- setOperationAction(ISD::BR_CC, MVT::i64, Custom);
- setOperationAction(ISD::BR_CC, MVT::f16, Custom);
- setOperationAction(ISD::BR_CC, MVT::f32, Custom);
- setOperationAction(ISD::BR_CC, MVT::f64, Custom);
- setOperationAction(ISD::SELECT, MVT::i32, Custom);
- setOperationAction(ISD::SELECT, MVT::i64, Custom);
- setOperationAction(ISD::SELECT, MVT::f16, Custom);
- setOperationAction(ISD::SELECT, MVT::f32, Custom);
- setOperationAction(ISD::SELECT, MVT::f64, Custom);
- setOperationAction(ISD::SELECT_CC, MVT::i32, Custom);
- setOperationAction(ISD::SELECT_CC, MVT::i64, Custom);
- setOperationAction(ISD::SELECT_CC, MVT::f16, Custom);
- setOperationAction(ISD::SELECT_CC, MVT::f32, Custom);
- setOperationAction(ISD::SELECT_CC, MVT::f64, Custom);
- setOperationAction(ISD::BR_JT, MVT::Other, Custom);
- setOperationAction(ISD::JumpTable, MVT::i64, Custom);
- setOperationAction(ISD::SHL_PARTS, MVT::i64, Custom);
- setOperationAction(ISD::SRA_PARTS, MVT::i64, Custom);
- setOperationAction(ISD::SRL_PARTS, MVT::i64, Custom);
- setOperationAction(ISD::FREM, MVT::f32, Expand);
- setOperationAction(ISD::FREM, MVT::f64, Expand);
- setOperationAction(ISD::FREM, MVT::f80, Expand);
- setOperationAction(ISD::BUILD_PAIR, MVT::i64, Expand);
-
-
- setOperationAction(ISD::XOR, MVT::i32, Custom);
- setOperationAction(ISD::XOR, MVT::i64, Custom);
-
-
- setOperationAction(ISD::FABS, MVT::f128, Expand);
- setOperationAction(ISD::FADD, MVT::f128, LibCall);
- setOperationAction(ISD::FCOPYSIGN, MVT::f128, Expand);
- setOperationAction(ISD::FCOS, MVT::f128, Expand);
- setOperationAction(ISD::FDIV, MVT::f128, LibCall);
- setOperationAction(ISD::FMA, MVT::f128, Expand);
- setOperationAction(ISD::FMUL, MVT::f128, LibCall);
- setOperationAction(ISD::FNEG, MVT::f128, Expand);
- setOperationAction(ISD::FPOW, MVT::f128, Expand);
- setOperationAction(ISD::FREM, MVT::f128, Expand);
- setOperationAction(ISD::FRINT, MVT::f128, Expand);
- setOperationAction(ISD::FSIN, MVT::f128, Expand);
- setOperationAction(ISD::FSINCOS, MVT::f128, Expand);
- setOperationAction(ISD::FSQRT, MVT::f128, Expand);
- setOperationAction(ISD::FSUB, MVT::f128, LibCall);
- setOperationAction(ISD::FTRUNC, MVT::f128, Expand);
- setOperationAction(ISD::SETCC, MVT::f128, Custom);
- setOperationAction(ISD::STRICT_FSETCC, MVT::f128, Custom);
- setOperationAction(ISD::STRICT_FSETCCS, MVT::f128, Custom);
- setOperationAction(ISD::BR_CC, MVT::f128, Custom);
- setOperationAction(ISD::SELECT, MVT::f128, Custom);
- setOperationAction(ISD::SELECT_CC, MVT::f128, Custom);
- setOperationAction(ISD::FP_EXTEND, MVT::f128, Custom);
-
-
- setOperationAction(ISD::FP_TO_SINT, MVT::i32, Custom);
- setOperationAction(ISD::FP_TO_SINT, MVT::i64, Custom);
- setOperationAction(ISD::FP_TO_SINT, MVT::i128, Custom);
- setOperationAction(ISD::STRICT_FP_TO_SINT, MVT::i32, Custom);
- setOperationAction(ISD::STRICT_FP_TO_SINT, MVT::i64, Custom);
- setOperationAction(ISD::STRICT_FP_TO_SINT, MVT::i128, Custom);
- setOperationAction(ISD::FP_TO_UINT, MVT::i32, Custom);
- setOperationAction(ISD::FP_TO_UINT, MVT::i64, Custom);
- setOperationAction(ISD::FP_TO_UINT, MVT::i128, Custom);
- setOperationAction(ISD::STRICT_FP_TO_UINT, MVT::i32, Custom);
- setOperationAction(ISD::STRICT_FP_TO_UINT, MVT::i64, Custom);
- setOperationAction(ISD::STRICT_FP_TO_UINT, MVT::i128, Custom);
- setOperationAction(ISD::SINT_TO_FP, MVT::i32, Custom);
- setOperationAction(ISD::SINT_TO_FP, MVT::i64, Custom);
- setOperationAction(ISD::SINT_TO_FP, MVT::i128, Custom);
- setOperationAction(ISD::STRICT_SINT_TO_FP, MVT::i32, Custom);
- setOperationAction(ISD::STRICT_SINT_TO_FP, MVT::i64, Custom);
- setOperationAction(ISD::STRICT_SINT_TO_FP, MVT::i128, Custom);
- setOperationAction(ISD::UINT_TO_FP, MVT::i32, Custom);
- setOperationAction(ISD::UINT_TO_FP, MVT::i64, Custom);
- setOperationAction(ISD::UINT_TO_FP, MVT::i128, Custom);
- setOperationAction(ISD::STRICT_UINT_TO_FP, MVT::i32, Custom);
- setOperationAction(ISD::STRICT_UINT_TO_FP, MVT::i64, Custom);
- setOperationAction(ISD::STRICT_UINT_TO_FP, MVT::i128, Custom);
- setOperationAction(ISD::FP_ROUND, MVT::f16, Custom);
- setOperationAction(ISD::FP_ROUND, MVT::f32, Custom);
- setOperationAction(ISD::FP_ROUND, MVT::f64, Custom);
- setOperationAction(ISD::STRICT_FP_ROUND, MVT::f16, Custom);
- setOperationAction(ISD::STRICT_FP_ROUND, MVT::f32, Custom);
- setOperationAction(ISD::STRICT_FP_ROUND, MVT::f64, Custom);
-
- setOperationAction(ISD::VASTART, MVT::Other, Custom);
- setOperationAction(ISD::VAARG, MVT::Other, Custom);
- setOperationAction(ISD::VACOPY, MVT::Other, Custom);
- setOperationAction(ISD::VAEND, MVT::Other, Expand);
-
- setOperationAction(ISD::STACKSAVE, MVT::Other, Expand);
- setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand);
- if (Subtarget->isTargetWindows())
- setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i64, Custom);
- else
- setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i64, Expand);
-
- setOperationAction(ISD::ConstantPool, MVT::i64, Custom);
-
- setOperationAction(ISD::BlockAddress, MVT::i64, Custom);
-
- setOperationAction(ISD::ADDC, MVT::i32, Custom);
- setOperationAction(ISD::ADDE, MVT::i32, Custom);
- setOperationAction(ISD::SUBC, MVT::i32, Custom);
- setOperationAction(ISD::SUBE, MVT::i32, Custom);
- setOperationAction(ISD::ADDC, MVT::i64, Custom);
- setOperationAction(ISD::ADDE, MVT::i64, Custom);
- setOperationAction(ISD::SUBC, MVT::i64, Custom);
- setOperationAction(ISD::SUBE, MVT::i64, Custom);
-
- setOperationAction(ISD::ROTL, MVT::i32, Expand);
- setOperationAction(ISD::ROTL, MVT::i64, Expand);
- for (MVT VT : MVT::fixedlen_vector_valuetypes()) {
- setOperationAction(ISD::ROTL, VT, Expand);
- setOperationAction(ISD::ROTR, VT, Expand);
- }
-
- setOperationAction(ISD::MULHU, MVT::i32, Expand);
- setOperationAction(ISD::MULHS, MVT::i32, Expand);
-
- setOperationAction(ISD::UMUL_LOHI, MVT::i64, Expand);
- setOperationAction(ISD::SMUL_LOHI, MVT::i64, Expand);
- setOperationAction(ISD::CTPOP, MVT::i32, Custom);
- setOperationAction(ISD::CTPOP, MVT::i64, Custom);
- setOperationAction(ISD::CTPOP, MVT::i128, Custom);
- setOperationAction(ISD::ABS, MVT::i32, Custom);
- setOperationAction(ISD::ABS, MVT::i64, Custom);
- setOperationAction(ISD::SDIVREM, MVT::i32, Expand);
- setOperationAction(ISD::SDIVREM, MVT::i64, Expand);
- for (MVT VT : MVT::fixedlen_vector_valuetypes()) {
- setOperationAction(ISD::SDIVREM, VT, Expand);
- setOperationAction(ISD::UDIVREM, VT, Expand);
- }
- setOperationAction(ISD::SREM, MVT::i32, Expand);
- setOperationAction(ISD::SREM, MVT::i64, Expand);
- setOperationAction(ISD::UDIVREM, MVT::i32, Expand);
- setOperationAction(ISD::UDIVREM, MVT::i64, Expand);
- setOperationAction(ISD::UREM, MVT::i32, Expand);
- setOperationAction(ISD::UREM, MVT::i64, Expand);
-
- setOperationAction(ISD::SADDO, MVT::i32, Custom);
- setOperationAction(ISD::SADDO, MVT::i64, Custom);
- setOperationAction(ISD::UADDO, MVT::i32, Custom);
- setOperationAction(ISD::UADDO, MVT::i64, Custom);
- setOperationAction(ISD::SSUBO, MVT::i32, Custom);
- setOperationAction(ISD::SSUBO, MVT::i64, Custom);
- setOperationAction(ISD::USUBO, MVT::i32, Custom);
- setOperationAction(ISD::USUBO, MVT::i64, Custom);
- setOperationAction(ISD::SMULO, MVT::i32, Custom);
- setOperationAction(ISD::SMULO, MVT::i64, Custom);
- setOperationAction(ISD::UMULO, MVT::i32, Custom);
- setOperationAction(ISD::UMULO, MVT::i64, Custom);
- setOperationAction(ISD::FSIN, MVT::f32, Expand);
- setOperationAction(ISD::FSIN, MVT::f64, Expand);
- setOperationAction(ISD::FCOS, MVT::f32, Expand);
- setOperationAction(ISD::FCOS, MVT::f64, Expand);
- setOperationAction(ISD::FPOW, MVT::f32, Expand);
- setOperationAction(ISD::FPOW, MVT::f64, Expand);
- setOperationAction(ISD::FCOPYSIGN, MVT::f64, Custom);
- setOperationAction(ISD::FCOPYSIGN, MVT::f32, Custom);
- if (Subtarget->hasFullFP16())
- setOperationAction(ISD::FCOPYSIGN, MVT::f16, Custom);
- else
- setOperationAction(ISD::FCOPYSIGN, MVT::f16, Promote);
- setOperationAction(ISD::FREM, MVT::f16, Promote);
- setOperationAction(ISD::FREM, MVT::v4f16, Expand);
- setOperationAction(ISD::FREM, MVT::v8f16, Expand);
- setOperationAction(ISD::FPOW, MVT::f16, Promote);
- setOperationAction(ISD::FPOW, MVT::v4f16, Expand);
- setOperationAction(ISD::FPOW, MVT::v8f16, Expand);
- setOperationAction(ISD::FPOWI, MVT::f16, Promote);
- setOperationAction(ISD::FPOWI, MVT::v4f16, Expand);
- setOperationAction(ISD::FPOWI, MVT::v8f16, Expand);
- setOperationAction(ISD::FCOS, MVT::f16, Promote);
- setOperationAction(ISD::FCOS, MVT::v4f16, Expand);
- setOperationAction(ISD::FCOS, MVT::v8f16, Expand);
- setOperationAction(ISD::FSIN, MVT::f16, Promote);
- setOperationAction(ISD::FSIN, MVT::v4f16, Expand);
- setOperationAction(ISD::FSIN, MVT::v8f16, Expand);
- setOperationAction(ISD::FSINCOS, MVT::f16, Promote);
- setOperationAction(ISD::FSINCOS, MVT::v4f16, Expand);
- setOperationAction(ISD::FSINCOS, MVT::v8f16, Expand);
- setOperationAction(ISD::FEXP, MVT::f16, Promote);
- setOperationAction(ISD::FEXP, MVT::v4f16, Expand);
- setOperationAction(ISD::FEXP, MVT::v8f16, Expand);
- setOperationAction(ISD::FEXP2, MVT::f16, Promote);
- setOperationAction(ISD::FEXP2, MVT::v4f16, Expand);
- setOperationAction(ISD::FEXP2, MVT::v8f16, Expand);
- setOperationAction(ISD::FLOG, MVT::f16, Promote);
- setOperationAction(ISD::FLOG, MVT::v4f16, Expand);
- setOperationAction(ISD::FLOG, MVT::v8f16, Expand);
- setOperationAction(ISD::FLOG2, MVT::f16, Promote);
- setOperationAction(ISD::FLOG2, MVT::v4f16, Expand);
- setOperationAction(ISD::FLOG2, MVT::v8f16, Expand);
- setOperationAction(ISD::FLOG10, MVT::f16, Promote);
- setOperationAction(ISD::FLOG10, MVT::v4f16, Expand);
- setOperationAction(ISD::FLOG10, MVT::v8f16, Expand);
- if (!Subtarget->hasFullFP16()) {
- setOperationAction(ISD::SELECT, MVT::f16, Promote);
- setOperationAction(ISD::SELECT_CC, MVT::f16, Promote);
- setOperationAction(ISD::SETCC, MVT::f16, Promote);
- setOperationAction(ISD::BR_CC, MVT::f16, Promote);
- setOperationAction(ISD::FADD, MVT::f16, Promote);
- setOperationAction(ISD::FSUB, MVT::f16, Promote);
- setOperationAction(ISD::FMUL, MVT::f16, Promote);
- setOperationAction(ISD::FDIV, MVT::f16, Promote);
- setOperationAction(ISD::FMA, MVT::f16, Promote);
- setOperationAction(ISD::FNEG, MVT::f16, Promote);
- setOperationAction(ISD::FABS, MVT::f16, Promote);
- setOperationAction(ISD::FCEIL, MVT::f16, Promote);
- setOperationAction(ISD::FSQRT, MVT::f16, Promote);
- setOperationAction(ISD::FFLOOR, MVT::f16, Promote);
- setOperationAction(ISD::FNEARBYINT, MVT::f16, Promote);
- setOperationAction(ISD::FRINT, MVT::f16, Promote);
- setOperationAction(ISD::FROUND, MVT::f16, Promote);
- setOperationAction(ISD::FTRUNC, MVT::f16, Promote);
- setOperationAction(ISD::FMINNUM, MVT::f16, Promote);
- setOperationAction(ISD::FMAXNUM, MVT::f16, Promote);
- setOperationAction(ISD::FMINIMUM, MVT::f16, Promote);
- setOperationAction(ISD::FMAXIMUM, MVT::f16, Promote);
-
- setOperationAction(ISD::FADD, MVT::v4f16, Promote);
- setOperationAction(ISD::FSUB, MVT::v4f16, Promote);
- setOperationAction(ISD::FMUL, MVT::v4f16, Promote);
- setOperationAction(ISD::FDIV, MVT::v4f16, Promote);
- AddPromotedToType(ISD::FADD, MVT::v4f16, MVT::v4f32);
- AddPromotedToType(ISD::FSUB, MVT::v4f16, MVT::v4f32);
- AddPromotedToType(ISD::FMUL, MVT::v4f16, MVT::v4f32);
- AddPromotedToType(ISD::FDIV, MVT::v4f16, MVT::v4f32);
- setOperationAction(ISD::FABS, MVT::v4f16, Expand);
- setOperationAction(ISD::FNEG, MVT::v4f16, Expand);
- setOperationAction(ISD::FROUND, MVT::v4f16, Expand);
- setOperationAction(ISD::FMA, MVT::v4f16, Expand);
- setOperationAction(ISD::SETCC, MVT::v4f16, Expand);
- setOperationAction(ISD::BR_CC, MVT::v4f16, Expand);
- setOperationAction(ISD::SELECT, MVT::v4f16, Expand);
- setOperationAction(ISD::SELECT_CC, MVT::v4f16, Expand);
- setOperationAction(ISD::FTRUNC, MVT::v4f16, Expand);
- setOperationAction(ISD::FCOPYSIGN, MVT::v4f16, Expand);
- setOperationAction(ISD::FFLOOR, MVT::v4f16, Expand);
- setOperationAction(ISD::FCEIL, MVT::v4f16, Expand);
- setOperationAction(ISD::FRINT, MVT::v4f16, Expand);
- setOperationAction(ISD::FNEARBYINT, MVT::v4f16, Expand);
- setOperationAction(ISD::FSQRT, MVT::v4f16, Expand);
- setOperationAction(ISD::FABS, MVT::v8f16, Expand);
- setOperationAction(ISD::FADD, MVT::v8f16, Expand);
- setOperationAction(ISD::FCEIL, MVT::v8f16, Expand);
- setOperationAction(ISD::FCOPYSIGN, MVT::v8f16, Expand);
- setOperationAction(ISD::FDIV, MVT::v8f16, Expand);
- setOperationAction(ISD::FFLOOR, MVT::v8f16, Expand);
- setOperationAction(ISD::FMA, MVT::v8f16, Expand);
- setOperationAction(ISD::FMUL, MVT::v8f16, Expand);
- setOperationAction(ISD::FNEARBYINT, MVT::v8f16, Expand);
- setOperationAction(ISD::FNEG, MVT::v8f16, Expand);
- setOperationAction(ISD::FROUND, MVT::v8f16, Expand);
- setOperationAction(ISD::FRINT, MVT::v8f16, Expand);
- setOperationAction(ISD::FSQRT, MVT::v8f16, Expand);
- setOperationAction(ISD::FSUB, MVT::v8f16, Expand);
- setOperationAction(ISD::FTRUNC, MVT::v8f16, Expand);
- setOperationAction(ISD::SETCC, MVT::v8f16, Expand);
- setOperationAction(ISD::BR_CC, MVT::v8f16, Expand);
- setOperationAction(ISD::SELECT, MVT::v8f16, Expand);
- setOperationAction(ISD::SELECT_CC, MVT::v8f16, Expand);
- setOperationAction(ISD::FP_EXTEND, MVT::v8f16, Expand);
- }
-
- for (MVT Ty : {MVT::f32, MVT::f64}) {
- setOperationAction(ISD::FFLOOR, Ty, Legal);
- setOperationAction(ISD::FNEARBYINT, Ty, Legal);
- setOperationAction(ISD::FCEIL, Ty, Legal);
- setOperationAction(ISD::FRINT, Ty, Legal);
- setOperationAction(ISD::FTRUNC, Ty, Legal);
- setOperationAction(ISD::FROUND, Ty, Legal);
- setOperationAction(ISD::FMINNUM, Ty, Legal);
- setOperationAction(ISD::FMAXNUM, Ty, Legal);
- setOperationAction(ISD::FMINIMUM, Ty, Legal);
- setOperationAction(ISD::FMAXIMUM, Ty, Legal);
- setOperationAction(ISD::LROUND, Ty, Legal);
- setOperationAction(ISD::LLROUND, Ty, Legal);
- setOperationAction(ISD::LRINT, Ty, Legal);
- setOperationAction(ISD::LLRINT, Ty, Legal);
- }
- if (Subtarget->hasFullFP16()) {
- setOperationAction(ISD::FNEARBYINT, MVT::f16, Legal);
- setOperationAction(ISD::FFLOOR, MVT::f16, Legal);
- setOperationAction(ISD::FCEIL, MVT::f16, Legal);
- setOperationAction(ISD::FRINT, MVT::f16, Legal);
- setOperationAction(ISD::FTRUNC, MVT::f16, Legal);
- setOperationAction(ISD::FROUND, MVT::f16, Legal);
- setOperationAction(ISD::FMINNUM, MVT::f16, Legal);
- setOperationAction(ISD::FMAXNUM, MVT::f16, Legal);
- setOperationAction(ISD::FMINIMUM, MVT::f16, Legal);
- setOperationAction(ISD::FMAXIMUM, MVT::f16, Legal);
- }
- setOperationAction(ISD::PREFETCH, MVT::Other, Custom);
- setOperationAction(ISD::FLT_ROUNDS_, MVT::i32, Custom);
- setOperationAction(ISD::ATOMIC_CMP_SWAP, MVT::i128, Custom);
- setOperationAction(ISD::ATOMIC_LOAD_SUB, MVT::i32, Custom);
- setOperationAction(ISD::ATOMIC_LOAD_SUB, MVT::i64, Custom);
- setOperationAction(ISD::ATOMIC_LOAD_AND, MVT::i32, Custom);
- setOperationAction(ISD::ATOMIC_LOAD_AND, MVT::i64, Custom);
-
-
- if (Subtarget->outlineAtomics() && !Subtarget->hasLSE()) {
- setOperationAction(ISD::ATOMIC_CMP_SWAP, MVT::i8, LibCall);
- setOperationAction(ISD::ATOMIC_CMP_SWAP, MVT::i16, LibCall);
- setOperationAction(ISD::ATOMIC_CMP_SWAP, MVT::i32, LibCall);
- setOperationAction(ISD::ATOMIC_CMP_SWAP, MVT::i64, LibCall);
- setOperationAction(ISD::ATOMIC_CMP_SWAP, MVT::i128, LibCall);
- setOperationAction(ISD::ATOMIC_SWAP, MVT::i8, LibCall);
- setOperationAction(ISD::ATOMIC_SWAP, MVT::i16, LibCall);
- setOperationAction(ISD::ATOMIC_SWAP, MVT::i32, LibCall);
- setOperationAction(ISD::ATOMIC_SWAP, MVT::i64, LibCall);
- setOperationAction(ISD::ATOMIC_LOAD_ADD, MVT::i8, LibCall);
- setOperationAction(ISD::ATOMIC_LOAD_ADD, MVT::i16, LibCall);
- setOperationAction(ISD::ATOMIC_LOAD_ADD, MVT::i32, LibCall);
- setOperationAction(ISD::ATOMIC_LOAD_ADD, MVT::i64, LibCall);
- setOperationAction(ISD::ATOMIC_LOAD_OR, MVT::i8, LibCall);
- setOperationAction(ISD::ATOMIC_LOAD_OR, MVT::i16, LibCall);
- setOperationAction(ISD::ATOMIC_LOAD_OR, MVT::i32, LibCall);
- setOperationAction(ISD::ATOMIC_LOAD_OR, MVT::i64, LibCall);
- setOperationAction(ISD::ATOMIC_LOAD_CLR, MVT::i8, LibCall);
- setOperationAction(ISD::ATOMIC_LOAD_CLR, MVT::i16, LibCall);
- setOperationAction(ISD::ATOMIC_LOAD_CLR, MVT::i32, LibCall);
- setOperationAction(ISD::ATOMIC_LOAD_CLR, MVT::i64, LibCall);
- setOperationAction(ISD::ATOMIC_LOAD_XOR, MVT::i8, LibCall);
- setOperationAction(ISD::ATOMIC_LOAD_XOR, MVT::i16, LibCall);
- setOperationAction(ISD::ATOMIC_LOAD_XOR, MVT::i32, LibCall);
- setOperationAction(ISD::ATOMIC_LOAD_XOR, MVT::i64, LibCall);
- #define LCALLNAMES(A, B, N) \
- setLibcallName(A##N##_RELAX, #B #N "_relax"); \
- setLibcallName(A##N##_ACQ, #B #N "_acq"); \
- setLibcallName(A##N##_REL, #B #N "_rel"); \
- setLibcallName(A##N##_ACQ_REL, #B #N "_acq_rel");
- #define LCALLNAME4(A, B) \
- LCALLNAMES(A, B, 1) \
- LCALLNAMES(A, B, 2) LCALLNAMES(A, B, 4) LCALLNAMES(A, B, 8)
- #define LCALLNAME5(A, B) \
- LCALLNAMES(A, B, 1) \
- LCALLNAMES(A, B, 2) \
- LCALLNAMES(A, B, 4) LCALLNAMES(A, B, 8) LCALLNAMES(A, B, 16)
- LCALLNAME5(RTLIB::OUTLINE_ATOMIC_CAS, __aarch64_cas)
- LCALLNAME4(RTLIB::OUTLINE_ATOMIC_SWP, __aarch64_swp)
- LCALLNAME4(RTLIB::OUTLINE_ATOMIC_LDADD, __aarch64_ldadd)
- LCALLNAME4(RTLIB::OUTLINE_ATOMIC_LDSET, __aarch64_ldset)
- LCALLNAME4(RTLIB::OUTLINE_ATOMIC_LDCLR, __aarch64_ldclr)
- LCALLNAME4(RTLIB::OUTLINE_ATOMIC_LDEOR, __aarch64_ldeor)
- #undef LCALLNAMES
- #undef LCALLNAME4
- #undef LCALLNAME5
- }
-
- setOperationAction(ISD::LOAD, MVT::i128, Custom);
- setOperationAction(ISD::STORE, MVT::i128, Custom);
-
-
-
- setOperationAction(ISD::STORE, MVT::v32i8, Custom);
- setOperationAction(ISD::STORE, MVT::v16i16, Custom);
- setOperationAction(ISD::STORE, MVT::v16f16, Custom);
- setOperationAction(ISD::STORE, MVT::v8i32, Custom);
- setOperationAction(ISD::STORE, MVT::v8f32, Custom);
- setOperationAction(ISD::STORE, MVT::v4f64, Custom);
- setOperationAction(ISD::STORE, MVT::v4i64, Custom);
-
-
- if (Subtarget->hasPerfMon())
- setOperationAction(ISD::READCYCLECOUNTER, MVT::i64, Legal);
- if (getLibcallName(RTLIB::SINCOS_STRET_F32) != nullptr &&
- getLibcallName(RTLIB::SINCOS_STRET_F64) != nullptr) {
-
- setOperationAction(ISD::FSINCOS, MVT::f64, Custom);
- setOperationAction(ISD::FSINCOS, MVT::f32, Custom);
- } else {
- setOperationAction(ISD::FSINCOS, MVT::f64, Expand);
- setOperationAction(ISD::FSINCOS, MVT::f32, Expand);
- }
- if (Subtarget->getTargetTriple().isOSMSVCRT()) {
-
- setLibcallName(RTLIB::POWI_F32, nullptr);
- setLibcallName(RTLIB::POWI_F64, nullptr);
- }
-
-
- if (Subtarget->isTargetMachO() && TM.getCodeModel() == CodeModel::Large) {
- setOperationAction(ISD::ConstantFP, MVT::f32, Legal);
- setOperationAction(ISD::ConstantFP, MVT::f64, Legal);
- }
-
-
- for (MVT VT : MVT::fp_valuetypes()) {
- setLoadExtAction(ISD::EXTLOAD, VT, MVT::f16, Expand);
- setLoadExtAction(ISD::EXTLOAD, VT, MVT::f32, Expand);
- setLoadExtAction(ISD::EXTLOAD, VT, MVT::f64, Expand);
- setLoadExtAction(ISD::EXTLOAD, VT, MVT::f80, Expand);
- }
- for (MVT VT : MVT::integer_valuetypes())
- setLoadExtAction(ISD::SEXTLOAD, VT, MVT::i1, Expand);
- setTruncStoreAction(MVT::f32, MVT::f16, Expand);
- setTruncStoreAction(MVT::f64, MVT::f32, Expand);
- setTruncStoreAction(MVT::f64, MVT::f16, Expand);
- setTruncStoreAction(MVT::f128, MVT::f80, Expand);
- setTruncStoreAction(MVT::f128, MVT::f64, Expand);
- setTruncStoreAction(MVT::f128, MVT::f32, Expand);
- setTruncStoreAction(MVT::f128, MVT::f16, Expand);
- setOperationAction(ISD::BITCAST, MVT::i16, Custom);
- setOperationAction(ISD::BITCAST, MVT::f16, Custom);
- setOperationAction(ISD::BITCAST, MVT::bf16, Custom);
-
- for (unsigned im = (unsigned)ISD::PRE_INC;
- im != (unsigned)ISD::LAST_INDEXED_MODE; ++im) {
- setIndexedLoadAction(im, MVT::i8, Legal);
- setIndexedLoadAction(im, MVT::i16, Legal);
- setIndexedLoadAction(im, MVT::i32, Legal);
- setIndexedLoadAction(im, MVT::i64, Legal);
- setIndexedLoadAction(im, MVT::f64, Legal);
- setIndexedLoadAction(im, MVT::f32, Legal);
- setIndexedLoadAction(im, MVT::f16, Legal);
- setIndexedLoadAction(im, MVT::bf16, Legal);
- setIndexedStoreAction(im, MVT::i8, Legal);
- setIndexedStoreAction(im, MVT::i16, Legal);
- setIndexedStoreAction(im, MVT::i32, Legal);
- setIndexedStoreAction(im, MVT::i64, Legal);
- setIndexedStoreAction(im, MVT::f64, Legal);
- setIndexedStoreAction(im, MVT::f32, Legal);
- setIndexedStoreAction(im, MVT::f16, Legal);
- setIndexedStoreAction(im, MVT::bf16, Legal);
- }
-
- setOperationAction(ISD::TRAP, MVT::Other, Legal);
- setOperationAction(ISD::DEBUGTRAP, MVT::Other, Legal);
- setOperationAction(ISD::UBSANTRAP, MVT::Other, Legal);
-
- setTargetDAGCombine(ISD::OR);
-
- setTargetDAGCombine(ISD::AND);
-
-
- setTargetDAGCombine(ISD::ADD);
- setTargetDAGCombine(ISD::ABS);
- setTargetDAGCombine(ISD::SUB);
- setTargetDAGCombine(ISD::SRL);
- setTargetDAGCombine(ISD::XOR);
- setTargetDAGCombine(ISD::SINT_TO_FP);
- setTargetDAGCombine(ISD::UINT_TO_FP);
- setTargetDAGCombine(ISD::FP_TO_SINT);
- setTargetDAGCombine(ISD::FP_TO_UINT);
- setTargetDAGCombine(ISD::FDIV);
- setTargetDAGCombine(ISD::INTRINSIC_WO_CHAIN);
- setTargetDAGCombine(ISD::ANY_EXTEND);
- setTargetDAGCombine(ISD::ZERO_EXTEND);
- setTargetDAGCombine(ISD::SIGN_EXTEND);
- setTargetDAGCombine(ISD::SIGN_EXTEND_INREG);
- setTargetDAGCombine(ISD::TRUNCATE);
- setTargetDAGCombine(ISD::CONCAT_VECTORS);
- setTargetDAGCombine(ISD::STORE);
- if (Subtarget->supportsAddressTopByteIgnored())
- setTargetDAGCombine(ISD::LOAD);
- setTargetDAGCombine(ISD::MGATHER);
- setTargetDAGCombine(ISD::MSCATTER);
- setTargetDAGCombine(ISD::MUL);
- setTargetDAGCombine(ISD::SELECT);
- setTargetDAGCombine(ISD::VSELECT);
- setTargetDAGCombine(ISD::INTRINSIC_VOID);
- setTargetDAGCombine(ISD::INTRINSIC_W_CHAIN);
- setTargetDAGCombine(ISD::INSERT_VECTOR_ELT);
- setTargetDAGCombine(ISD::EXTRACT_VECTOR_ELT);
- setTargetDAGCombine(ISD::VECREDUCE_ADD);
- setTargetDAGCombine(ISD::GlobalAddress);
-
- MaxStoresPerMemsetOptSize = 8;
- MaxStoresPerMemset = Subtarget->requiresStrictAlign()
- ? MaxStoresPerMemsetOptSize : 32;
- MaxGluedStoresPerMemcpy = 4;
- MaxStoresPerMemcpyOptSize = 4;
- MaxStoresPerMemcpy = Subtarget->requiresStrictAlign()
- ? MaxStoresPerMemcpyOptSize : 16;
- MaxStoresPerMemmoveOptSize = MaxStoresPerMemmove = 4;
- MaxLoadsPerMemcmpOptSize = 4;
- MaxLoadsPerMemcmp = Subtarget->requiresStrictAlign()
- ? MaxLoadsPerMemcmpOptSize : 8;
- setStackPointerRegisterToSaveRestore(AArch64::SP);
- setSchedulingPreference(Sched::Hybrid);
- EnableExtLdPromotion = true;
-
- setMinFunctionAlignment(Align(4));
-
- setPrefLoopAlignment(Align(1ULL << STI.getPrefLoopLogAlignment()));
- setPrefFunctionAlignment(Align(1ULL << STI.getPrefFunctionLogAlignment()));
-
-
- unsigned MaxJT = STI.getMaximumJumpTableSize();
- if (MaxJT && getMaximumJumpTableSize() == UINT_MAX)
- setMaximumJumpTableSize(MaxJT);
- setHasExtractBitsInsn(true);
- setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::Other, Custom);
- if (Subtarget->hasNEON()) {
-
-
- setOperationAction(ISD::FABS, MVT::v1f64, Expand);
- setOperationAction(ISD::FADD, MVT::v1f64, Expand);
- setOperationAction(ISD::FCEIL, MVT::v1f64, Expand);
- setOperationAction(ISD::FCOPYSIGN, MVT::v1f64, Expand);
- setOperationAction(ISD::FCOS, MVT::v1f64, Expand);
- setOperationAction(ISD::FDIV, MVT::v1f64, Expand);
- setOperationAction(ISD::FFLOOR, MVT::v1f64, Expand);
- setOperationAction(ISD::FMA, MVT::v1f64, Expand);
- setOperationAction(ISD::FMUL, MVT::v1f64, Expand);
- setOperationAction(ISD::FNEARBYINT, MVT::v1f64, Expand);
- setOperationAction(ISD::FNEG, MVT::v1f64, Expand);
- setOperationAction(ISD::FPOW, MVT::v1f64, Expand);
- setOperationAction(ISD::FREM, MVT::v1f64, Expand);
- setOperationAction(ISD::FROUND, MVT::v1f64, Expand);
- setOperationAction(ISD::FRINT, MVT::v1f64, Expand);
- setOperationAction(ISD::FSIN, MVT::v1f64, Expand);
- setOperationAction(ISD::FSINCOS, MVT::v1f64, Expand);
- setOperationAction(ISD::FSQRT, MVT::v1f64, Expand);
- setOperationAction(ISD::FSUB, MVT::v1f64, Expand);
- setOperationAction(ISD::FTRUNC, MVT::v1f64, Expand);
- setOperationAction(ISD::SETCC, MVT::v1f64, Expand);
- setOperationAction(ISD::BR_CC, MVT::v1f64, Expand);
- setOperationAction(ISD::SELECT, MVT::v1f64, Expand);
- setOperationAction(ISD::SELECT_CC, MVT::v1f64, Expand);
- setOperationAction(ISD::FP_EXTEND, MVT::v1f64, Expand);
- setOperationAction(ISD::FP_TO_SINT, MVT::v1i64, Expand);
- setOperationAction(ISD::FP_TO_UINT, MVT::v1i64, Expand);
- setOperationAction(ISD::SINT_TO_FP, MVT::v1i64, Expand);
- setOperationAction(ISD::UINT_TO_FP, MVT::v1i64, Expand);
- setOperationAction(ISD::FP_ROUND, MVT::v1f64, Expand);
- setOperationAction(ISD::MUL, MVT::v1i64, Expand);
-
-
- setOperationPromotedToType(ISD::UINT_TO_FP, MVT::v4i8, MVT::v4i32);
- setOperationPromotedToType(ISD::SINT_TO_FP, MVT::v4i8, MVT::v4i32);
-
- setOperationPromotedToType(ISD::SINT_TO_FP, MVT::v8i8, MVT::v8i32);
- setOperationPromotedToType(ISD::UINT_TO_FP, MVT::v8i8, MVT::v8i32);
-
- setOperationAction(ISD::SINT_TO_FP, MVT::v2i32, Custom);
- setOperationAction(ISD::UINT_TO_FP, MVT::v2i32, Custom);
- setOperationAction(ISD::SINT_TO_FP, MVT::v2i64, Custom);
- setOperationAction(ISD::UINT_TO_FP, MVT::v2i64, Custom);
-
-
- setOperationAction(ISD::SINT_TO_FP, MVT::v4i32, Custom);
- setOperationAction(ISD::UINT_TO_FP, MVT::v4i32, Custom);
- if (Subtarget->hasFullFP16()) {
- setOperationAction(ISD::SINT_TO_FP, MVT::v4i16, Custom);
- setOperationAction(ISD::UINT_TO_FP, MVT::v4i16, Custom);
- setOperationAction(ISD::SINT_TO_FP, MVT::v8i16, Custom);
- setOperationAction(ISD::UINT_TO_FP, MVT::v8i16, Custom);
- } else {
-
-
- setOperationPromotedToType(ISD::UINT_TO_FP, MVT::v4i16, MVT::v4i32);
- setOperationPromotedToType(ISD::SINT_TO_FP, MVT::v4i16, MVT::v4i32);
- setOperationPromotedToType(ISD::SINT_TO_FP, MVT::v8i16, MVT::v8i32);
- setOperationPromotedToType(ISD::UINT_TO_FP, MVT::v8i16, MVT::v8i32);
- }
- setOperationAction(ISD::CTLZ, MVT::v1i64, Expand);
- setOperationAction(ISD::CTLZ, MVT::v2i64, Expand);
-
- setOperationAction(ISD::MUL, MVT::v2i64, Expand);
-
- setOperationAction(ISD::MUL, MVT::v8i16, Custom);
- setOperationAction(ISD::MUL, MVT::v4i32, Custom);
- setOperationAction(ISD::MUL, MVT::v2i64, Custom);
-
- for (MVT VT : { MVT::v8i8, MVT::v4i16, MVT::v2i32,
- MVT::v16i8, MVT::v8i16, MVT::v4i32, MVT::v2i64 }) {
- setOperationAction(ISD::SADDSAT, VT, Legal);
- setOperationAction(ISD::UADDSAT, VT, Legal);
- setOperationAction(ISD::SSUBSAT, VT, Legal);
- setOperationAction(ISD::USUBSAT, VT, Legal);
- }
-
- for (MVT VT : { MVT::v4f16, MVT::v2f32,
- MVT::v8f16, MVT::v4f32, MVT::v2f64 }) {
- if (VT.getVectorElementType() != MVT::f16 || Subtarget->hasFullFP16()) {
- setOperationAction(ISD::VECREDUCE_FMAX, VT, Custom);
- setOperationAction(ISD::VECREDUCE_FMIN, VT, Custom);
- setOperationAction(ISD::VECREDUCE_FADD, VT, Legal);
- }
- }
- for (MVT VT : { MVT::v8i8, MVT::v4i16, MVT::v2i32,
- MVT::v16i8, MVT::v8i16, MVT::v4i32 }) {
- setOperationAction(ISD::VECREDUCE_ADD, VT, Custom);
- setOperationAction(ISD::VECREDUCE_SMAX, VT, Custom);
- setOperationAction(ISD::VECREDUCE_SMIN, VT, Custom);
- setOperationAction(ISD::VECREDUCE_UMAX, VT, Custom);
- setOperationAction(ISD::VECREDUCE_UMIN, VT, Custom);
- }
- setOperationAction(ISD::VECREDUCE_ADD, MVT::v2i64, Custom);
- setOperationAction(ISD::ANY_EXTEND, MVT::v4i32, Legal);
- setTruncStoreAction(MVT::v2i32, MVT::v2i16, Expand);
-
-
- for (MVT VT : MVT::fixedlen_vector_valuetypes()) {
- setOperationAction(ISD::SIGN_EXTEND_INREG, VT, Expand);
- if (VT == MVT::v16i8 || VT == MVT::v8i16 || VT == MVT::v4i32) {
- setOperationAction(ISD::MULHS, VT, Legal);
- setOperationAction(ISD::MULHU, VT, Legal);
- } else {
- setOperationAction(ISD::MULHS, VT, Expand);
- setOperationAction(ISD::MULHU, VT, Expand);
- }
- setOperationAction(ISD::SMUL_LOHI, VT, Expand);
- setOperationAction(ISD::UMUL_LOHI, VT, Expand);
- setOperationAction(ISD::BSWAP, VT, Expand);
- setOperationAction(ISD::CTTZ, VT, Expand);
- for (MVT InnerVT : MVT::fixedlen_vector_valuetypes()) {
- setTruncStoreAction(VT, InnerVT, Expand);
- setLoadExtAction(ISD::SEXTLOAD, VT, InnerVT, Expand);
- setLoadExtAction(ISD::ZEXTLOAD, VT, InnerVT, Expand);
- setLoadExtAction(ISD::EXTLOAD, VT, InnerVT, Expand);
- }
- }
-
- for (MVT Ty : {MVT::v2f32, MVT::v4f32, MVT::v2f64}) {
- setOperationAction(ISD::FFLOOR, Ty, Legal);
- setOperationAction(ISD::FNEARBYINT, Ty, Legal);
- setOperationAction(ISD::FCEIL, Ty, Legal);
- setOperationAction(ISD::FRINT, Ty, Legal);
- setOperationAction(ISD::FTRUNC, Ty, Legal);
- setOperationAction(ISD::FROUND, Ty, Legal);
- }
- if (Subtarget->hasFullFP16()) {
- for (MVT Ty : {MVT::v4f16, MVT::v8f16}) {
- setOperationAction(ISD::FFLOOR, Ty, Legal);
- setOperationAction(ISD::FNEARBYINT, Ty, Legal);
- setOperationAction(ISD::FCEIL, Ty, Legal);
- setOperationAction(ISD::FRINT, Ty, Legal);
- setOperationAction(ISD::FTRUNC, Ty, Legal);
- setOperationAction(ISD::FROUND, Ty, Legal);
- }
- }
- if (Subtarget->hasSVE())
- setOperationAction(ISD::VSCALE, MVT::i32, Custom);
- setTruncStoreAction(MVT::v4i16, MVT::v4i8, Custom);
- }
- if (Subtarget->hasSVE()) {
-
-
-
- for (auto VT : {MVT::nxv16i8, MVT::nxv8i16, MVT::nxv4i32, MVT::nxv2i64}) {
- setOperationAction(ISD::BITREVERSE, VT, Custom);
- setOperationAction(ISD::BSWAP, VT, Custom);
- setOperationAction(ISD::CTLZ, VT, Custom);
- setOperationAction(ISD::CTPOP, VT, Custom);
- setOperationAction(ISD::CTTZ, VT, Custom);
- setOperationAction(ISD::INSERT_SUBVECTOR, VT, Custom);
- setOperationAction(ISD::UINT_TO_FP, VT, Custom);
- setOperationAction(ISD::SINT_TO_FP, VT, Custom);
- setOperationAction(ISD::FP_TO_UINT, VT, Custom);
- setOperationAction(ISD::FP_TO_SINT, VT, Custom);
- setOperationAction(ISD::MGATHER, VT, Custom);
- setOperationAction(ISD::MSCATTER, VT, Custom);
- setOperationAction(ISD::MUL, VT, Custom);
- setOperationAction(ISD::SPLAT_VECTOR, VT, Custom);
- setOperationAction(ISD::SELECT, VT, Custom);
- setOperationAction(ISD::SDIV, VT, Custom);
- setOperationAction(ISD::UDIV, VT, Custom);
- setOperationAction(ISD::SMIN, VT, Custom);
- setOperationAction(ISD::UMIN, VT, Custom);
- setOperationAction(ISD::SMAX, VT, Custom);
- setOperationAction(ISD::UMAX, VT, Custom);
- setOperationAction(ISD::SHL, VT, Custom);
- setOperationAction(ISD::SRL, VT, Custom);
- setOperationAction(ISD::SRA, VT, Custom);
- setOperationAction(ISD::ABS, VT, Custom);
- setOperationAction(ISD::VECREDUCE_ADD, VT, Custom);
- setOperationAction(ISD::VECREDUCE_AND, VT, Custom);
- setOperationAction(ISD::VECREDUCE_OR, VT, Custom);
- setOperationAction(ISD::VECREDUCE_XOR, VT, Custom);
- setOperationAction(ISD::VECREDUCE_UMIN, VT, Custom);
- setOperationAction(ISD::VECREDUCE_UMAX, VT, Custom);
- setOperationAction(ISD::VECREDUCE_SMIN, VT, Custom);
- setOperationAction(ISD::VECREDUCE_SMAX, VT, Custom);
- }
-
- for (auto VT : {MVT::nxv8i8, MVT::nxv4i16, MVT::nxv2i32}) {
- setOperationAction(ISD::EXTRACT_SUBVECTOR, VT, Custom);
- setOperationAction(ISD::INSERT_SUBVECTOR, VT, Custom);
- }
- for (auto VT : {MVT::nxv16i1, MVT::nxv8i1, MVT::nxv4i1, MVT::nxv2i1}) {
- setOperationAction(ISD::CONCAT_VECTORS, VT, Custom);
- setOperationAction(ISD::SELECT, VT, Custom);
- setOperationAction(ISD::SETCC, VT, Custom);
- setOperationAction(ISD::SPLAT_VECTOR, VT, Custom);
- setOperationAction(ISD::TRUNCATE, VT, Custom);
- setOperationAction(ISD::VECREDUCE_AND, VT, Custom);
- setOperationAction(ISD::VECREDUCE_OR, VT, Custom);
- setOperationAction(ISD::VECREDUCE_XOR, VT, Custom);
-
- if (VT != MVT::nxv16i1) {
- setOperationAction(ISD::SINT_TO_FP, VT, Custom);
- setOperationAction(ISD::UINT_TO_FP, VT, Custom);
- }
- }
- for (auto VT : {MVT::nxv2f16, MVT::nxv4f16, MVT::nxv8f16, MVT::nxv2f32,
- MVT::nxv4f32, MVT::nxv2f64}) {
- setOperationAction(ISD::CONCAT_VECTORS, VT, Custom);
- setOperationAction(ISD::INSERT_SUBVECTOR, VT, Custom);
- setOperationAction(ISD::MGATHER, VT, Custom);
- setOperationAction(ISD::MSCATTER, VT, Custom);
- setOperationAction(ISD::SPLAT_VECTOR, VT, Custom);
- setOperationAction(ISD::SELECT, VT, Custom);
- setOperationAction(ISD::FADD, VT, Custom);
- setOperationAction(ISD::FDIV, VT, Custom);
- setOperationAction(ISD::FMA, VT, Custom);
- setOperationAction(ISD::FMAXNUM, VT, Custom);
- setOperationAction(ISD::FMINNUM, VT, Custom);
- setOperationAction(ISD::FMUL, VT, Custom);
- setOperationAction(ISD::FNEG, VT, Custom);
- setOperationAction(ISD::FSUB, VT, Custom);
- setOperationAction(ISD::FCEIL, VT, Custom);
- setOperationAction(ISD::FFLOOR, VT, Custom);
- setOperationAction(ISD::FNEARBYINT, VT, Custom);
- setOperationAction(ISD::FRINT, VT, Custom);
- setOperationAction(ISD::FROUND, VT, Custom);
- setOperationAction(ISD::FROUNDEVEN, VT, Custom);
- setOperationAction(ISD::FTRUNC, VT, Custom);
- setOperationAction(ISD::FSQRT, VT, Custom);
- setOperationAction(ISD::FABS, VT, Custom);
- setOperationAction(ISD::FP_EXTEND, VT, Custom);
- setOperationAction(ISD::FP_ROUND, VT, Custom);
- setOperationAction(ISD::VECREDUCE_FADD, VT, Custom);
- setOperationAction(ISD::VECREDUCE_FMAX, VT, Custom);
- setOperationAction(ISD::VECREDUCE_FMIN, VT, Custom);
- setOperationAction(ISD::VECREDUCE_SEQ_FADD, VT, Custom);
- }
- for (auto VT : {MVT::nxv2bf16, MVT::nxv4bf16, MVT::nxv8bf16}) {
- setOperationAction(ISD::CONCAT_VECTORS, VT, Custom);
- setOperationAction(ISD::MGATHER, VT, Custom);
- setOperationAction(ISD::MSCATTER, VT, Custom);
- }
- setOperationAction(ISD::SPLAT_VECTOR, MVT::nxv8bf16, Custom);
- setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::i8, Custom);
- setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::i16, Custom);
-
-
- if (Subtarget->useSVEForFixedLengthVectors()) {
- for (MVT VT : MVT::integer_fixedlen_vector_valuetypes())
- if (useSVEForFixedLengthVectorVT(VT))
- addTypeForFixedLengthSVE(VT);
- for (MVT VT : MVT::fp_fixedlen_vector_valuetypes())
- if (useSVEForFixedLengthVectorVT(VT))
- addTypeForFixedLengthSVE(VT);
-
- for (auto VT : {MVT::v8i8, MVT::v4i16})
- setOperationAction(ISD::TRUNCATE, VT, Custom);
- setOperationAction(ISD::FP_ROUND, MVT::v4f16, Custom);
-
- for (auto VT : {MVT::v16i8, MVT::v8i16, MVT::v4i32})
- setOperationAction(ISD::TRUNCATE, VT, Custom);
- for (auto VT : {MVT::v8f16, MVT::v4f32})
- setOperationAction(ISD::FP_ROUND, VT, Expand);
-
- setOperationAction(ISD::BITREVERSE, MVT::v1i64, Custom);
- setOperationAction(ISD::CTLZ, MVT::v1i64, Custom);
- setOperationAction(ISD::CTLZ, MVT::v2i64, Custom);
- setOperationAction(ISD::CTTZ, MVT::v1i64, Custom);
- setOperationAction(ISD::MUL, MVT::v1i64, Custom);
- setOperationAction(ISD::MUL, MVT::v2i64, Custom);
- setOperationAction(ISD::SDIV, MVT::v8i8, Custom);
- setOperationAction(ISD::SDIV, MVT::v16i8, Custom);
- setOperationAction(ISD::SDIV, MVT::v4i16, Custom);
- setOperationAction(ISD::SDIV, MVT::v8i16, Custom);
- setOperationAction(ISD::SDIV, MVT::v2i32, Custom);
- setOperationAction(ISD::SDIV, MVT::v4i32, Custom);
- setOperationAction(ISD::SDIV, MVT::v1i64, Custom);
- setOperationAction(ISD::SDIV, MVT::v2i64, Custom);
- setOperationAction(ISD::SMAX, MVT::v1i64, Custom);
- setOperationAction(ISD::SMAX, MVT::v2i64, Custom);
- setOperationAction(ISD::SMIN, MVT::v1i64, Custom);
- setOperationAction(ISD::SMIN, MVT::v2i64, Custom);
- setOperationAction(ISD::UDIV, MVT::v8i8, Custom);
- setOperationAction(ISD::UDIV, MVT::v16i8, Custom);
- setOperationAction(ISD::UDIV, MVT::v4i16, Custom);
- setOperationAction(ISD::UDIV, MVT::v8i16, Custom);
- setOperationAction(ISD::UDIV, MVT::v2i32, Custom);
- setOperationAction(ISD::UDIV, MVT::v4i32, Custom);
- setOperationAction(ISD::UDIV, MVT::v1i64, Custom);
- setOperationAction(ISD::UDIV, MVT::v2i64, Custom);
- setOperationAction(ISD::UMAX, MVT::v1i64, Custom);
- setOperationAction(ISD::UMAX, MVT::v2i64, Custom);
- setOperationAction(ISD::UMIN, MVT::v1i64, Custom);
- setOperationAction(ISD::UMIN, MVT::v2i64, Custom);
- setOperationAction(ISD::VECREDUCE_SMAX, MVT::v2i64, Custom);
- setOperationAction(ISD::VECREDUCE_SMIN, MVT::v2i64, Custom);
- setOperationAction(ISD::VECREDUCE_UMAX, MVT::v2i64, Custom);
- setOperationAction(ISD::VECREDUCE_UMIN, MVT::v2i64, Custom);
-
- for (auto VT : {MVT::v8i8, MVT::v16i8, MVT::v4i16, MVT::v8i16,
- MVT::v2i32, MVT::v4i32, MVT::v2i64}) {
- setOperationAction(ISD::BITREVERSE, VT, Custom);
- setOperationAction(ISD::CTTZ, VT, Custom);
- setOperationAction(ISD::VECREDUCE_AND, VT, Custom);
- setOperationAction(ISD::VECREDUCE_OR, VT, Custom);
- setOperationAction(ISD::VECREDUCE_XOR, VT, Custom);
- }
-
- for (auto VT : {MVT::v4f16, MVT::v8f16, MVT::v2f32, MVT::v4f32,
- MVT::v1f64, MVT::v2f64})
- setOperationAction(ISD::VECREDUCE_SEQ_FADD, VT, Custom);
-
- for (auto VT : {MVT::v4f16, MVT::v8f16, MVT::v4f32})
- setOperationAction(ISD::VECREDUCE_FADD, VT, Custom);
- }
- }
- PredictableSelectIsExpensive = Subtarget->predictableSelectIsExpensive();
- }
- void AArch64TargetLowering::addTypeForNEON(MVT VT, MVT PromotedBitwiseVT) {
- assert(VT.isVector() && "VT should be a vector type");
- if (VT.isFloatingPoint()) {
- MVT PromoteTo = EVT(VT).changeVectorElementTypeToInteger().getSimpleVT();
- setOperationPromotedToType(ISD::LOAD, VT, PromoteTo);
- setOperationPromotedToType(ISD::STORE, VT, PromoteTo);
- }
-
- if (VT == MVT::v2f32 || VT == MVT::v4f32 || VT == MVT::v2f64) {
- setOperationAction(ISD::FSIN, VT, Expand);
- setOperationAction(ISD::FCOS, VT, Expand);
- setOperationAction(ISD::FPOW, VT, Expand);
- setOperationAction(ISD::FLOG, VT, Expand);
- setOperationAction(ISD::FLOG2, VT, Expand);
- setOperationAction(ISD::FLOG10, VT, Expand);
- setOperationAction(ISD::FEXP, VT, Expand);
- setOperationAction(ISD::FEXP2, VT, Expand);
-
- setOperationAction(ISD::FCOPYSIGN, VT, Custom);
- }
- setOperationAction(ISD::EXTRACT_VECTOR_ELT, VT, Custom);
- setOperationAction(ISD::INSERT_VECTOR_ELT, VT, Custom);
- setOperationAction(ISD::BUILD_VECTOR, VT, Custom);
- setOperationAction(ISD::VECTOR_SHUFFLE, VT, Custom);
- setOperationAction(ISD::EXTRACT_SUBVECTOR, VT, Custom);
- setOperationAction(ISD::SRA, VT, Custom);
- setOperationAction(ISD::SRL, VT, Custom);
- setOperationAction(ISD::SHL, VT, Custom);
- setOperationAction(ISD::OR, VT, Custom);
- setOperationAction(ISD::SETCC, VT, Custom);
- setOperationAction(ISD::CONCAT_VECTORS, VT, Legal);
- setOperationAction(ISD::SELECT, VT, Expand);
- setOperationAction(ISD::SELECT_CC, VT, Expand);
- setOperationAction(ISD::VSELECT, VT, Expand);
- for (MVT InnerVT : MVT::all_valuetypes())
- setLoadExtAction(ISD::EXTLOAD, InnerVT, VT, Expand);
-
- if (VT != MVT::v8i8 && VT != MVT::v16i8)
- setOperationAction(ISD::CTPOP, VT, Custom);
- setOperationAction(ISD::UDIV, VT, Expand);
- setOperationAction(ISD::SDIV, VT, Expand);
- setOperationAction(ISD::UREM, VT, Expand);
- setOperationAction(ISD::SREM, VT, Expand);
- setOperationAction(ISD::FREM, VT, Expand);
- setOperationAction(ISD::FP_TO_SINT, VT, Custom);
- setOperationAction(ISD::FP_TO_UINT, VT, Custom);
- if (!VT.isFloatingPoint())
- setOperationAction(ISD::ABS, VT, Legal);
-
- if (!VT.isFloatingPoint() && VT != MVT::v2i64 && VT != MVT::v1i64)
- for (unsigned Opcode : {ISD::SMIN, ISD::SMAX, ISD::UMIN, ISD::UMAX})
- setOperationAction(Opcode, VT, Legal);
-
- if (VT.isFloatingPoint() &&
- VT.getVectorElementType() != MVT::bf16 &&
- (VT.getVectorElementType() != MVT::f16 || Subtarget->hasFullFP16()))
- for (unsigned Opcode :
- {ISD::FMINIMUM, ISD::FMAXIMUM, ISD::FMINNUM, ISD::FMAXNUM})
- setOperationAction(Opcode, VT, Legal);
- if (Subtarget->isLittleEndian()) {
- for (unsigned im = (unsigned)ISD::PRE_INC;
- im != (unsigned)ISD::LAST_INDEXED_MODE; ++im) {
- setIndexedLoadAction(im, VT, Legal);
- setIndexedStoreAction(im, VT, Legal);
- }
- }
- }
- void AArch64TargetLowering::addTypeForFixedLengthSVE(MVT VT) {
- assert(VT.isFixedLengthVector() && "Expected fixed length vector type!");
-
- for (unsigned Op = 0; Op < ISD::BUILTIN_OP_END; ++Op)
- setOperationAction(Op, VT, Expand);
-
- setOperationAction(ISD::EXTRACT_SUBVECTOR, VT, Custom);
-
- setOperationAction(ISD::ABS, VT, Custom);
- setOperationAction(ISD::ADD, VT, Custom);
- setOperationAction(ISD::AND, VT, Custom);
- setOperationAction(ISD::ANY_EXTEND, VT, Custom);
- setOperationAction(ISD::BITREVERSE, VT, Custom);
- setOperationAction(ISD::BSWAP, VT, Custom);
- setOperationAction(ISD::CTLZ, VT, Custom);
- setOperationAction(ISD::CTPOP, VT, Custom);
- setOperationAction(ISD::CTTZ, VT, Custom);
- setOperationAction(ISD::FADD, VT, Custom);
- setOperationAction(ISD::FCEIL, VT, Custom);
- setOperationAction(ISD::FDIV, VT, Custom);
- setOperationAction(ISD::FFLOOR, VT, Custom);
- setOperationAction(ISD::FMA, VT, Custom);
- setOperationAction(ISD::FMAXNUM, VT, Custom);
- setOperationAction(ISD::FMINNUM, VT, Custom);
- setOperationAction(ISD::FMUL, VT, Custom);
- setOperationAction(ISD::FNEARBYINT, VT, Custom);
- setOperationAction(ISD::FNEG, VT, Custom);
- setOperationAction(ISD::FRINT, VT, Custom);
- setOperationAction(ISD::FROUND, VT, Custom);
- setOperationAction(ISD::FSQRT, VT, Custom);
- setOperationAction(ISD::FSUB, VT, Custom);
- setOperationAction(ISD::FTRUNC, VT, Custom);
- setOperationAction(ISD::LOAD, VT, Custom);
- setOperationAction(ISD::MUL, VT, Custom);
- setOperationAction(ISD::OR, VT, Custom);
- setOperationAction(ISD::SDIV, VT, Custom);
- setOperationAction(ISD::SETCC, VT, Custom);
- setOperationAction(ISD::SHL, VT, Custom);
- setOperationAction(ISD::SIGN_EXTEND, VT, Custom);
- setOperationAction(ISD::SIGN_EXTEND_INREG, VT, Custom);
- setOperationAction(ISD::SMAX, VT, Custom);
- setOperationAction(ISD::SMIN, VT, Custom);
- setOperationAction(ISD::SPLAT_VECTOR, VT, Custom);
- setOperationAction(ISD::SRA, VT, Custom);
- setOperationAction(ISD::SRL, VT, Custom);
- setOperationAction(ISD::STORE, VT, Custom);
- setOperationAction(ISD::SUB, VT, Custom);
- setOperationAction(ISD::TRUNCATE, VT, Custom);
- setOperationAction(ISD::UDIV, VT, Custom);
- setOperationAction(ISD::UMAX, VT, Custom);
- setOperationAction(ISD::UMIN, VT, Custom);
- setOperationAction(ISD::VECREDUCE_ADD, VT, Custom);
- setOperationAction(ISD::VECREDUCE_AND, VT, Custom);
- setOperationAction(ISD::VECREDUCE_FADD, VT, Custom);
- setOperationAction(ISD::VECREDUCE_SEQ_FADD, VT, Custom);
- setOperationAction(ISD::VECREDUCE_FMAX, VT, Custom);
- setOperationAction(ISD::VECREDUCE_FMIN, VT, Custom);
- setOperationAction(ISD::VECREDUCE_OR, VT, Custom);
- setOperationAction(ISD::VECREDUCE_SMAX, VT, Custom);
- setOperationAction(ISD::VECREDUCE_SMIN, VT, Custom);
- setOperationAction(ISD::VECREDUCE_UMAX, VT, Custom);
- setOperationAction(ISD::VECREDUCE_UMIN, VT, Custom);
- setOperationAction(ISD::VECREDUCE_XOR, VT, Custom);
- setOperationAction(ISD::VSELECT, VT, Custom);
- setOperationAction(ISD::XOR, VT, Custom);
- setOperationAction(ISD::ZERO_EXTEND, VT, Custom);
- }
- void AArch64TargetLowering::addDRTypeForNEON(MVT VT) {
- addRegisterClass(VT, &AArch64::FPR64RegClass);
- addTypeForNEON(VT, MVT::v2i32);
- }
- void AArch64TargetLowering::addQRTypeForNEON(MVT VT) {
- addRegisterClass(VT, &AArch64::FPR128RegClass);
- addTypeForNEON(VT, MVT::v4i32);
- }
- EVT AArch64TargetLowering::getSetCCResultType(const DataLayout &,
- LLVMContext &C, EVT VT) const {
- if (!VT.isVector())
- return MVT::i32;
- if (VT.isScalableVector())
- return EVT::getVectorVT(C, MVT::i1, VT.getVectorElementCount());
- return VT.changeVectorElementTypeToInteger();
- }
- static bool optimizeLogicalImm(SDValue Op, unsigned Size, uint64_t Imm,
- const APInt &Demanded,
- TargetLowering::TargetLoweringOpt &TLO,
- unsigned NewOpc) {
- uint64_t OldImm = Imm, NewImm, Enc;
- uint64_t Mask = ((uint64_t)(-1LL) >> (64 - Size)), OrigMask = Mask;
-
-
- if (Imm == 0 || Imm == Mask ||
- AArch64_AM::isLogicalImmediate(Imm & Mask, Size))
- return false;
- unsigned EltSize = Size;
- uint64_t DemandedBits = Demanded.getZExtValue();
-
- Imm &= DemandedBits;
- while (true) {
-
-
-
-
-
-
-
- uint64_t NonDemandedBits = ~DemandedBits;
- uint64_t InvertedImm = ~Imm & DemandedBits;
- uint64_t RotatedImm =
- ((InvertedImm << 1) | (InvertedImm >> (EltSize - 1) & 1)) &
- NonDemandedBits;
- uint64_t Sum = RotatedImm + NonDemandedBits;
- bool Carry = NonDemandedBits & ~Sum & (1ULL << (EltSize - 1));
- uint64_t Ones = (Sum + Carry) & NonDemandedBits;
- NewImm = (Imm | Ones) & Mask;
-
-
-
- if (isShiftedMask_64(NewImm) || isShiftedMask_64(~(NewImm | ~Mask)))
- break;
-
- if (EltSize == 2)
- return false;
- EltSize /= 2;
- Mask >>= EltSize;
- uint64_t Hi = Imm >> EltSize, DemandedBitsHi = DemandedBits >> EltSize;
-
- if (((Imm ^ Hi) & (DemandedBits & DemandedBitsHi) & Mask) != 0)
- return false;
-
- Imm |= Hi;
- DemandedBits |= DemandedBitsHi;
- }
- ++NumOptimizedImms;
-
- while (EltSize < Size) {
- NewImm |= NewImm << EltSize;
- EltSize *= 2;
- }
- (void)OldImm;
- assert(((OldImm ^ NewImm) & Demanded.getZExtValue()) == 0 &&
- "demanded bits should never be altered");
- assert(OldImm != NewImm && "the new imm shouldn't be equal to the old imm");
-
- EVT VT = Op.getValueType();
- SDLoc DL(Op);
- SDValue New;
-
-
- if (NewImm == 0 || NewImm == OrigMask) {
- New = TLO.DAG.getNode(Op.getOpcode(), DL, VT, Op.getOperand(0),
- TLO.DAG.getConstant(NewImm, DL, VT));
-
-
- } else {
- Enc = AArch64_AM::encodeLogicalImmediate(NewImm, Size);
- SDValue EncConst = TLO.DAG.getTargetConstant(Enc, DL, VT);
- New = SDValue(
- TLO.DAG.getMachineNode(NewOpc, DL, VT, Op.getOperand(0), EncConst), 0);
- }
- return TLO.CombineTo(Op, New);
- }
- bool AArch64TargetLowering::targetShrinkDemandedConstant(
- SDValue Op, const APInt &DemandedBits, const APInt &DemandedElts,
- TargetLoweringOpt &TLO) const {
-
- if (!TLO.LegalOps)
- return false;
- if (!EnableOptimizeLogicalImm)
- return false;
- EVT VT = Op.getValueType();
- if (VT.isVector())
- return false;
- unsigned Size = VT.getSizeInBits();
- assert((Size == 32 || Size == 64) &&
- "i32 or i64 is expected after legalization.");
-
- if (DemandedBits.countPopulation() == Size)
- return false;
- unsigned NewOpc;
- switch (Op.getOpcode()) {
- default:
- return false;
- case ISD::AND:
- NewOpc = Size == 32 ? AArch64::ANDWri : AArch64::ANDXri;
- break;
- case ISD::OR:
- NewOpc = Size == 32 ? AArch64::ORRWri : AArch64::ORRXri;
- break;
- case ISD::XOR:
- NewOpc = Size == 32 ? AArch64::EORWri : AArch64::EORXri;
- break;
- }
- ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op.getOperand(1));
- if (!C)
- return false;
- uint64_t Imm = C->getZExtValue();
- return optimizeLogicalImm(Op, Size, Imm, DemandedBits, TLO, NewOpc);
- }
- void AArch64TargetLowering::computeKnownBitsForTargetNode(
- const SDValue Op, KnownBits &Known,
- const APInt &DemandedElts, const SelectionDAG &DAG, unsigned Depth) const {
- switch (Op.getOpcode()) {
- default:
- break;
- case AArch64ISD::CSEL: {
- KnownBits Known2;
- Known = DAG.computeKnownBits(Op->getOperand(0), Depth + 1);
- Known2 = DAG.computeKnownBits(Op->getOperand(1), Depth + 1);
- Known = KnownBits::commonBits(Known, Known2);
- break;
- }
- case AArch64ISD::LOADgot:
- case AArch64ISD::ADDlow: {
- if (!Subtarget->isTargetILP32())
- break;
-
- Known.Zero = APInt::getHighBitsSet(64, 32);
- break;
- }
- case ISD::INTRINSIC_W_CHAIN: {
- ConstantSDNode *CN = cast<ConstantSDNode>(Op->getOperand(1));
- Intrinsic::ID IntID = static_cast<Intrinsic::ID>(CN->getZExtValue());
- switch (IntID) {
- default: return;
- case Intrinsic::aarch64_ldaxr:
- case Intrinsic::aarch64_ldxr: {
- unsigned BitWidth = Known.getBitWidth();
- EVT VT = cast<MemIntrinsicSDNode>(Op)->getMemoryVT();
- unsigned MemBits = VT.getScalarSizeInBits();
- Known.Zero |= APInt::getHighBitsSet(BitWidth, BitWidth - MemBits);
- return;
- }
- }
- break;
- }
- case ISD::INTRINSIC_WO_CHAIN:
- case ISD::INTRINSIC_VOID: {
- unsigned IntNo = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue();
- switch (IntNo) {
- default:
- break;
- case Intrinsic::aarch64_neon_umaxv:
- case Intrinsic::aarch64_neon_uminv: {
-
-
-
-
- MVT VT = Op.getOperand(1).getValueType().getSimpleVT();
- unsigned BitWidth = Known.getBitWidth();
- if (VT == MVT::v8i8 || VT == MVT::v16i8) {
- assert(BitWidth >= 8 && "Unexpected width!");
- APInt Mask = APInt::getHighBitsSet(BitWidth, BitWidth - 8);
- Known.Zero |= Mask;
- } else if (VT == MVT::v4i16 || VT == MVT::v8i16) {
- assert(BitWidth >= 16 && "Unexpected width!");
- APInt Mask = APInt::getHighBitsSet(BitWidth, BitWidth - 16);
- Known.Zero |= Mask;
- }
- break;
- } break;
- }
- }
- }
- }
- MVT AArch64TargetLowering::getScalarShiftAmountTy(const DataLayout &DL,
- EVT) const {
- return MVT::i64;
- }
- bool AArch64TargetLowering::allowsMisalignedMemoryAccesses(
- EVT VT, unsigned AddrSpace, unsigned Align, MachineMemOperand::Flags Flags,
- bool *Fast) const {
- if (Subtarget->requiresStrictAlign())
- return false;
- if (Fast) {
-
- *Fast = !Subtarget->isMisaligned128StoreSlow() || VT.getStoreSize() != 16 ||
-
-
-
-
-
- Align <= 2 ||
-
-
- VT == MVT::v2i64;
- }
- return true;
- }
- bool AArch64TargetLowering::allowsMisalignedMemoryAccesses(
- LLT Ty, unsigned AddrSpace, Align Alignment, MachineMemOperand::Flags Flags,
- bool *Fast) const {
- if (Subtarget->requiresStrictAlign())
- return false;
- if (Fast) {
-
- *Fast = !Subtarget->isMisaligned128StoreSlow() ||
- Ty.getSizeInBytes() != 16 ||
-
-
-
-
-
- Alignment <= 2 ||
-
-
- Ty == LLT::vector(2, 64);
- }
- return true;
- }
- FastISel *
- AArch64TargetLowering::createFastISel(FunctionLoweringInfo &funcInfo,
- const TargetLibraryInfo *libInfo) const {
- return AArch64::createFastISel(funcInfo, libInfo);
- }
- const char *AArch64TargetLowering::getTargetNodeName(unsigned Opcode) const {
- #define MAKE_CASE(V) \
- case V: \
- return #V;
- switch ((AArch64ISD::NodeType)Opcode) {
- case AArch64ISD::FIRST_NUMBER:
- break;
- MAKE_CASE(AArch64ISD::CALL)
- MAKE_CASE(AArch64ISD::ADRP)
- MAKE_CASE(AArch64ISD::ADR)
- MAKE_CASE(AArch64ISD::ADDlow)
- MAKE_CASE(AArch64ISD::LOADgot)
- MAKE_CASE(AArch64ISD::RET_FLAG)
- MAKE_CASE(AArch64ISD::BRCOND)
- MAKE_CASE(AArch64ISD::CSEL)
- MAKE_CASE(AArch64ISD::FCSEL)
- MAKE_CASE(AArch64ISD::CSINV)
- MAKE_CASE(AArch64ISD::CSNEG)
- MAKE_CASE(AArch64ISD::CSINC)
- MAKE_CASE(AArch64ISD::THREAD_POINTER)
- MAKE_CASE(AArch64ISD::TLSDESC_CALLSEQ)
- MAKE_CASE(AArch64ISD::ADD_PRED)
- MAKE_CASE(AArch64ISD::MUL_PRED)
- MAKE_CASE(AArch64ISD::SDIV_PRED)
- MAKE_CASE(AArch64ISD::SHL_PRED)
- MAKE_CASE(AArch64ISD::SMAX_PRED)
- MAKE_CASE(AArch64ISD::SMIN_PRED)
- MAKE_CASE(AArch64ISD::SRA_PRED)
- MAKE_CASE(AArch64ISD::SRL_PRED)
- MAKE_CASE(AArch64ISD::SUB_PRED)
- MAKE_CASE(AArch64ISD::UDIV_PRED)
- MAKE_CASE(AArch64ISD::UMAX_PRED)
- MAKE_CASE(AArch64ISD::UMIN_PRED)
- MAKE_CASE(AArch64ISD::FNEG_MERGE_PASSTHRU)
- MAKE_CASE(AArch64ISD::SIGN_EXTEND_INREG_MERGE_PASSTHRU)
- MAKE_CASE(AArch64ISD::ZERO_EXTEND_INREG_MERGE_PASSTHRU)
- MAKE_CASE(AArch64ISD::FCEIL_MERGE_PASSTHRU)
- MAKE_CASE(AArch64ISD::FFLOOR_MERGE_PASSTHRU)
- MAKE_CASE(AArch64ISD::FNEARBYINT_MERGE_PASSTHRU)
- MAKE_CASE(AArch64ISD::FRINT_MERGE_PASSTHRU)
- MAKE_CASE(AArch64ISD::FROUND_MERGE_PASSTHRU)
- MAKE_CASE(AArch64ISD::FROUNDEVEN_MERGE_PASSTHRU)
- MAKE_CASE(AArch64ISD::FTRUNC_MERGE_PASSTHRU)
- MAKE_CASE(AArch64ISD::FP_ROUND_MERGE_PASSTHRU)
- MAKE_CASE(AArch64ISD::FP_EXTEND_MERGE_PASSTHRU)
- MAKE_CASE(AArch64ISD::SINT_TO_FP_MERGE_PASSTHRU)
- MAKE_CASE(AArch64ISD::UINT_TO_FP_MERGE_PASSTHRU)
- MAKE_CASE(AArch64ISD::FCVTZU_MERGE_PASSTHRU)
- MAKE_CASE(AArch64ISD::FCVTZS_MERGE_PASSTHRU)
- MAKE_CASE(AArch64ISD::FSQRT_MERGE_PASSTHRU)
- MAKE_CASE(AArch64ISD::FRECPX_MERGE_PASSTHRU)
- MAKE_CASE(AArch64ISD::FABS_MERGE_PASSTHRU)
- MAKE_CASE(AArch64ISD::ABS_MERGE_PASSTHRU)
- MAKE_CASE(AArch64ISD::NEG_MERGE_PASSTHRU)
- MAKE_CASE(AArch64ISD::SETCC_MERGE_ZERO)
- MAKE_CASE(AArch64ISD::ADC)
- MAKE_CASE(AArch64ISD::SBC)
- MAKE_CASE(AArch64ISD::ADDS)
- MAKE_CASE(AArch64ISD::SUBS)
- MAKE_CASE(AArch64ISD::ADCS)
- MAKE_CASE(AArch64ISD::SBCS)
- MAKE_CASE(AArch64ISD::ANDS)
- MAKE_CASE(AArch64ISD::CCMP)
- MAKE_CASE(AArch64ISD::CCMN)
- MAKE_CASE(AArch64ISD::FCCMP)
- MAKE_CASE(AArch64ISD::FCMP)
- MAKE_CASE(AArch64ISD::STRICT_FCMP)
- MAKE_CASE(AArch64ISD::STRICT_FCMPE)
- MAKE_CASE(AArch64ISD::DUP)
- MAKE_CASE(AArch64ISD::DUPLANE8)
- MAKE_CASE(AArch64ISD::DUPLANE16)
- MAKE_CASE(AArch64ISD::DUPLANE32)
- MAKE_CASE(AArch64ISD::DUPLANE64)
- MAKE_CASE(AArch64ISD::MOVI)
- MAKE_CASE(AArch64ISD::MOVIshift)
- MAKE_CASE(AArch64ISD::MOVIedit)
- MAKE_CASE(AArch64ISD::MOVImsl)
- MAKE_CASE(AArch64ISD::FMOV)
- MAKE_CASE(AArch64ISD::MVNIshift)
- MAKE_CASE(AArch64ISD::MVNImsl)
- MAKE_CASE(AArch64ISD::BICi)
- MAKE_CASE(AArch64ISD::ORRi)
- MAKE_CASE(AArch64ISD::BSP)
- MAKE_CASE(AArch64ISD::NEG)
- MAKE_CASE(AArch64ISD::EXTR)
- MAKE_CASE(AArch64ISD::ZIP1)
- MAKE_CASE(AArch64ISD::ZIP2)
- MAKE_CASE(AArch64ISD::UZP1)
- MAKE_CASE(AArch64ISD::UZP2)
- MAKE_CASE(AArch64ISD::TRN1)
- MAKE_CASE(AArch64ISD::TRN2)
- MAKE_CASE(AArch64ISD::REV16)
- MAKE_CASE(AArch64ISD::REV32)
- MAKE_CASE(AArch64ISD::REV64)
- MAKE_CASE(AArch64ISD::EXT)
- MAKE_CASE(AArch64ISD::VSHL)
- MAKE_CASE(AArch64ISD::VLSHR)
- MAKE_CASE(AArch64ISD::VASHR)
- MAKE_CASE(AArch64ISD::VSLI)
- MAKE_CASE(AArch64ISD::VSRI)
- MAKE_CASE(AArch64ISD::CMEQ)
- MAKE_CASE(AArch64ISD::CMGE)
- MAKE_CASE(AArch64ISD::CMGT)
- MAKE_CASE(AArch64ISD::CMHI)
- MAKE_CASE(AArch64ISD::CMHS)
- MAKE_CASE(AArch64ISD::FCMEQ)
- MAKE_CASE(AArch64ISD::FCMGE)
- MAKE_CASE(AArch64ISD::FCMGT)
- MAKE_CASE(AArch64ISD::CMEQz)
- MAKE_CASE(AArch64ISD::CMGEz)
- MAKE_CASE(AArch64ISD::CMGTz)
- MAKE_CASE(AArch64ISD::CMLEz)
- MAKE_CASE(AArch64ISD::CMLTz)
- MAKE_CASE(AArch64ISD::FCMEQz)
- MAKE_CASE(AArch64ISD::FCMGEz)
- MAKE_CASE(AArch64ISD::FCMGTz)
- MAKE_CASE(AArch64ISD::FCMLEz)
- MAKE_CASE(AArch64ISD::FCMLTz)
- MAKE_CASE(AArch64ISD::SADDV)
- MAKE_CASE(AArch64ISD::UADDV)
- MAKE_CASE(AArch64ISD::SRHADD)
- MAKE_CASE(AArch64ISD::URHADD)
- MAKE_CASE(AArch64ISD::SHADD)
- MAKE_CASE(AArch64ISD::UHADD)
- MAKE_CASE(AArch64ISD::SMINV)
- MAKE_CASE(AArch64ISD::UMINV)
- MAKE_CASE(AArch64ISD::SMAXV)
- MAKE_CASE(AArch64ISD::UMAXV)
- MAKE_CASE(AArch64ISD::SADDV_PRED)
- MAKE_CASE(AArch64ISD::UADDV_PRED)
- MAKE_CASE(AArch64ISD::SMAXV_PRED)
- MAKE_CASE(AArch64ISD::UMAXV_PRED)
- MAKE_CASE(AArch64ISD::SMINV_PRED)
- MAKE_CASE(AArch64ISD::UMINV_PRED)
- MAKE_CASE(AArch64ISD::ORV_PRED)
- MAKE_CASE(AArch64ISD::EORV_PRED)
- MAKE_CASE(AArch64ISD::ANDV_PRED)
- MAKE_CASE(AArch64ISD::CLASTA_N)
- MAKE_CASE(AArch64ISD::CLASTB_N)
- MAKE_CASE(AArch64ISD::LASTA)
- MAKE_CASE(AArch64ISD::LASTB)
- MAKE_CASE(AArch64ISD::REV)
- MAKE_CASE(AArch64ISD::REINTERPRET_CAST)
- MAKE_CASE(AArch64ISD::TBL)
- MAKE_CASE(AArch64ISD::FADD_PRED)
- MAKE_CASE(AArch64ISD::FADDA_PRED)
- MAKE_CASE(AArch64ISD::FADDV_PRED)
- MAKE_CASE(AArch64ISD::FDIV_PRED)
- MAKE_CASE(AArch64ISD::FMA_PRED)
- MAKE_CASE(AArch64ISD::FMAXV_PRED)
- MAKE_CASE(AArch64ISD::FMAXNM_PRED)
- MAKE_CASE(AArch64ISD::FMAXNMV_PRED)
- MAKE_CASE(AArch64ISD::FMINV_PRED)
- MAKE_CASE(AArch64ISD::FMINNM_PRED)
- MAKE_CASE(AArch64ISD::FMINNMV_PRED)
- MAKE_CASE(AArch64ISD::FMUL_PRED)
- MAKE_CASE(AArch64ISD::FSUB_PRED)
- MAKE_CASE(AArch64ISD::BIT)
- MAKE_CASE(AArch64ISD::CBZ)
- MAKE_CASE(AArch64ISD::CBNZ)
- MAKE_CASE(AArch64ISD::TBZ)
- MAKE_CASE(AArch64ISD::TBNZ)
- MAKE_CASE(AArch64ISD::TC_RETURN)
- MAKE_CASE(AArch64ISD::PREFETCH)
- MAKE_CASE(AArch64ISD::SITOF)
- MAKE_CASE(AArch64ISD::UITOF)
- MAKE_CASE(AArch64ISD::NVCAST)
- MAKE_CASE(AArch64ISD::SQSHL_I)
- MAKE_CASE(AArch64ISD::UQSHL_I)
- MAKE_CASE(AArch64ISD::SRSHR_I)
- MAKE_CASE(AArch64ISD::URSHR_I)
- MAKE_CASE(AArch64ISD::SQSHLU_I)
- MAKE_CASE(AArch64ISD::WrapperLarge)
- MAKE_CASE(AArch64ISD::LD2post)
- MAKE_CASE(AArch64ISD::LD3post)
- MAKE_CASE(AArch64ISD::LD4post)
- MAKE_CASE(AArch64ISD::ST2post)
- MAKE_CASE(AArch64ISD::ST3post)
- MAKE_CASE(AArch64ISD::ST4post)
- MAKE_CASE(AArch64ISD::LD1x2post)
- MAKE_CASE(AArch64ISD::LD1x3post)
- MAKE_CASE(AArch64ISD::LD1x4post)
- MAKE_CASE(AArch64ISD::ST1x2post)
- MAKE_CASE(AArch64ISD::ST1x3post)
- MAKE_CASE(AArch64ISD::ST1x4post)
- MAKE_CASE(AArch64ISD::LD1DUPpost)
- MAKE_CASE(AArch64ISD::LD2DUPpost)
- MAKE_CASE(AArch64ISD::LD3DUPpost)
- MAKE_CASE(AArch64ISD::LD4DUPpost)
- MAKE_CASE(AArch64ISD::LD1LANEpost)
- MAKE_CASE(AArch64ISD::LD2LANEpost)
- MAKE_CASE(AArch64ISD::LD3LANEpost)
- MAKE_CASE(AArch64ISD::LD4LANEpost)
- MAKE_CASE(AArch64ISD::ST2LANEpost)
- MAKE_CASE(AArch64ISD::ST3LANEpost)
- MAKE_CASE(AArch64ISD::ST4LANEpost)
- MAKE_CASE(AArch64ISD::SMULL)
- MAKE_CASE(AArch64ISD::UMULL)
- MAKE_CASE(AArch64ISD::FRECPE)
- MAKE_CASE(AArch64ISD::FRECPS)
- MAKE_CASE(AArch64ISD::FRSQRTE)
- MAKE_CASE(AArch64ISD::FRSQRTS)
- MAKE_CASE(AArch64ISD::STG)
- MAKE_CASE(AArch64ISD::STZG)
- MAKE_CASE(AArch64ISD::ST2G)
- MAKE_CASE(AArch64ISD::STZ2G)
- MAKE_CASE(AArch64ISD::SUNPKHI)
- MAKE_CASE(AArch64ISD::SUNPKLO)
- MAKE_CASE(AArch64ISD::UUNPKHI)
- MAKE_CASE(AArch64ISD::UUNPKLO)
- MAKE_CASE(AArch64ISD::INSR)
- MAKE_CASE(AArch64ISD::PTEST)
- MAKE_CASE(AArch64ISD::PTRUE)
- MAKE_CASE(AArch64ISD::LD1_MERGE_ZERO)
- MAKE_CASE(AArch64ISD::LD1S_MERGE_ZERO)
- MAKE_CASE(AArch64ISD::LDNF1_MERGE_ZERO)
- MAKE_CASE(AArch64ISD::LDNF1S_MERGE_ZERO)
- MAKE_CASE(AArch64ISD::LDFF1_MERGE_ZERO)
- MAKE_CASE(AArch64ISD::LDFF1S_MERGE_ZERO)
- MAKE_CASE(AArch64ISD::LD1RQ_MERGE_ZERO)
- MAKE_CASE(AArch64ISD::LD1RO_MERGE_ZERO)
- MAKE_CASE(AArch64ISD::SVE_LD2_MERGE_ZERO)
- MAKE_CASE(AArch64ISD::SVE_LD3_MERGE_ZERO)
- MAKE_CASE(AArch64ISD::SVE_LD4_MERGE_ZERO)
- MAKE_CASE(AArch64ISD::GLD1_MERGE_ZERO)
- MAKE_CASE(AArch64ISD::GLD1_SCALED_MERGE_ZERO)
- MAKE_CASE(AArch64ISD::GLD1_SXTW_MERGE_ZERO)
- MAKE_CASE(AArch64ISD::GLD1_UXTW_MERGE_ZERO)
- MAKE_CASE(AArch64ISD::GLD1_SXTW_SCALED_MERGE_ZERO)
- MAKE_CASE(AArch64ISD::GLD1_UXTW_SCALED_MERGE_ZERO)
- MAKE_CASE(AArch64ISD::GLD1_IMM_MERGE_ZERO)
- MAKE_CASE(AArch64ISD::GLD1S_MERGE_ZERO)
- MAKE_CASE(AArch64ISD::GLD1S_SCALED_MERGE_ZERO)
- MAKE_CASE(AArch64ISD::GLD1S_SXTW_MERGE_ZERO)
- MAKE_CASE(AArch64ISD::GLD1S_UXTW_MERGE_ZERO)
- MAKE_CASE(AArch64ISD::GLD1S_SXTW_SCALED_MERGE_ZERO)
- MAKE_CASE(AArch64ISD::GLD1S_UXTW_SCALED_MERGE_ZERO)
- MAKE_CASE(AArch64ISD::GLD1S_IMM_MERGE_ZERO)
- MAKE_CASE(AArch64ISD::GLDFF1_MERGE_ZERO)
- MAKE_CASE(AArch64ISD::GLDFF1_SCALED_MERGE_ZERO)
- MAKE_CASE(AArch64ISD::GLDFF1_SXTW_MERGE_ZERO)
- MAKE_CASE(AArch64ISD::GLDFF1_UXTW_MERGE_ZERO)
- MAKE_CASE(AArch64ISD::GLDFF1_SXTW_SCALED_MERGE_ZERO)
- MAKE_CASE(AArch64ISD::GLDFF1_UXTW_SCALED_MERGE_ZERO)
- MAKE_CASE(AArch64ISD::GLDFF1_IMM_MERGE_ZERO)
- MAKE_CASE(AArch64ISD::GLDFF1S_MERGE_ZERO)
- MAKE_CASE(AArch64ISD::GLDFF1S_SCALED_MERGE_ZERO)
- MAKE_CASE(AArch64ISD::GLDFF1S_SXTW_MERGE_ZERO)
- MAKE_CASE(AArch64ISD::GLDFF1S_UXTW_MERGE_ZERO)
- MAKE_CASE(AArch64ISD::GLDFF1S_SXTW_SCALED_MERGE_ZERO)
- MAKE_CASE(AArch64ISD::GLDFF1S_UXTW_SCALED_MERGE_ZERO)
- MAKE_CASE(AArch64ISD::GLDFF1S_IMM_MERGE_ZERO)
- MAKE_CASE(AArch64ISD::GLDNT1_MERGE_ZERO)
- MAKE_CASE(AArch64ISD::GLDNT1_INDEX_MERGE_ZERO)
- MAKE_CASE(AArch64ISD::GLDNT1S_MERGE_ZERO)
- MAKE_CASE(AArch64ISD::ST1_PRED)
- MAKE_CASE(AArch64ISD::SST1_PRED)
- MAKE_CASE(AArch64ISD::SST1_SCALED_PRED)
- MAKE_CASE(AArch64ISD::SST1_SXTW_PRED)
- MAKE_CASE(AArch64ISD::SST1_UXTW_PRED)
- MAKE_CASE(AArch64ISD::SST1_SXTW_SCALED_PRED)
- MAKE_CASE(AArch64ISD::SST1_UXTW_SCALED_PRED)
- MAKE_CASE(AArch64ISD::SST1_IMM_PRED)
- MAKE_CASE(AArch64ISD::SSTNT1_PRED)
- MAKE_CASE(AArch64ISD::SSTNT1_INDEX_PRED)
- MAKE_CASE(AArch64ISD::LDP)
- MAKE_CASE(AArch64ISD::STP)
- MAKE_CASE(AArch64ISD::STNP)
- MAKE_CASE(AArch64ISD::BITREVERSE_MERGE_PASSTHRU)
- MAKE_CASE(AArch64ISD::BSWAP_MERGE_PASSTHRU)
- MAKE_CASE(AArch64ISD::CTLZ_MERGE_PASSTHRU)
- MAKE_CASE(AArch64ISD::CTPOP_MERGE_PASSTHRU)
- MAKE_CASE(AArch64ISD::DUP_MERGE_PASSTHRU)
- MAKE_CASE(AArch64ISD::INDEX_VECTOR)
- MAKE_CASE(AArch64ISD::UABD)
- MAKE_CASE(AArch64ISD::SABD)
- MAKE_CASE(AArch64ISD::CALL_RVMARKER)
- }
- #undef MAKE_CASE
- return nullptr;
- }
- MachineBasicBlock *
- AArch64TargetLowering::EmitF128CSEL(MachineInstr &MI,
- MachineBasicBlock *MBB) const {
-
-
-
-
-
-
-
-
-
-
- MachineFunction *MF = MBB->getParent();
- const TargetInstrInfo *TII = Subtarget->getInstrInfo();
- const BasicBlock *LLVM_BB = MBB->getBasicBlock();
- DebugLoc DL = MI.getDebugLoc();
- MachineFunction::iterator It = ++MBB->getIterator();
- Register DestReg = MI.getOperand(0).getReg();
- Register IfTrueReg = MI.getOperand(1).getReg();
- Register IfFalseReg = MI.getOperand(2).getReg();
- unsigned CondCode = MI.getOperand(3).getImm();
- bool NZCVKilled = MI.getOperand(4).isKill();
- MachineBasicBlock *TrueBB = MF->CreateMachineBasicBlock(LLVM_BB);
- MachineBasicBlock *EndBB = MF->CreateMachineBasicBlock(LLVM_BB);
- MF->insert(It, TrueBB);
- MF->insert(It, EndBB);
-
- EndBB->splice(EndBB->begin(), MBB, std::next(MachineBasicBlock::iterator(MI)),
- MBB->end());
- EndBB->transferSuccessorsAndUpdatePHIs(MBB);
- BuildMI(MBB, DL, TII->get(AArch64::Bcc)).addImm(CondCode).addMBB(TrueBB);
- BuildMI(MBB, DL, TII->get(AArch64::B)).addMBB(EndBB);
- MBB->addSuccessor(TrueBB);
- MBB->addSuccessor(EndBB);
-
- TrueBB->addSuccessor(EndBB);
- if (!NZCVKilled) {
- TrueBB->addLiveIn(AArch64::NZCV);
- EndBB->addLiveIn(AArch64::NZCV);
- }
- BuildMI(*EndBB, EndBB->begin(), DL, TII->get(AArch64::PHI), DestReg)
- .addReg(IfTrueReg)
- .addMBB(TrueBB)
- .addReg(IfFalseReg)
- .addMBB(MBB);
- MI.eraseFromParent();
- return EndBB;
- }
- MachineBasicBlock *AArch64TargetLowering::EmitLoweredCatchRet(
- MachineInstr &MI, MachineBasicBlock *BB) const {
- assert(!isAsynchronousEHPersonality(classifyEHPersonality(
- BB->getParent()->getFunction().getPersonalityFn())) &&
- "SEH does not use catchret!");
- return BB;
- }
- MachineBasicBlock *AArch64TargetLowering::EmitInstrWithCustomInserter(
- MachineInstr &MI, MachineBasicBlock *BB) const {
- switch (MI.getOpcode()) {
- default:
- #ifndef NDEBUG
- MI.dump();
- #endif
- llvm_unreachable("Unexpected instruction for custom inserter!");
- case AArch64::F128CSEL:
- return EmitF128CSEL(MI, BB);
- case TargetOpcode::STACKMAP:
- case TargetOpcode::PATCHPOINT:
- case TargetOpcode::STATEPOINT:
- return emitPatchPoint(MI, BB);
- case AArch64::CATCHRET:
- return EmitLoweredCatchRet(MI, BB);
- }
- }
- static AArch64CC::CondCode changeIntCCToAArch64CC(ISD::CondCode CC) {
- switch (CC) {
- default:
- llvm_unreachable("Unknown condition code!");
- case ISD::SETNE:
- return AArch64CC::NE;
- case ISD::SETEQ:
- return AArch64CC::EQ;
- case ISD::SETGT:
- return AArch64CC::GT;
- case ISD::SETGE:
- return AArch64CC::GE;
- case ISD::SETLT:
- return AArch64CC::LT;
- case ISD::SETLE:
- return AArch64CC::LE;
- case ISD::SETUGT:
- return AArch64CC::HI;
- case ISD::SETUGE:
- return AArch64CC::HS;
- case ISD::SETULT:
- return AArch64CC::LO;
- case ISD::SETULE:
- return AArch64CC::LS;
- }
- }
- static void changeFPCCToAArch64CC(ISD::CondCode CC,
- AArch64CC::CondCode &CondCode,
- AArch64CC::CondCode &CondCode2) {
- CondCode2 = AArch64CC::AL;
- switch (CC) {
- default:
- llvm_unreachable("Unknown FP condition!");
- case ISD::SETEQ:
- case ISD::SETOEQ:
- CondCode = AArch64CC::EQ;
- break;
- case ISD::SETGT:
- case ISD::SETOGT:
- CondCode = AArch64CC::GT;
- break;
- case ISD::SETGE:
- case ISD::SETOGE:
- CondCode = AArch64CC::GE;
- break;
- case ISD::SETOLT:
- CondCode = AArch64CC::MI;
- break;
- case ISD::SETOLE:
- CondCode = AArch64CC::LS;
- break;
- case ISD::SETONE:
- CondCode = AArch64CC::MI;
- CondCode2 = AArch64CC::GT;
- break;
- case ISD::SETO:
- CondCode = AArch64CC::VC;
- break;
- case ISD::SETUO:
- CondCode = AArch64CC::VS;
- break;
- case ISD::SETUEQ:
- CondCode = AArch64CC::EQ;
- CondCode2 = AArch64CC::VS;
- break;
- case ISD::SETUGT:
- CondCode = AArch64CC::HI;
- break;
- case ISD::SETUGE:
- CondCode = AArch64CC::PL;
- break;
- case ISD::SETLT:
- case ISD::SETULT:
- CondCode = AArch64CC::LT;
- break;
- case ISD::SETLE:
- case ISD::SETULE:
- CondCode = AArch64CC::LE;
- break;
- case ISD::SETNE:
- case ISD::SETUNE:
- CondCode = AArch64CC::NE;
- break;
- }
- }
- static void changeFPCCToANDAArch64CC(ISD::CondCode CC,
- AArch64CC::CondCode &CondCode,
- AArch64CC::CondCode &CondCode2) {
- CondCode2 = AArch64CC::AL;
- switch (CC) {
- default:
- changeFPCCToAArch64CC(CC, CondCode, CondCode2);
- assert(CondCode2 == AArch64CC::AL);
- break;
- case ISD::SETONE:
-
-
-
- CondCode = AArch64CC::VC;
- CondCode2 = AArch64CC::NE;
- break;
- case ISD::SETUEQ:
-
-
-
- CondCode = AArch64CC::PL;
- CondCode2 = AArch64CC::LE;
- break;
- }
- }
- static void changeVectorFPCCToAArch64CC(ISD::CondCode CC,
- AArch64CC::CondCode &CondCode,
- AArch64CC::CondCode &CondCode2,
- bool &Invert) {
- Invert = false;
- switch (CC) {
- default:
-
- changeFPCCToAArch64CC(CC, CondCode, CondCode2);
- break;
- case ISD::SETUO:
- Invert = true;
- LLVM_FALLTHROUGH;
- case ISD::SETO:
- CondCode = AArch64CC::MI;
- CondCode2 = AArch64CC::GE;
- break;
- case ISD::SETUEQ:
- case ISD::SETULT:
- case ISD::SETULE:
- case ISD::SETUGT:
- case ISD::SETUGE:
-
-
- Invert = true;
- changeFPCCToAArch64CC(getSetCCInverse(CC, MVT::f32),
- CondCode, CondCode2);
- break;
- }
- }
- static bool isLegalArithImmed(uint64_t C) {
-
- bool IsLegal = (C >> 12 == 0) || ((C & 0xFFFULL) == 0 && C >> 24 == 0);
- LLVM_DEBUG(dbgs() << "Is imm " << C
- << " legal: " << (IsLegal ? "yes\n" : "no\n"));
- return IsLegal;
- }
- static bool isCMN(SDValue Op, ISD::CondCode CC) {
- return Op.getOpcode() == ISD::SUB && isNullConstant(Op.getOperand(0)) &&
- (CC == ISD::SETEQ || CC == ISD::SETNE);
- }
- static SDValue emitStrictFPComparison(SDValue LHS, SDValue RHS, const SDLoc &dl,
- SelectionDAG &DAG, SDValue Chain,
- bool IsSignaling) {
- EVT VT = LHS.getValueType();
- assert(VT != MVT::f128);
- assert(VT != MVT::f16 && "Lowering of strict fp16 not yet implemented");
- unsigned Opcode =
- IsSignaling ? AArch64ISD::STRICT_FCMPE : AArch64ISD::STRICT_FCMP;
- return DAG.getNode(Opcode, dl, {VT, MVT::Other}, {Chain, LHS, RHS});
- }
- static SDValue emitComparison(SDValue LHS, SDValue RHS, ISD::CondCode CC,
- const SDLoc &dl, SelectionDAG &DAG) {
- EVT VT = LHS.getValueType();
- const bool FullFP16 =
- static_cast<const AArch64Subtarget &>(DAG.getSubtarget()).hasFullFP16();
- if (VT.isFloatingPoint()) {
- assert(VT != MVT::f128);
- if (VT == MVT::f16 && !FullFP16) {
- LHS = DAG.getNode(ISD::FP_EXTEND, dl, MVT::f32, LHS);
- RHS = DAG.getNode(ISD::FP_EXTEND, dl, MVT::f32, RHS);
- VT = MVT::f32;
- }
- return DAG.getNode(AArch64ISD::FCMP, dl, VT, LHS, RHS);
- }
-
-
-
-
- unsigned Opcode = AArch64ISD::SUBS;
- if (isCMN(RHS, CC)) {
-
- Opcode = AArch64ISD::ADDS;
- RHS = RHS.getOperand(1);
- } else if (isCMN(LHS, CC)) {
-
-
- Opcode = AArch64ISD::ADDS;
- LHS = LHS.getOperand(1);
- } else if (isNullConstant(RHS) && !isUnsignedIntSetCC(CC)) {
- if (LHS.getOpcode() == ISD::AND) {
-
-
-
- const SDValue ANDSNode = DAG.getNode(AArch64ISD::ANDS, dl,
- DAG.getVTList(VT, MVT_CC),
- LHS.getOperand(0),
- LHS.getOperand(1));
-
- DAG.ReplaceAllUsesWith(LHS, ANDSNode);
- return ANDSNode.getValue(1);
- } else if (LHS.getOpcode() == AArch64ISD::ANDS) {
-
- return LHS.getValue(1);
- }
- }
- return DAG.getNode(Opcode, dl, DAG.getVTList(VT, MVT_CC), LHS, RHS)
- .getValue(1);
- }
- static SDValue emitConditionalComparison(SDValue LHS, SDValue RHS,
- ISD::CondCode CC, SDValue CCOp,
- AArch64CC::CondCode Predicate,
- AArch64CC::CondCode OutCC,
- const SDLoc &DL, SelectionDAG &DAG) {
- unsigned Opcode = 0;
- const bool FullFP16 =
- static_cast<const AArch64Subtarget &>(DAG.getSubtarget()).hasFullFP16();
- if (LHS.getValueType().isFloatingPoint()) {
- assert(LHS.getValueType() != MVT::f128);
- if (LHS.getValueType() == MVT::f16 && !FullFP16) {
- LHS = DAG.getNode(ISD::FP_EXTEND, DL, MVT::f32, LHS);
- RHS = DAG.getNode(ISD::FP_EXTEND, DL, MVT::f32, RHS);
- }
- Opcode = AArch64ISD::FCCMP;
- } else if (RHS.getOpcode() == ISD::SUB) {
- SDValue SubOp0 = RHS.getOperand(0);
- if (isNullConstant(SubOp0) && (CC == ISD::SETEQ || CC == ISD::SETNE)) {
-
- Opcode = AArch64ISD::CCMN;
- RHS = RHS.getOperand(1);
- }
- }
- if (Opcode == 0)
- Opcode = AArch64ISD::CCMP;
- SDValue Condition = DAG.getConstant(Predicate, DL, MVT_CC);
- AArch64CC::CondCode InvOutCC = AArch64CC::getInvertedCondCode(OutCC);
- unsigned NZCV = AArch64CC::getNZCVToSatisfyCondCode(InvOutCC);
- SDValue NZCVOp = DAG.getConstant(NZCV, DL, MVT::i32);
- return DAG.getNode(Opcode, DL, MVT_CC, LHS, RHS, NZCVOp, Condition, CCOp);
- }
- static bool canEmitConjunction(const SDValue Val, bool &CanNegate,
- bool &MustBeFirst, bool WillNegate,
- unsigned Depth = 0) {
- if (!Val.hasOneUse())
- return false;
- unsigned Opcode = Val->getOpcode();
- if (Opcode == ISD::SETCC) {
- if (Val->getOperand(0).getValueType() == MVT::f128)
- return false;
- CanNegate = true;
- MustBeFirst = false;
- return true;
- }
-
- if (Depth > 6)
- return false;
- if (Opcode == ISD::AND || Opcode == ISD::OR) {
- bool IsOR = Opcode == ISD::OR;
- SDValue O0 = Val->getOperand(0);
- SDValue O1 = Val->getOperand(1);
- bool CanNegateL;
- bool MustBeFirstL;
- if (!canEmitConjunction(O0, CanNegateL, MustBeFirstL, IsOR, Depth+1))
- return false;
- bool CanNegateR;
- bool MustBeFirstR;
- if (!canEmitConjunction(O1, CanNegateR, MustBeFirstR, IsOR, Depth+1))
- return false;
- if (MustBeFirstL && MustBeFirstR)
- return false;
- if (IsOR) {
-
-
- if (!CanNegateL && !CanNegateR)
- return false;
-
-
- CanNegate = WillNegate && CanNegateL && CanNegateR;
-
-
- MustBeFirst = !CanNegate;
- } else {
- assert(Opcode == ISD::AND && "Must be OR or AND");
-
- CanNegate = false;
- MustBeFirst = MustBeFirstL || MustBeFirstR;
- }
- return true;
- }
- return false;
- }
- static SDValue emitConjunctionRec(SelectionDAG &DAG, SDValue Val,
- AArch64CC::CondCode &OutCC, bool Negate, SDValue CCOp,
- AArch64CC::CondCode Predicate) {
-
- unsigned Opcode = Val->getOpcode();
- if (Opcode == ISD::SETCC) {
- SDValue LHS = Val->getOperand(0);
- SDValue RHS = Val->getOperand(1);
- ISD::CondCode CC = cast<CondCodeSDNode>(Val->getOperand(2))->get();
- bool isInteger = LHS.getValueType().isInteger();
- if (Negate)
- CC = getSetCCInverse(CC, LHS.getValueType());
- SDLoc DL(Val);
-
- if (isInteger) {
- OutCC = changeIntCCToAArch64CC(CC);
- } else {
- assert(LHS.getValueType().isFloatingPoint());
- AArch64CC::CondCode ExtraCC;
- changeFPCCToANDAArch64CC(CC, OutCC, ExtraCC);
-
-
- if (ExtraCC != AArch64CC::AL) {
- SDValue ExtraCmp;
- if (!CCOp.getNode())
- ExtraCmp = emitComparison(LHS, RHS, CC, DL, DAG);
- else
- ExtraCmp = emitConditionalComparison(LHS, RHS, CC, CCOp, Predicate,
- ExtraCC, DL, DAG);
- CCOp = ExtraCmp;
- Predicate = ExtraCC;
- }
- }
-
- if (!CCOp)
- return emitComparison(LHS, RHS, CC, DL, DAG);
-
- return emitConditionalComparison(LHS, RHS, CC, CCOp, Predicate, OutCC, DL,
- DAG);
- }
- assert(Val->hasOneUse() && "Valid conjunction/disjunction tree");
- bool IsOR = Opcode == ISD::OR;
- SDValue LHS = Val->getOperand(0);
- bool CanNegateL;
- bool MustBeFirstL;
- bool ValidL = canEmitConjunction(LHS, CanNegateL, MustBeFirstL, IsOR);
- assert(ValidL && "Valid conjunction/disjunction tree");
- (void)ValidL;
- SDValue RHS = Val->getOperand(1);
- bool CanNegateR;
- bool MustBeFirstR;
- bool ValidR = canEmitConjunction(RHS, CanNegateR, MustBeFirstR, IsOR);
- assert(ValidR && "Valid conjunction/disjunction tree");
- (void)ValidR;
-
- if (MustBeFirstL) {
- assert(!MustBeFirstR && "Valid conjunction/disjunction tree");
- std::swap(LHS, RHS);
- std::swap(CanNegateL, CanNegateR);
- std::swap(MustBeFirstL, MustBeFirstR);
- }
- bool NegateR;
- bool NegateAfterR;
- bool NegateL;
- bool NegateAfterAll;
- if (Opcode == ISD::OR) {
-
- if (!CanNegateL) {
- assert(CanNegateR && "at least one side must be negatable");
- assert(!MustBeFirstR && "invalid conjunction/disjunction tree");
- assert(!Negate);
- std::swap(LHS, RHS);
- NegateR = false;
- NegateAfterR = true;
- } else {
-
- NegateR = CanNegateR;
- NegateAfterR = !CanNegateR;
- }
- NegateL = true;
- NegateAfterAll = !Negate;
- } else {
- assert(Opcode == ISD::AND && "Valid conjunction/disjunction tree");
- assert(!Negate && "Valid conjunction/disjunction tree");
- NegateL = false;
- NegateR = false;
- NegateAfterR = false;
- NegateAfterAll = false;
- }
-
- AArch64CC::CondCode RHSCC;
- SDValue CmpR = emitConjunctionRec(DAG, RHS, RHSCC, NegateR, CCOp, Predicate);
- if (NegateAfterR)
- RHSCC = AArch64CC::getInvertedCondCode(RHSCC);
- SDValue CmpL = emitConjunctionRec(DAG, LHS, OutCC, NegateL, CmpR, RHSCC);
- if (NegateAfterAll)
- OutCC = AArch64CC::getInvertedCondCode(OutCC);
- return CmpL;
- }
- static SDValue emitConjunction(SelectionDAG &DAG, SDValue Val,
- AArch64CC::CondCode &OutCC) {
- bool DummyCanNegate;
- bool DummyMustBeFirst;
- if (!canEmitConjunction(Val, DummyCanNegate, DummyMustBeFirst, false))
- return SDValue();
- return emitConjunctionRec(DAG, Val, OutCC, false, SDValue(), AArch64CC::AL);
- }
- static unsigned getCmpOperandFoldingProfit(SDValue Op) {
- auto isSupportedExtend = [&](SDValue V) {
- if (V.getOpcode() == ISD::SIGN_EXTEND_INREG)
- return true;
- if (V.getOpcode() == ISD::AND)
- if (ConstantSDNode *MaskCst = dyn_cast<ConstantSDNode>(V.getOperand(1))) {
- uint64_t Mask = MaskCst->getZExtValue();
- return (Mask == 0xFF || Mask == 0xFFFF || Mask == 0xFFFFFFFF);
- }
- return false;
- };
- if (!Op.hasOneUse())
- return 0;
- if (isSupportedExtend(Op))
- return 1;
- unsigned Opc = Op.getOpcode();
- if (Opc == ISD::SHL || Opc == ISD::SRL || Opc == ISD::SRA)
- if (ConstantSDNode *ShiftCst = dyn_cast<ConstantSDNode>(Op.getOperand(1))) {
- uint64_t Shift = ShiftCst->getZExtValue();
- if (isSupportedExtend(Op.getOperand(0)))
- return (Shift <= 4) ? 2 : 1;
- EVT VT = Op.getValueType();
- if ((VT == MVT::i32 && Shift <= 31) || (VT == MVT::i64 && Shift <= 63))
- return 1;
- }
- return 0;
- }
- static SDValue getAArch64Cmp(SDValue LHS, SDValue RHS, ISD::CondCode CC,
- SDValue &AArch64cc, SelectionDAG &DAG,
- const SDLoc &dl) {
- if (ConstantSDNode *RHSC = dyn_cast<ConstantSDNode>(RHS.getNode())) {
- EVT VT = RHS.getValueType();
- uint64_t C = RHSC->getZExtValue();
- if (!isLegalArithImmed(C)) {
-
- switch (CC) {
- default:
- break;
- case ISD::SETLT:
- case ISD::SETGE:
- if ((VT == MVT::i32 && C != 0x80000000 &&
- isLegalArithImmed((uint32_t)(C - 1))) ||
- (VT == MVT::i64 && C != 0x80000000ULL &&
- isLegalArithImmed(C - 1ULL))) {
- CC = (CC == ISD::SETLT) ? ISD::SETLE : ISD::SETGT;
- C = (VT == MVT::i32) ? (uint32_t)(C - 1) : C - 1;
- RHS = DAG.getConstant(C, dl, VT);
- }
- break;
- case ISD::SETULT:
- case ISD::SETUGE:
- if ((VT == MVT::i32 && C != 0 &&
- isLegalArithImmed((uint32_t)(C - 1))) ||
- (VT == MVT::i64 && C != 0ULL && isLegalArithImmed(C - 1ULL))) {
- CC = (CC == ISD::SETULT) ? ISD::SETULE : ISD::SETUGT;
- C = (VT == MVT::i32) ? (uint32_t)(C - 1) : C - 1;
- RHS = DAG.getConstant(C, dl, VT);
- }
- break;
- case ISD::SETLE:
- case ISD::SETGT:
- if ((VT == MVT::i32 && C != INT32_MAX &&
- isLegalArithImmed((uint32_t)(C + 1))) ||
- (VT == MVT::i64 && C != INT64_MAX &&
- isLegalArithImmed(C + 1ULL))) {
- CC = (CC == ISD::SETLE) ? ISD::SETLT : ISD::SETGE;
- C = (VT == MVT::i32) ? (uint32_t)(C + 1) : C + 1;
- RHS = DAG.getConstant(C, dl, VT);
- }
- break;
- case ISD::SETULE:
- case ISD::SETUGT:
- if ((VT == MVT::i32 && C != UINT32_MAX &&
- isLegalArithImmed((uint32_t)(C + 1))) ||
- (VT == MVT::i64 && C != UINT64_MAX &&
- isLegalArithImmed(C + 1ULL))) {
- CC = (CC == ISD::SETULE) ? ISD::SETULT : ISD::SETUGE;
- C = (VT == MVT::i32) ? (uint32_t)(C + 1) : C + 1;
- RHS = DAG.getConstant(C, dl, VT);
- }
- break;
- }
- }
- }
-
-
-
-
-
-
-
-
-
-
- if (!isa<ConstantSDNode>(RHS) ||
- !isLegalArithImmed(cast<ConstantSDNode>(RHS)->getZExtValue())) {
- SDValue TheLHS = isCMN(LHS, CC) ? LHS.getOperand(1) : LHS;
- if (getCmpOperandFoldingProfit(TheLHS) > getCmpOperandFoldingProfit(RHS)) {
- std::swap(LHS, RHS);
- CC = ISD::getSetCCSwappedOperands(CC);
- }
- }
- SDValue Cmp;
- AArch64CC::CondCode AArch64CC;
- if ((CC == ISD::SETEQ || CC == ISD::SETNE) && isa<ConstantSDNode>(RHS)) {
- const ConstantSDNode *RHSC = cast<ConstantSDNode>(RHS);
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- if ((RHSC->getZExtValue() >> 16 == 0) && isa<LoadSDNode>(LHS) &&
- cast<LoadSDNode>(LHS)->getExtensionType() == ISD::ZEXTLOAD &&
- cast<LoadSDNode>(LHS)->getMemoryVT() == MVT::i16 &&
- LHS.getNode()->hasNUsesOfValue(1, 0)) {
- int16_t ValueofRHS = cast<ConstantSDNode>(RHS)->getZExtValue();
- if (ValueofRHS < 0 && isLegalArithImmed(-ValueofRHS)) {
- SDValue SExt =
- DAG.getNode(ISD::SIGN_EXTEND_INREG, dl, LHS.getValueType(), LHS,
- DAG.getValueType(MVT::i16));
- Cmp = emitComparison(SExt, DAG.getConstant(ValueofRHS, dl,
- RHS.getValueType()),
- CC, dl, DAG);
- AArch64CC = changeIntCCToAArch64CC(CC);
- }
- }
- if (!Cmp && (RHSC->isNullValue() || RHSC->isOne())) {
- if ((Cmp = emitConjunction(DAG, LHS, AArch64CC))) {
- if ((CC == ISD::SETNE) ^ RHSC->isNullValue())
- AArch64CC = AArch64CC::getInvertedCondCode(AArch64CC);
- }
- }
- }
- if (!Cmp) {
- Cmp = emitComparison(LHS, RHS, CC, dl, DAG);
- AArch64CC = changeIntCCToAArch64CC(CC);
- }
- AArch64cc = DAG.getConstant(AArch64CC, dl, MVT_CC);
- return Cmp;
- }
- static std::pair<SDValue, SDValue>
- getAArch64XALUOOp(AArch64CC::CondCode &CC, SDValue Op, SelectionDAG &DAG) {
- assert((Op.getValueType() == MVT::i32 || Op.getValueType() == MVT::i64) &&
- "Unsupported value type");
- SDValue Value, Overflow;
- SDLoc DL(Op);
- SDValue LHS = Op.getOperand(0);
- SDValue RHS = Op.getOperand(1);
- unsigned Opc = 0;
- switch (Op.getOpcode()) {
- default:
- llvm_unreachable("Unknown overflow instruction!");
- case ISD::SADDO:
- Opc = AArch64ISD::ADDS;
- CC = AArch64CC::VS;
- break;
- case ISD::UADDO:
- Opc = AArch64ISD::ADDS;
- CC = AArch64CC::HS;
- break;
- case ISD::SSUBO:
- Opc = AArch64ISD::SUBS;
- CC = AArch64CC::VS;
- break;
- case ISD::USUBO:
- Opc = AArch64ISD::SUBS;
- CC = AArch64CC::LO;
- break;
-
- case ISD::SMULO:
- case ISD::UMULO: {
- CC = AArch64CC::NE;
- bool IsSigned = Op.getOpcode() == ISD::SMULO;
- if (Op.getValueType() == MVT::i32) {
- unsigned ExtendOpc = IsSigned ? ISD::SIGN_EXTEND : ISD::ZERO_EXTEND;
-
-
-
-
- LHS = DAG.getNode(ExtendOpc, DL, MVT::i64, LHS);
- RHS = DAG.getNode(ExtendOpc, DL, MVT::i64, RHS);
- SDValue Mul = DAG.getNode(ISD::MUL, DL, MVT::i64, LHS, RHS);
- SDValue Add = DAG.getNode(ISD::ADD, DL, MVT::i64, Mul,
- DAG.getConstant(0, DL, MVT::i64));
-
-
-
-
- Value = DAG.getNode(ISD::TRUNCATE, DL, MVT::i32, Add);
- if (IsSigned) {
-
-
-
-
-
- SDValue UpperBits = DAG.getNode(ISD::SRL, DL, MVT::i64, Add,
- DAG.getConstant(32, DL, MVT::i64));
- UpperBits = DAG.getNode(ISD::TRUNCATE, DL, MVT::i32, UpperBits);
- SDValue LowerBits = DAG.getNode(ISD::SRA, DL, MVT::i32, Value,
- DAG.getConstant(31, DL, MVT::i64));
-
-
- SDVTList VTs = DAG.getVTList(MVT::i32, MVT::i32);
- Overflow = DAG.getNode(AArch64ISD::SUBS, DL, VTs, UpperBits, LowerBits)
- .getValue(1);
- } else {
-
-
-
-
-
- SDValue UpperBits = DAG.getNode(ISD::SRL, DL, MVT::i64, Mul,
- DAG.getConstant(32, DL, MVT::i64));
- SDVTList VTs = DAG.getVTList(MVT::i64, MVT::i32);
- Overflow =
- DAG.getNode(AArch64ISD::SUBS, DL, VTs,
- DAG.getConstant(0, DL, MVT::i64),
- UpperBits).getValue(1);
- }
- break;
- }
- assert(Op.getValueType() == MVT::i64 && "Expected an i64 value type");
-
- Value = DAG.getNode(ISD::MUL, DL, MVT::i64, LHS, RHS);
- if (IsSigned) {
- SDValue UpperBits = DAG.getNode(ISD::MULHS, DL, MVT::i64, LHS, RHS);
- SDValue LowerBits = DAG.getNode(ISD::SRA, DL, MVT::i64, Value,
- DAG.getConstant(63, DL, MVT::i64));
-
-
- SDVTList VTs = DAG.getVTList(MVT::i64, MVT::i32);
- Overflow = DAG.getNode(AArch64ISD::SUBS, DL, VTs, UpperBits, LowerBits)
- .getValue(1);
- } else {
- SDValue UpperBits = DAG.getNode(ISD::MULHU, DL, MVT::i64, LHS, RHS);
- SDVTList VTs = DAG.getVTList(MVT::i64, MVT::i32);
- Overflow =
- DAG.getNode(AArch64ISD::SUBS, DL, VTs,
- DAG.getConstant(0, DL, MVT::i64),
- UpperBits).getValue(1);
- }
- break;
- }
- }
- if (Opc) {
- SDVTList VTs = DAG.getVTList(Op->getValueType(0), MVT::i32);
-
- Value = DAG.getNode(Opc, DL, VTs, LHS, RHS);
- Overflow = Value.getValue(1);
- }
- return std::make_pair(Value, Overflow);
- }
- SDValue AArch64TargetLowering::LowerXOR(SDValue Op, SelectionDAG &DAG) const {
- if (useSVEForFixedLengthVectorVT(Op.getValueType()))
- return LowerToScalableOp(Op, DAG);
- SDValue Sel = Op.getOperand(0);
- SDValue Other = Op.getOperand(1);
- SDLoc dl(Sel);
-
-
-
-
-
-
-
- if (isOneConstant(Other) && ISD::isOverflowIntrOpRes(Sel)) {
-
- if (!DAG.getTargetLoweringInfo().isTypeLegal(Sel->getValueType(0)))
- return SDValue();
- SDValue TVal = DAG.getConstant(1, dl, MVT::i32);
- SDValue FVal = DAG.getConstant(0, dl, MVT::i32);
- AArch64CC::CondCode CC;
- SDValue Value, Overflow;
- std::tie(Value, Overflow) = getAArch64XALUOOp(CC, Sel.getValue(0), DAG);
- SDValue CCVal = DAG.getConstant(getInvertedCondCode(CC), dl, MVT::i32);
- return DAG.getNode(AArch64ISD::CSEL, dl, Op.getValueType(), TVal, FVal,
- CCVal, Overflow);
- }
-
- if (Sel.getOpcode() != ISD::SELECT_CC)
- std::swap(Sel, Other);
- if (Sel.getOpcode() != ISD::SELECT_CC)
- return Op;
-
-
-
-
-
-
- ISD::CondCode CC = cast<CondCodeSDNode>(Sel.getOperand(4))->get();
- SDValue LHS = Sel.getOperand(0);
- SDValue RHS = Sel.getOperand(1);
- SDValue TVal = Sel.getOperand(2);
- SDValue FVal = Sel.getOperand(3);
-
- if (LHS.getValueType() != MVT::i32 && LHS.getValueType() != MVT::i64)
- return Op;
- ConstantSDNode *CFVal = dyn_cast<ConstantSDNode>(FVal);
- ConstantSDNode *CTVal = dyn_cast<ConstantSDNode>(TVal);
-
- if (!CFVal || !CTVal)
- return Op;
-
-
- if (CTVal->isAllOnesValue() && CFVal->isNullValue()) {
- std::swap(TVal, FVal);
- std::swap(CTVal, CFVal);
- CC = ISD::getSetCCInverse(CC, LHS.getValueType());
- }
-
- if (CTVal->isNullValue() && CFVal->isAllOnesValue()) {
- SDValue CCVal;
- SDValue Cmp = getAArch64Cmp(LHS, RHS, CC, CCVal, DAG, dl);
- FVal = Other;
- TVal = DAG.getNode(ISD::XOR, dl, Other.getValueType(), Other,
- DAG.getConstant(-1ULL, dl, Other.getValueType()));
- return DAG.getNode(AArch64ISD::CSEL, dl, Sel.getValueType(), FVal, TVal,
- CCVal, Cmp);
- }
- return Op;
- }
- static SDValue LowerADDC_ADDE_SUBC_SUBE(SDValue Op, SelectionDAG &DAG) {
- EVT VT = Op.getValueType();
-
- if (!DAG.getTargetLoweringInfo().isTypeLegal(VT))
- return SDValue();
- SDVTList VTs = DAG.getVTList(VT, MVT::i32);
- unsigned Opc;
- bool ExtraOp = false;
- switch (Op.getOpcode()) {
- default:
- llvm_unreachable("Invalid code");
- case ISD::ADDC:
- Opc = AArch64ISD::ADDS;
- break;
- case ISD::SUBC:
- Opc = AArch64ISD::SUBS;
- break;
- case ISD::ADDE:
- Opc = AArch64ISD::ADCS;
- ExtraOp = true;
- break;
- case ISD::SUBE:
- Opc = AArch64ISD::SBCS;
- ExtraOp = true;
- break;
- }
- if (!ExtraOp)
- return DAG.getNode(Opc, SDLoc(Op), VTs, Op.getOperand(0), Op.getOperand(1));
- return DAG.getNode(Opc, SDLoc(Op), VTs, Op.getOperand(0), Op.getOperand(1),
- Op.getOperand(2));
- }
- static SDValue LowerXALUO(SDValue Op, SelectionDAG &DAG) {
-
- if (!DAG.getTargetLoweringInfo().isTypeLegal(Op.getValueType()))
- return SDValue();
- SDLoc dl(Op);
- AArch64CC::CondCode CC;
-
- SDValue Value, Overflow;
- std::tie(Value, Overflow) = getAArch64XALUOOp(CC, Op, DAG);
-
- SDValue TVal = DAG.getConstant(1, dl, MVT::i32);
- SDValue FVal = DAG.getConstant(0, dl, MVT::i32);
-
-
-
- SDValue CCVal = DAG.getConstant(getInvertedCondCode(CC), dl, MVT::i32);
- Overflow = DAG.getNode(AArch64ISD::CSEL, dl, MVT::i32, FVal, TVal,
- CCVal, Overflow);
- SDVTList VTs = DAG.getVTList(Op.getValueType(), MVT::i32);
- return DAG.getNode(ISD::MERGE_VALUES, dl, VTs, Value, Overflow);
- }
- static SDValue LowerPREFETCH(SDValue Op, SelectionDAG &DAG) {
- SDLoc DL(Op);
- unsigned IsWrite = cast<ConstantSDNode>(Op.getOperand(2))->getZExtValue();
- unsigned Locality = cast<ConstantSDNode>(Op.getOperand(3))->getZExtValue();
- unsigned IsData = cast<ConstantSDNode>(Op.getOperand(4))->getZExtValue();
- bool IsStream = !Locality;
-
- if (Locality) {
-
- assert(Locality <= 3 && "Prefetch locality out-of-range");
-
-
-
- Locality = 3 - Locality;
- }
-
- unsigned PrfOp = (IsWrite << 4) |
- (!IsData << 3) |
- (Locality << 1) |
- (unsigned)IsStream;
- return DAG.getNode(AArch64ISD::PREFETCH, DL, MVT::Other, Op.getOperand(0),
- DAG.getConstant(PrfOp, DL, MVT::i32), Op.getOperand(1));
- }
- SDValue AArch64TargetLowering::LowerFP_EXTEND(SDValue Op,
- SelectionDAG &DAG) const {
- if (Op.getValueType().isScalableVector())
- return LowerToPredicatedOp(Op, DAG, AArch64ISD::FP_EXTEND_MERGE_PASSTHRU);
- assert(Op.getValueType() == MVT::f128 && "Unexpected lowering");
- return SDValue();
- }
- SDValue AArch64TargetLowering::LowerFP_ROUND(SDValue Op,
- SelectionDAG &DAG) const {
- if (Op.getValueType().isScalableVector())
- return LowerToPredicatedOp(Op, DAG, AArch64ISD::FP_ROUND_MERGE_PASSTHRU);
- bool IsStrict = Op->isStrictFPOpcode();
- SDValue SrcVal = Op.getOperand(IsStrict ? 1 : 0);
- EVT SrcVT = SrcVal.getValueType();
- if (SrcVT != MVT::f128) {
-
- if (useSVEForFixedLengthVectorVT(SrcVT))
- return SDValue();
-
- return Op;
- }
- return SDValue();
- }
- SDValue AArch64TargetLowering::LowerVectorFP_TO_INT(SDValue Op,
- SelectionDAG &DAG) const {
-
-
-
- EVT InVT = Op.getOperand(0).getValueType();
- EVT VT = Op.getValueType();
- if (VT.isScalableVector()) {
- unsigned Opcode = Op.getOpcode() == ISD::FP_TO_UINT
- ? AArch64ISD::FCVTZU_MERGE_PASSTHRU
- : AArch64ISD::FCVTZS_MERGE_PASSTHRU;
- return LowerToPredicatedOp(Op, DAG, Opcode);
- }
- unsigned NumElts = InVT.getVectorNumElements();
-
- if (InVT.getVectorElementType() == MVT::f16 &&
- !Subtarget->hasFullFP16()) {
- MVT NewVT = MVT::getVectorVT(MVT::f32, NumElts);
- SDLoc dl(Op);
- return DAG.getNode(
- Op.getOpcode(), dl, Op.getValueType(),
- DAG.getNode(ISD::FP_EXTEND, dl, NewVT, Op.getOperand(0)));
- }
- uint64_t VTSize = VT.getFixedSizeInBits();
- uint64_t InVTSize = InVT.getFixedSizeInBits();
- if (VTSize < InVTSize) {
- SDLoc dl(Op);
- SDValue Cv =
- DAG.getNode(Op.getOpcode(), dl, InVT.changeVectorElementTypeToInteger(),
- Op.getOperand(0));
- return DAG.getNode(ISD::TRUNCATE, dl, VT, Cv);
- }
- if (VTSize > InVTSize) {
- SDLoc dl(Op);
- MVT ExtVT =
- MVT::getVectorVT(MVT::getFloatingPointVT(VT.getScalarSizeInBits()),
- VT.getVectorNumElements());
- SDValue Ext = DAG.getNode(ISD::FP_EXTEND, dl, ExtVT, Op.getOperand(0));
- return DAG.getNode(Op.getOpcode(), dl, VT, Ext);
- }
-
- return Op;
- }
- SDValue AArch64TargetLowering::LowerFP_TO_INT(SDValue Op,
- SelectionDAG &DAG) const {
- bool IsStrict = Op->isStrictFPOpcode();
- SDValue SrcVal = Op.getOperand(IsStrict ? 1 : 0);
- if (SrcVal.getValueType().isVector())
- return LowerVectorFP_TO_INT(Op, DAG);
-
- if (SrcVal.getValueType() == MVT::f16 && !Subtarget->hasFullFP16()) {
- assert(!IsStrict && "Lowering of strict fp16 not yet implemented");
- SDLoc dl(Op);
- return DAG.getNode(
- Op.getOpcode(), dl, Op.getValueType(),
- DAG.getNode(ISD::FP_EXTEND, dl, MVT::f32, SrcVal));
- }
- if (SrcVal.getValueType() != MVT::f128) {
-
- return Op;
- }
- return SDValue();
- }
- SDValue AArch64TargetLowering::LowerVectorINT_TO_FP(SDValue Op,
- SelectionDAG &DAG) const {
-
-
-
- EVT VT = Op.getValueType();
- SDLoc dl(Op);
- SDValue In = Op.getOperand(0);
- EVT InVT = In.getValueType();
- unsigned Opc = Op.getOpcode();
- bool IsSigned = Opc == ISD::SINT_TO_FP || Opc == ISD::STRICT_SINT_TO_FP;
- if (VT.isScalableVector()) {
- if (InVT.getVectorElementType() == MVT::i1) {
-
- unsigned CastOpc = IsSigned ? ISD::SIGN_EXTEND : ISD::ZERO_EXTEND;
- EVT CastVT = getPromotedVTForPredicate(InVT);
- In = DAG.getNode(CastOpc, dl, CastVT, In);
- return DAG.getNode(Opc, dl, VT, In);
- }
- unsigned Opcode = IsSigned ? AArch64ISD::SINT_TO_FP_MERGE_PASSTHRU
- : AArch64ISD::UINT_TO_FP_MERGE_PASSTHRU;
- return LowerToPredicatedOp(Op, DAG, Opcode);
- }
- uint64_t VTSize = VT.getFixedSizeInBits();
- uint64_t InVTSize = InVT.getFixedSizeInBits();
- if (VTSize < InVTSize) {
- MVT CastVT =
- MVT::getVectorVT(MVT::getFloatingPointVT(InVT.getScalarSizeInBits()),
- InVT.getVectorNumElements());
- In = DAG.getNode(Opc, dl, CastVT, In);
- return DAG.getNode(ISD::FP_ROUND, dl, VT, In, DAG.getIntPtrConstant(0, dl));
- }
- if (VTSize > InVTSize) {
- unsigned CastOpc = IsSigned ? ISD::SIGN_EXTEND : ISD::ZERO_EXTEND;
- EVT CastVT = VT.changeVectorElementTypeToInteger();
- In = DAG.getNode(CastOpc, dl, CastVT, In);
- return DAG.getNode(Opc, dl, VT, In);
- }
- return Op;
- }
- SDValue AArch64TargetLowering::LowerINT_TO_FP(SDValue Op,
- SelectionDAG &DAG) const {
- if (Op.getValueType().isVector())
- return LowerVectorINT_TO_FP(Op, DAG);
- bool IsStrict = Op->isStrictFPOpcode();
- SDValue SrcVal = Op.getOperand(IsStrict ? 1 : 0);
-
- if (Op.getValueType() == MVT::f16 &&
- !Subtarget->hasFullFP16()) {
- assert(!IsStrict && "Lowering of strict fp16 not yet implemented");
- SDLoc dl(Op);
- return DAG.getNode(
- ISD::FP_ROUND, dl, MVT::f16,
- DAG.getNode(Op.getOpcode(), dl, MVT::f32, SrcVal),
- DAG.getIntPtrConstant(0, dl));
- }
-
- if (SrcVal.getValueType() == MVT::i128)
- return SDValue();
-
-
- if (Op.getValueType() != MVT::f128)
- return Op;
- return SDValue();
- }
- SDValue AArch64TargetLowering::LowerFSINCOS(SDValue Op,
- SelectionDAG &DAG) const {
-
-
- SDLoc dl(Op);
- SDValue Arg = Op.getOperand(0);
- EVT ArgVT = Arg.getValueType();
- Type *ArgTy = ArgVT.getTypeForEVT(*DAG.getContext());
- ArgListTy Args;
- ArgListEntry Entry;
- Entry.Node = Arg;
- Entry.Ty = ArgTy;
- Entry.IsSExt = false;
- Entry.IsZExt = false;
- Args.push_back(Entry);
- RTLIB::Libcall LC = ArgVT == MVT::f64 ? RTLIB::SINCOS_STRET_F64
- : RTLIB::SINCOS_STRET_F32;
- const char *LibcallName = getLibcallName(LC);
- SDValue Callee =
- DAG.getExternalSymbol(LibcallName, getPointerTy(DAG.getDataLayout()));
- StructType *RetTy = StructType::get(ArgTy, ArgTy);
- TargetLowering::CallLoweringInfo CLI(DAG);
- CLI.setDebugLoc(dl)
- .setChain(DAG.getEntryNode())
- .setLibCallee(CallingConv::Fast, RetTy, Callee, std::move(Args));
- std::pair<SDValue, SDValue> CallResult = LowerCallTo(CLI);
- return CallResult.first;
- }
- static SDValue LowerBITCAST(SDValue Op, SelectionDAG &DAG) {
- EVT OpVT = Op.getValueType();
- if (OpVT != MVT::f16 && OpVT != MVT::bf16)
- return SDValue();
- assert(Op.getOperand(0).getValueType() == MVT::i16);
- SDLoc DL(Op);
- Op = DAG.getNode(ISD::ANY_EXTEND, DL, MVT::i32, Op.getOperand(0));
- Op = DAG.getNode(ISD::BITCAST, DL, MVT::f32, Op);
- return SDValue(
- DAG.getMachineNode(TargetOpcode::EXTRACT_SUBREG, DL, OpVT, Op,
- DAG.getTargetConstant(AArch64::hsub, DL, MVT::i32)),
- 0);
- }
- static EVT getExtensionTo64Bits(const EVT &OrigVT) {
- if (OrigVT.getSizeInBits() >= 64)
- return OrigVT;
- assert(OrigVT.isSimple() && "Expecting a simple value type");
- MVT::SimpleValueType OrigSimpleTy = OrigVT.getSimpleVT().SimpleTy;
- switch (OrigSimpleTy) {
- default: llvm_unreachable("Unexpected Vector Type");
- case MVT::v2i8:
- case MVT::v2i16:
- return MVT::v2i32;
- case MVT::v4i8:
- return MVT::v4i16;
- }
- }
- static SDValue addRequiredExtensionForVectorMULL(SDValue N, SelectionDAG &DAG,
- const EVT &OrigTy,
- const EVT &ExtTy,
- unsigned ExtOpcode) {
-
-
-
- assert(ExtTy.is128BitVector() && "Unexpected extension size");
- if (OrigTy.getSizeInBits() >= 64)
- return N;
-
- EVT NewVT = getExtensionTo64Bits(OrigTy);
- return DAG.getNode(ExtOpcode, SDLoc(N), NewVT, N);
- }
- static bool isExtendedBUILD_VECTOR(SDNode *N, SelectionDAG &DAG,
- bool isSigned) {
- EVT VT = N->getValueType(0);
- if (N->getOpcode() != ISD::BUILD_VECTOR)
- return false;
- for (const SDValue &Elt : N->op_values()) {
- if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Elt)) {
- unsigned EltSize = VT.getScalarSizeInBits();
- unsigned HalfSize = EltSize / 2;
- if (isSigned) {
- if (!isIntN(HalfSize, C->getSExtValue()))
- return false;
- } else {
- if (!isUIntN(HalfSize, C->getZExtValue()))
- return false;
- }
- continue;
- }
- return false;
- }
- return true;
- }
- static SDValue skipExtensionForVectorMULL(SDNode *N, SelectionDAG &DAG) {
- if (N->getOpcode() == ISD::SIGN_EXTEND ||
- N->getOpcode() == ISD::ZERO_EXTEND || N->getOpcode() == ISD::ANY_EXTEND)
- return addRequiredExtensionForVectorMULL(N->getOperand(0), DAG,
- N->getOperand(0)->getValueType(0),
- N->getValueType(0),
- N->getOpcode());
- assert(N->getOpcode() == ISD::BUILD_VECTOR && "expected BUILD_VECTOR");
- EVT VT = N->getValueType(0);
- SDLoc dl(N);
- unsigned EltSize = VT.getScalarSizeInBits() / 2;
- unsigned NumElts = VT.getVectorNumElements();
- MVT TruncVT = MVT::getIntegerVT(EltSize);
- SmallVector<SDValue, 8> Ops;
- for (unsigned i = 0; i != NumElts; ++i) {
- ConstantSDNode *C = cast<ConstantSDNode>(N->getOperand(i));
- const APInt &CInt = C->getAPIntValue();
-
-
- Ops.push_back(DAG.getConstant(CInt.zextOrTrunc(32), dl, MVT::i32));
- }
- return DAG.getBuildVector(MVT::getVectorVT(TruncVT, NumElts), dl, Ops);
- }
- static bool isSignExtended(SDNode *N, SelectionDAG &DAG) {
- return N->getOpcode() == ISD::SIGN_EXTEND ||
- N->getOpcode() == ISD::ANY_EXTEND ||
- isExtendedBUILD_VECTOR(N, DAG, true);
- }
- static bool isZeroExtended(SDNode *N, SelectionDAG &DAG) {
- return N->getOpcode() == ISD::ZERO_EXTEND ||
- N->getOpcode() == ISD::ANY_EXTEND ||
- isExtendedBUILD_VECTOR(N, DAG, false);
- }
- static bool isAddSubSExt(SDNode *N, SelectionDAG &DAG) {
- unsigned Opcode = N->getOpcode();
- if (Opcode == ISD::ADD || Opcode == ISD::SUB) {
- SDNode *N0 = N->getOperand(0).getNode();
- SDNode *N1 = N->getOperand(1).getNode();
- return N0->hasOneUse() && N1->hasOneUse() &&
- isSignExtended(N0, DAG) && isSignExtended(N1, DAG);
- }
- return false;
- }
- static bool isAddSubZExt(SDNode *N, SelectionDAG &DAG) {
- unsigned Opcode = N->getOpcode();
- if (Opcode == ISD::ADD || Opcode == ISD::SUB) {
- SDNode *N0 = N->getOperand(0).getNode();
- SDNode *N1 = N->getOperand(1).getNode();
- return N0->hasOneUse() && N1->hasOneUse() &&
- isZeroExtended(N0, DAG) && isZeroExtended(N1, DAG);
- }
- return false;
- }
- SDValue AArch64TargetLowering::LowerFLT_ROUNDS_(SDValue Op,
- SelectionDAG &DAG) const {
-
-
-
-
- SDLoc dl(Op);
- SDValue Chain = Op.getOperand(0);
- SDValue FPCR_64 = DAG.getNode(
- ISD::INTRINSIC_W_CHAIN, dl, {MVT::i64, MVT::Other},
- {Chain, DAG.getConstant(Intrinsic::aarch64_get_fpcr, dl, MVT::i64)});
- Chain = FPCR_64.getValue(1);
- SDValue FPCR_32 = DAG.getNode(ISD::TRUNCATE, dl, MVT::i32, FPCR_64);
- SDValue FltRounds = DAG.getNode(ISD::ADD, dl, MVT::i32, FPCR_32,
- DAG.getConstant(1U << 22, dl, MVT::i32));
- SDValue RMODE = DAG.getNode(ISD::SRL, dl, MVT::i32, FltRounds,
- DAG.getConstant(22, dl, MVT::i32));
- SDValue AND = DAG.getNode(ISD::AND, dl, MVT::i32, RMODE,
- DAG.getConstant(3, dl, MVT::i32));
- return DAG.getMergeValues({AND, Chain}, dl);
- }
- SDValue AArch64TargetLowering::LowerMUL(SDValue Op, SelectionDAG &DAG) const {
- EVT VT = Op.getValueType();
-
- bool OverrideNEON = VT == MVT::v2i64 || VT == MVT::v1i64;
- if (VT.isScalableVector() || useSVEForFixedLengthVectorVT(VT, OverrideNEON))
- return LowerToPredicatedOp(Op, DAG, AArch64ISD::MUL_PRED, OverrideNEON);
-
-
- assert(VT.is128BitVector() && VT.isInteger() &&
- "unexpected type for custom-lowering ISD::MUL");
- SDNode *N0 = Op.getOperand(0).getNode();
- SDNode *N1 = Op.getOperand(1).getNode();
- unsigned NewOpc = 0;
- bool isMLA = false;
- bool isN0SExt = isSignExtended(N0, DAG);
- bool isN1SExt = isSignExtended(N1, DAG);
- if (isN0SExt && isN1SExt)
- NewOpc = AArch64ISD::SMULL;
- else {
- bool isN0ZExt = isZeroExtended(N0, DAG);
- bool isN1ZExt = isZeroExtended(N1, DAG);
- if (isN0ZExt && isN1ZExt)
- NewOpc = AArch64ISD::UMULL;
- else if (isN1SExt || isN1ZExt) {
-
-
- if (isN1SExt && isAddSubSExt(N0, DAG)) {
- NewOpc = AArch64ISD::SMULL;
- isMLA = true;
- } else if (isN1ZExt && isAddSubZExt(N0, DAG)) {
- NewOpc = AArch64ISD::UMULL;
- isMLA = true;
- } else if (isN0ZExt && isAddSubZExt(N1, DAG)) {
- std::swap(N0, N1);
- NewOpc = AArch64ISD::UMULL;
- isMLA = true;
- }
- }
- if (!NewOpc) {
- if (VT == MVT::v2i64)
-
- return SDValue();
- else
-
- return Op;
- }
- }
-
- SDLoc DL(Op);
- SDValue Op0;
- SDValue Op1 = skipExtensionForVectorMULL(N1, DAG);
- if (!isMLA) {
- Op0 = skipExtensionForVectorMULL(N0, DAG);
- assert(Op0.getValueType().is64BitVector() &&
- Op1.getValueType().is64BitVector() &&
- "unexpected types for extended operands to VMULL");
- return DAG.getNode(NewOpc, DL, VT, Op0, Op1);
- }
-
-
-
- SDValue N00 = skipExtensionForVectorMULL(N0->getOperand(0).getNode(), DAG);
- SDValue N01 = skipExtensionForVectorMULL(N0->getOperand(1).getNode(), DAG);
- EVT Op1VT = Op1.getValueType();
- return DAG.getNode(N0->getOpcode(), DL, VT,
- DAG.getNode(NewOpc, DL, VT,
- DAG.getNode(ISD::BITCAST, DL, Op1VT, N00), Op1),
- DAG.getNode(NewOpc, DL, VT,
- DAG.getNode(ISD::BITCAST, DL, Op1VT, N01), Op1));
- }
- static inline SDValue getPTrue(SelectionDAG &DAG, SDLoc DL, EVT VT,
- int Pattern) {
- return DAG.getNode(AArch64ISD::PTRUE, DL, VT,
- DAG.getTargetConstant(Pattern, DL, MVT::i32));
- }
- SDValue AArch64TargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op,
- SelectionDAG &DAG) const {
- unsigned IntNo = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue();
- SDLoc dl(Op);
- switch (IntNo) {
- default: return SDValue();
- case Intrinsic::thread_pointer: {
- EVT PtrVT = getPointerTy(DAG.getDataLayout());
- return DAG.getNode(AArch64ISD::THREAD_POINTER, dl, PtrVT);
- }
- case Intrinsic::aarch64_neon_abs: {
- EVT Ty = Op.getValueType();
- if (Ty == MVT::i64) {
- SDValue Result = DAG.getNode(ISD::BITCAST, dl, MVT::v1i64,
- Op.getOperand(1));
- Result = DAG.getNode(ISD::ABS, dl, MVT::v1i64, Result);
- return DAG.getNode(ISD::BITCAST, dl, MVT::i64, Result);
- } else if (Ty.isVector() && Ty.isInteger() && isTypeLegal(Ty)) {
- return DAG.getNode(ISD::ABS, dl, Ty, Op.getOperand(1));
- } else {
- report_fatal_error("Unexpected type for AArch64 NEON intrinic");
- }
- }
- case Intrinsic::aarch64_neon_smax:
- return DAG.getNode(ISD::SMAX, dl, Op.getValueType(),
- Op.getOperand(1), Op.getOperand(2));
- case Intrinsic::aarch64_neon_umax:
- return DAG.getNode(ISD::UMAX, dl, Op.getValueType(),
- Op.getOperand(1), Op.getOperand(2));
- case Intrinsic::aarch64_neon_smin:
- return DAG.getNode(ISD::SMIN, dl, Op.getValueType(),
- Op.getOperand(1), Op.getOperand(2));
- case Intrinsic::aarch64_neon_umin:
- return DAG.getNode(ISD::UMIN, dl, Op.getValueType(),
- Op.getOperand(1), Op.getOperand(2));
- case Intrinsic::aarch64_sve_sunpkhi:
- return DAG.getNode(AArch64ISD::SUNPKHI, dl, Op.getValueType(),
- Op.getOperand(1));
- case Intrinsic::aarch64_sve_sunpklo:
- return DAG.getNode(AArch64ISD::SUNPKLO, dl, Op.getValueType(),
- Op.getOperand(1));
- case Intrinsic::aarch64_sve_uunpkhi:
- return DAG.getNode(AArch64ISD::UUNPKHI, dl, Op.getValueType(),
- Op.getOperand(1));
- case Intrinsic::aarch64_sve_uunpklo:
- return DAG.getNode(AArch64ISD::UUNPKLO, dl, Op.getValueType(),
- Op.getOperand(1));
- case Intrinsic::aarch64_sve_clasta_n:
- return DAG.getNode(AArch64ISD::CLASTA_N, dl, Op.getValueType(),
- Op.getOperand(1), Op.getOperand(2), Op.getOperand(3));
- case Intrinsic::aarch64_sve_clastb_n:
- return DAG.getNode(AArch64ISD::CLASTB_N, dl, Op.getValueType(),
- Op.getOperand(1), Op.getOperand(2), Op.getOperand(3));
- case Intrinsic::aarch64_sve_lasta:
- return DAG.getNode(AArch64ISD::LASTA, dl, Op.getValueType(),
- Op.getOperand(1), Op.getOperand(2));
- case Intrinsic::aarch64_sve_lastb:
- return DAG.getNode(AArch64ISD::LASTB, dl, Op.getValueType(),
- Op.getOperand(1), Op.getOperand(2));
- case Intrinsic::aarch64_sve_rev:
- return DAG.getNode(AArch64ISD::REV, dl, Op.getValueType(),
- Op.getOperand(1));
- case Intrinsic::aarch64_sve_tbl:
- return DAG.getNode(AArch64ISD::TBL, dl, Op.getValueType(),
- Op.getOperand(1), Op.getOperand(2));
- case Intrinsic::aarch64_sve_trn1:
- return DAG.getNode(AArch64ISD::TRN1, dl, Op.getValueType(),
- Op.getOperand(1), Op.getOperand(2));
- case Intrinsic::aarch64_sve_trn2:
- return DAG.getNode(AArch64ISD::TRN2, dl, Op.getValueType(),
- Op.getOperand(1), Op.getOperand(2));
- case Intrinsic::aarch64_sve_uzp1:
- return DAG.getNode(AArch64ISD::UZP1, dl, Op.getValueType(),
- Op.getOperand(1), Op.getOperand(2));
- case Intrinsic::aarch64_sve_uzp2:
- return DAG.getNode(AArch64ISD::UZP2, dl, Op.getValueType(),
- Op.getOperand(1), Op.getOperand(2));
- case Intrinsic::aarch64_sve_zip1:
- return DAG.getNode(AArch64ISD::ZIP1, dl, Op.getValueType(),
- Op.getOperand(1), Op.getOperand(2));
- case Intrinsic::aarch64_sve_zip2:
- return DAG.getNode(AArch64ISD::ZIP2, dl, Op.getValueType(),
- Op.getOperand(1), Op.getOperand(2));
- case Intrinsic::aarch64_sve_ptrue:
- return DAG.getNode(AArch64ISD::PTRUE, dl, Op.getValueType(),
- Op.getOperand(1));
- case Intrinsic::aarch64_sve_clz:
- return DAG.getNode(AArch64ISD::CTLZ_MERGE_PASSTHRU, dl, Op.getValueType(),
- Op.getOperand(2), Op.getOperand(3), Op.getOperand(1));
- case Intrinsic::aarch64_sve_cnt: {
- SDValue Data = Op.getOperand(3);
-
- if (Data.getValueType().isFloatingPoint())
- Data = DAG.getNode(ISD::BITCAST, dl, Op.getValueType(), Data);
- return DAG.getNode(AArch64ISD::CTPOP_MERGE_PASSTHRU, dl, Op.getValueType(),
- Op.getOperand(2), Data, Op.getOperand(1));
- }
- case Intrinsic::aarch64_sve_dupq_lane:
- return LowerDUPQLane(Op, DAG);
- case Intrinsic::aarch64_sve_convert_from_svbool:
- return DAG.getNode(AArch64ISD::REINTERPRET_CAST, dl, Op.getValueType(),
- Op.getOperand(1));
- case Intrinsic::aarch64_sve_fneg:
- return DAG.getNode(AArch64ISD::FNEG_MERGE_PASSTHRU, dl, Op.getValueType(),
- Op.getOperand(2), Op.getOperand(3), Op.getOperand(1));
- case Intrinsic::aarch64_sve_frintp:
- return DAG.getNode(AArch64ISD::FCEIL_MERGE_PASSTHRU, dl, Op.getValueType(),
- Op.getOperand(2), Op.getOperand(3), Op.getOperand(1));
- case Intrinsic::aarch64_sve_frintm:
- return DAG.getNode(AArch64ISD::FFLOOR_MERGE_PASSTHRU, dl, Op.getValueType(),
- Op.getOperand(2), Op.getOperand(3), Op.getOperand(1));
- case Intrinsic::aarch64_sve_frinti:
- return DAG.getNode(AArch64ISD::FNEARBYINT_MERGE_PASSTHRU, dl, Op.getValueType(),
- Op.getOperand(2), Op.getOperand(3), Op.getOperand(1));
- case Intrinsic::aarch64_sve_frintx:
- return DAG.getNode(AArch64ISD::FRINT_MERGE_PASSTHRU, dl, Op.getValueType(),
- Op.getOperand(2), Op.getOperand(3), Op.getOperand(1));
- case Intrinsic::aarch64_sve_frinta:
- return DAG.getNode(AArch64ISD::FROUND_MERGE_PASSTHRU, dl, Op.getValueType(),
- Op.getOperand(2), Op.getOperand(3), Op.getOperand(1));
- case Intrinsic::aarch64_sve_frintn:
- return DAG.getNode(AArch64ISD::FROUNDEVEN_MERGE_PASSTHRU, dl, Op.getValueType(),
- Op.getOperand(2), Op.getOperand(3), Op.getOperand(1));
- case Intrinsic::aarch64_sve_frintz:
- return DAG.getNode(AArch64ISD::FTRUNC_MERGE_PASSTHRU, dl, Op.getValueType(),
- Op.getOperand(2), Op.getOperand(3), Op.getOperand(1));
- case Intrinsic::aarch64_sve_ucvtf:
- return DAG.getNode(AArch64ISD::UINT_TO_FP_MERGE_PASSTHRU, dl,
- Op.getValueType(), Op.getOperand(2), Op.getOperand(3),
- Op.getOperand(1));
- case Intrinsic::aarch64_sve_scvtf:
- return DAG.getNode(AArch64ISD::SINT_TO_FP_MERGE_PASSTHRU, dl,
- Op.getValueType(), Op.getOperand(2), Op.getOperand(3),
- Op.getOperand(1));
- case Intrinsic::aarch64_sve_fcvtzu:
- return DAG.getNode(AArch64ISD::FCVTZU_MERGE_PASSTHRU, dl,
- Op.getValueType(), Op.getOperand(2), Op.getOperand(3),
- Op.getOperand(1));
- case Intrinsic::aarch64_sve_fcvtzs:
- return DAG.getNode(AArch64ISD::FCVTZS_MERGE_PASSTHRU, dl,
- Op.getValueType(), Op.getOperand(2), Op.getOperand(3),
- Op.getOperand(1));
- case Intrinsic::aarch64_sve_fsqrt:
- return DAG.getNode(AArch64ISD::FSQRT_MERGE_PASSTHRU, dl, Op.getValueType(),
- Op.getOperand(2), Op.getOperand(3), Op.getOperand(1));
- case Intrinsic::aarch64_sve_frecpx:
- return DAG.getNode(AArch64ISD::FRECPX_MERGE_PASSTHRU, dl, Op.getValueType(),
- Op.getOperand(2), Op.getOperand(3), Op.getOperand(1));
- case Intrinsic::aarch64_sve_fabs:
- return DAG.getNode(AArch64ISD::FABS_MERGE_PASSTHRU, dl, Op.getValueType(),
- Op.getOperand(2), Op.getOperand(3), Op.getOperand(1));
- case Intrinsic::aarch64_sve_abs:
- return DAG.getNode(AArch64ISD::ABS_MERGE_PASSTHRU, dl, Op.getValueType(),
- Op.getOperand(2), Op.getOperand(3), Op.getOperand(1));
- case Intrinsic::aarch64_sve_neg:
- return DAG.getNode(AArch64ISD::NEG_MERGE_PASSTHRU, dl, Op.getValueType(),
- Op.getOperand(2), Op.getOperand(3), Op.getOperand(1));
- case Intrinsic::aarch64_sve_convert_to_svbool: {
- EVT OutVT = Op.getValueType();
- EVT InVT = Op.getOperand(1).getValueType();
-
-
- if (InVT == OutVT)
- return Op.getOperand(1);
-
- SDValue Reinterpret =
- DAG.getNode(AArch64ISD::REINTERPRET_CAST, dl, OutVT, Op.getOperand(1));
- SDValue Mask = getPTrue(DAG, dl, InVT, AArch64SVEPredPattern::all);
- SDValue MaskReinterpret =
- DAG.getNode(AArch64ISD::REINTERPRET_CAST, dl, OutVT, Mask);
- return DAG.getNode(ISD::AND, dl, OutVT, Reinterpret, MaskReinterpret);
- }
- case Intrinsic::aarch64_sve_insr: {
- SDValue Scalar = Op.getOperand(2);
- EVT ScalarTy = Scalar.getValueType();
- if ((ScalarTy == MVT::i8) || (ScalarTy == MVT::i16))
- Scalar = DAG.getNode(ISD::ANY_EXTEND, dl, MVT::i32, Scalar);
- return DAG.getNode(AArch64ISD::INSR, dl, Op.getValueType(),
- Op.getOperand(1), Scalar);
- }
- case Intrinsic::aarch64_sve_rbit:
- return DAG.getNode(AArch64ISD::BITREVERSE_MERGE_PASSTHRU, dl,
- Op.getValueType(), Op.getOperand(2), Op.getOperand(3),
- Op.getOperand(1));
- case Intrinsic::aarch64_sve_revb:
- return DAG.getNode(AArch64ISD::BSWAP_MERGE_PASSTHRU, dl, Op.getValueType(),
- Op.getOperand(2), Op.getOperand(3), Op.getOperand(1));
- case Intrinsic::aarch64_sve_sxtb:
- return DAG.getNode(
- AArch64ISD::SIGN_EXTEND_INREG_MERGE_PASSTHRU, dl, Op.getValueType(),
- Op.getOperand(2), Op.getOperand(3),
- DAG.getValueType(Op.getValueType().changeVectorElementType(MVT::i8)),
- Op.getOperand(1));
- case Intrinsic::aarch64_sve_sxth:
- return DAG.getNode(
- AArch64ISD::SIGN_EXTEND_INREG_MERGE_PASSTHRU, dl, Op.getValueType(),
- Op.getOperand(2), Op.getOperand(3),
- DAG.getValueType(Op.getValueType().changeVectorElementType(MVT::i16)),
- Op.getOperand(1));
- case Intrinsic::aarch64_sve_sxtw:
- return DAG.getNode(
- AArch64ISD::SIGN_EXTEND_INREG_MERGE_PASSTHRU, dl, Op.getValueType(),
- Op.getOperand(2), Op.getOperand(3),
- DAG.getValueType(Op.getValueType().changeVectorElementType(MVT::i32)),
- Op.getOperand(1));
- case Intrinsic::aarch64_sve_uxtb:
- return DAG.getNode(
- AArch64ISD::ZERO_EXTEND_INREG_MERGE_PASSTHRU, dl, Op.getValueType(),
- Op.getOperand(2), Op.getOperand(3),
- DAG.getValueType(Op.getValueType().changeVectorElementType(MVT::i8)),
- Op.getOperand(1));
- case Intrinsic::aarch64_sve_uxth:
- return DAG.getNode(
- AArch64ISD::ZERO_EXTEND_INREG_MERGE_PASSTHRU, dl, Op.getValueType(),
- Op.getOperand(2), Op.getOperand(3),
- DAG.getValueType(Op.getValueType().changeVectorElementType(MVT::i16)),
- Op.getOperand(1));
- case Intrinsic::aarch64_sve_uxtw:
- return DAG.getNode(
- AArch64ISD::ZERO_EXTEND_INREG_MERGE_PASSTHRU, dl, Op.getValueType(),
- Op.getOperand(2), Op.getOperand(3),
- DAG.getValueType(Op.getValueType().changeVectorElementType(MVT::i32)),
- Op.getOperand(1));
- case Intrinsic::localaddress: {
- const auto &MF = DAG.getMachineFunction();
- const auto *RegInfo = Subtarget->getRegisterInfo();
- unsigned Reg = RegInfo->getLocalAddressRegister(MF);
- return DAG.getCopyFromReg(DAG.getEntryNode(), dl, Reg,
- Op.getSimpleValueType());
- }
- case Intrinsic::eh_recoverfp: {
-
-
-
- SDValue FnOp = Op.getOperand(1);
- SDValue IncomingFPOp = Op.getOperand(2);
- GlobalAddressSDNode *GSD = dyn_cast<GlobalAddressSDNode>(FnOp);
- auto *Fn = dyn_cast_or_null<Function>(GSD ? GSD->getGlobal() : nullptr);
- if (!Fn)
- report_fatal_error(
- "llvm.eh.recoverfp must take a function as the first argument");
- return IncomingFPOp;
- }
- case Intrinsic::aarch64_neon_vsri:
- case Intrinsic::aarch64_neon_vsli: {
- EVT Ty = Op.getValueType();
- if (!Ty.isVector())
- report_fatal_error("Unexpected type for aarch64_neon_vsli");
- assert(Op.getConstantOperandVal(3) <= Ty.getScalarSizeInBits());
- bool IsShiftRight = IntNo == Intrinsic::aarch64_neon_vsri;
- unsigned Opcode = IsShiftRight ? AArch64ISD::VSRI : AArch64ISD::VSLI;
- return DAG.getNode(Opcode, dl, Ty, Op.getOperand(1), Op.getOperand(2),
- Op.getOperand(3));
- }
- case Intrinsic::aarch64_neon_srhadd:
- case Intrinsic::aarch64_neon_urhadd:
- case Intrinsic::aarch64_neon_shadd:
- case Intrinsic::aarch64_neon_uhadd: {
- bool IsSignedAdd = (IntNo == Intrinsic::aarch64_neon_srhadd ||
- IntNo == Intrinsic::aarch64_neon_shadd);
- bool IsRoundingAdd = (IntNo == Intrinsic::aarch64_neon_srhadd ||
- IntNo == Intrinsic::aarch64_neon_urhadd);
- unsigned Opcode =
- IsSignedAdd ? (IsRoundingAdd ? AArch64ISD::SRHADD : AArch64ISD::SHADD)
- : (IsRoundingAdd ? AArch64ISD::URHADD : AArch64ISD::UHADD);
- return DAG.getNode(Opcode, dl, Op.getValueType(), Op.getOperand(1),
- Op.getOperand(2));
- }
- case Intrinsic::aarch64_neon_uabd: {
- return DAG.getNode(AArch64ISD::UABD, dl, Op.getValueType(),
- Op.getOperand(1), Op.getOperand(2));
- }
- case Intrinsic::aarch64_neon_sabd: {
- return DAG.getNode(AArch64ISD::SABD, dl, Op.getValueType(),
- Op.getOperand(1), Op.getOperand(2));
- }
- }
- }
- bool AArch64TargetLowering::shouldRemoveExtendFromGSIndex(EVT VT) const {
- if (VT.getVectorElementType() == MVT::i32 &&
- VT.getVectorElementCount().getKnownMinValue() >= 4)
- return true;
- return false;
- }
- bool AArch64TargetLowering::isVectorLoadExtDesirable(SDValue ExtVal) const {
- return ExtVal.getValueType().isScalableVector();
- }
- unsigned getGatherVecOpcode(bool IsScaled, bool IsSigned, bool NeedsExtend) {
- std::map<std::tuple<bool, bool, bool>, unsigned> AddrModes = {
- {std::make_tuple( false, false, false),
- AArch64ISD::GLD1_MERGE_ZERO},
- {std::make_tuple( false, false, true),
- AArch64ISD::GLD1_UXTW_MERGE_ZERO},
- {std::make_tuple( false, true, false),
- AArch64ISD::GLD1_MERGE_ZERO},
- {std::make_tuple( false, true, true),
- AArch64ISD::GLD1_SXTW_MERGE_ZERO},
- {std::make_tuple( true, false, false),
- AArch64ISD::GLD1_SCALED_MERGE_ZERO},
- {std::make_tuple( true, false, true),
- AArch64ISD::GLD1_UXTW_SCALED_MERGE_ZERO},
- {std::make_tuple( true, true, false),
- AArch64ISD::GLD1_SCALED_MERGE_ZERO},
- {std::make_tuple( true, true, true),
- AArch64ISD::GLD1_SXTW_SCALED_MERGE_ZERO},
- };
- auto Key = std::make_tuple(IsScaled, IsSigned, NeedsExtend);
- return AddrModes.find(Key)->second;
- }
- unsigned getScatterVecOpcode(bool IsScaled, bool IsSigned, bool NeedsExtend) {
- std::map<std::tuple<bool, bool, bool>, unsigned> AddrModes = {
- {std::make_tuple( false, false, false),
- AArch64ISD::SST1_PRED},
- {std::make_tuple( false, false, true),
- AArch64ISD::SST1_UXTW_PRED},
- {std::make_tuple( false, true, false),
- AArch64ISD::SST1_PRED},
- {std::make_tuple( false, true, true),
- AArch64ISD::SST1_SXTW_PRED},
- {std::make_tuple( true, false, false),
- AArch64ISD::SST1_SCALED_PRED},
- {std::make_tuple( true, false, true),
- AArch64ISD::SST1_UXTW_SCALED_PRED},
- {std::make_tuple( true, true, false),
- AArch64ISD::SST1_SCALED_PRED},
- {std::make_tuple( true, true, true),
- AArch64ISD::SST1_SXTW_SCALED_PRED},
- };
- auto Key = std::make_tuple(IsScaled, IsSigned, NeedsExtend);
- return AddrModes.find(Key)->second;
- }
- unsigned getSignExtendedGatherOpcode(unsigned Opcode) {
- switch (Opcode) {
- default:
- llvm_unreachable("unimplemented opcode");
- return Opcode;
- case AArch64ISD::GLD1_MERGE_ZERO:
- return AArch64ISD::GLD1S_MERGE_ZERO;
- case AArch64ISD::GLD1_IMM_MERGE_ZERO:
- return AArch64ISD::GLD1S_IMM_MERGE_ZERO;
- case AArch64ISD::GLD1_UXTW_MERGE_ZERO:
- return AArch64ISD::GLD1S_UXTW_MERGE_ZERO;
- case AArch64ISD::GLD1_SXTW_MERGE_ZERO:
- return AArch64ISD::GLD1S_SXTW_MERGE_ZERO;
- case AArch64ISD::GLD1_SCALED_MERGE_ZERO:
- return AArch64ISD::GLD1S_SCALED_MERGE_ZERO;
- case AArch64ISD::GLD1_UXTW_SCALED_MERGE_ZERO:
- return AArch64ISD::GLD1S_UXTW_SCALED_MERGE_ZERO;
- case AArch64ISD::GLD1_SXTW_SCALED_MERGE_ZERO:
- return AArch64ISD::GLD1S_SXTW_SCALED_MERGE_ZERO;
- }
- }
- bool getGatherScatterIndexIsExtended(SDValue Index) {
- unsigned Opcode = Index.getOpcode();
- if (Opcode == ISD::SIGN_EXTEND_INREG)
- return true;
- if (Opcode == ISD::AND) {
- SDValue Splat = Index.getOperand(1);
- if (Splat.getOpcode() != ISD::SPLAT_VECTOR)
- return false;
- ConstantSDNode *Mask = dyn_cast<ConstantSDNode>(Splat.getOperand(0));
- if (!Mask || Mask->getZExtValue() != 0xFFFFFFFF)
- return false;
- return true;
- }
- return false;
- }
- void selectGatherScatterAddrMode(SDValue &BasePtr, SDValue &Index, EVT MemVT,
- unsigned &Opcode, bool IsGather,
- SelectionDAG &DAG) {
- if (!isNullConstant(BasePtr))
- return;
- ConstantSDNode *Offset = nullptr;
- if (Index.getOpcode() == ISD::ADD)
- if (auto SplatVal = DAG.getSplatValue(Index.getOperand(1))) {
- if (isa<ConstantSDNode>(SplatVal))
- Offset = cast<ConstantSDNode>(SplatVal);
- else {
- BasePtr = SplatVal;
- Index = Index->getOperand(0);
- return;
- }
- }
- unsigned NewOp =
- IsGather ? AArch64ISD::GLD1_IMM_MERGE_ZERO : AArch64ISD::SST1_IMM_PRED;
- if (!Offset) {
- std::swap(BasePtr, Index);
- Opcode = NewOp;
- return;
- }
- uint64_t OffsetVal = Offset->getZExtValue();
- unsigned ScalarSizeInBytes = MemVT.getScalarSizeInBits() / 8;
- auto ConstOffset = DAG.getConstant(OffsetVal, SDLoc(Index), MVT::i64);
- if (OffsetVal % ScalarSizeInBytes || OffsetVal / ScalarSizeInBytes > 31) {
-
- BasePtr = ConstOffset;
- Index = Index->getOperand(0);
- return;
- }
-
- Opcode = NewOp;
- BasePtr = Index->getOperand(0);
- Index = ConstOffset;
- }
- SDValue AArch64TargetLowering::LowerMGATHER(SDValue Op,
- SelectionDAG &DAG) const {
- SDLoc DL(Op);
- MaskedGatherSDNode *MGT = cast<MaskedGatherSDNode>(Op);
- assert(MGT && "Can only custom lower gather load nodes");
- SDValue Index = MGT->getIndex();
- SDValue Chain = MGT->getChain();
- SDValue PassThru = MGT->getPassThru();
- SDValue Mask = MGT->getMask();
- SDValue BasePtr = MGT->getBasePtr();
- ISD::LoadExtType ExtTy = MGT->getExtensionType();
- ISD::MemIndexType IndexType = MGT->getIndexType();
- bool IsScaled =
- IndexType == ISD::SIGNED_SCALED || IndexType == ISD::UNSIGNED_SCALED;
- bool IsSigned =
- IndexType == ISD::SIGNED_SCALED || IndexType == ISD::SIGNED_UNSCALED;
- bool IdxNeedsExtend =
- getGatherScatterIndexIsExtended(Index) ||
- Index.getSimpleValueType().getVectorElementType() == MVT::i32;
- bool ResNeedsSignExtend = ExtTy == ISD::EXTLOAD || ExtTy == ISD::SEXTLOAD;
- EVT VT = PassThru.getSimpleValueType();
- EVT MemVT = MGT->getMemoryVT();
- SDValue InputVT = DAG.getValueType(MemVT);
- if (VT.getVectorElementType() == MVT::bf16 &&
- !static_cast<const AArch64Subtarget &>(DAG.getSubtarget()).hasBF16())
- return SDValue();
-
- if (VT.isFloatingPoint()) {
- EVT PassThruVT = getPackedSVEVectorVT(VT.getVectorElementCount());
- PassThru = getSVESafeBitCast(PassThruVT, PassThru, DAG);
- InputVT = DAG.getValueType(MemVT.changeVectorElementTypeToInteger());
- }
- SDVTList VTs = DAG.getVTList(PassThru.getSimpleValueType(), MVT::Other);
- if (getGatherScatterIndexIsExtended(Index))
- Index = Index.getOperand(0);
- unsigned Opcode = getGatherVecOpcode(IsScaled, IsSigned, IdxNeedsExtend);
- selectGatherScatterAddrMode(BasePtr, Index, MemVT, Opcode,
- true, DAG);
- if (ResNeedsSignExtend)
- Opcode = getSignExtendedGatherOpcode(Opcode);
- SDValue Ops[] = {Chain, Mask, BasePtr, Index, InputVT, PassThru};
- SDValue Gather = DAG.getNode(Opcode, DL, VTs, Ops);
- if (VT.isFloatingPoint()) {
- SDValue Cast = getSVESafeBitCast(VT, Gather, DAG);
- return DAG.getMergeValues({Cast, Gather}, DL);
- }
- return Gather;
- }
- SDValue AArch64TargetLowering::LowerMSCATTER(SDValue Op,
- SelectionDAG &DAG) const {
- SDLoc DL(Op);
- MaskedScatterSDNode *MSC = cast<MaskedScatterSDNode>(Op);
- assert(MSC && "Can only custom lower scatter store nodes");
- SDValue Index = MSC->getIndex();
- SDValue Chain = MSC->getChain();
- SDValue StoreVal = MSC->getValue();
- SDValue Mask = MSC->getMask();
- SDValue BasePtr = MSC->getBasePtr();
- ISD::MemIndexType IndexType = MSC->getIndexType();
- bool IsScaled =
- IndexType == ISD::SIGNED_SCALED || IndexType == ISD::UNSIGNED_SCALED;
- bool IsSigned =
- IndexType == ISD::SIGNED_SCALED || IndexType == ISD::SIGNED_UNSCALED;
- bool NeedsExtend =
- getGatherScatterIndexIsExtended(Index) ||
- Index.getSimpleValueType().getVectorElementType() == MVT::i32;
- EVT VT = StoreVal.getSimpleValueType();
- SDVTList VTs = DAG.getVTList(MVT::Other);
- EVT MemVT = MSC->getMemoryVT();
- SDValue InputVT = DAG.getValueType(MemVT);
- if (VT.getVectorElementType() == MVT::bf16 &&
- !static_cast<const AArch64Subtarget &>(DAG.getSubtarget()).hasBF16())
- return SDValue();
-
- if (VT.isFloatingPoint()) {
- EVT StoreValVT = getPackedSVEVectorVT(VT.getVectorElementCount());
- StoreVal = getSVESafeBitCast(StoreValVT, StoreVal, DAG);
- InputVT = DAG.getValueType(MemVT.changeVectorElementTypeToInteger());
- }
- if (getGatherScatterIndexIsExtended(Index))
- Index = Index.getOperand(0);
- unsigned Opcode = getScatterVecOpcode(IsScaled, IsSigned, NeedsExtend);
- selectGatherScatterAddrMode(BasePtr, Index, MemVT, Opcode,
- false, DAG);
- SDValue Ops[] = {Chain, StoreVal, Mask, BasePtr, Index, InputVT};
- return DAG.getNode(Opcode, DL, VTs, Ops);
- }
- static SDValue LowerTruncateVectorStore(SDLoc DL, StoreSDNode *ST,
- EVT VT, EVT MemVT,
- SelectionDAG &DAG) {
- assert(VT.isVector() && "VT should be a vector type");
- assert(MemVT == MVT::v4i8 && VT == MVT::v4i16);
- SDValue Value = ST->getValue();
-
-
-
-
-
-
- SDValue Undef = DAG.getUNDEF(MVT::i16);
- SDValue UndefVec = DAG.getBuildVector(MVT::v4i16, DL,
- {Undef, Undef, Undef, Undef});
- SDValue TruncExt = DAG.getNode(ISD::CONCAT_VECTORS, DL, MVT::v8i16,
- Value, UndefVec);
- SDValue Trunc = DAG.getNode(ISD::TRUNCATE, DL, MVT::v8i8, TruncExt);
- Trunc = DAG.getNode(ISD::BITCAST, DL, MVT::v2i32, Trunc);
- SDValue ExtractTrunc = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::i32,
- Trunc, DAG.getConstant(0, DL, MVT::i64));
- return DAG.getStore(ST->getChain(), DL, ExtractTrunc,
- ST->getBasePtr(), ST->getMemOperand());
- }
- SDValue AArch64TargetLowering::LowerSTORE(SDValue Op,
- SelectionDAG &DAG) const {
- SDLoc Dl(Op);
- StoreSDNode *StoreNode = cast<StoreSDNode>(Op);
- assert (StoreNode && "Can only custom lower store nodes");
- SDValue Value = StoreNode->getValue();
- EVT VT = Value.getValueType();
- EVT MemVT = StoreNode->getMemoryVT();
- if (VT.isVector()) {
- if (useSVEForFixedLengthVectorVT(VT))
- return LowerFixedLengthVectorStoreToSVE(Op, DAG);
- unsigned AS = StoreNode->getAddressSpace();
- Align Alignment = StoreNode->getAlign();
- if (Alignment < MemVT.getStoreSize() &&
- !allowsMisalignedMemoryAccesses(MemVT, AS, Alignment.value(),
- StoreNode->getMemOperand()->getFlags(),
- nullptr)) {
- return scalarizeVectorStore(StoreNode, DAG);
- }
- if (StoreNode->isTruncatingStore()) {
- return LowerTruncateVectorStore(Dl, StoreNode, VT, MemVT, DAG);
- }
-
-
-
- ElementCount EC = MemVT.getVectorElementCount();
- if (StoreNode->isNonTemporal() && MemVT.getSizeInBits() == 256u &&
- EC.isKnownEven() &&
- ((MemVT.getScalarSizeInBits() == 8u ||
- MemVT.getScalarSizeInBits() == 16u ||
- MemVT.getScalarSizeInBits() == 32u ||
- MemVT.getScalarSizeInBits() == 64u))) {
- SDValue Lo =
- DAG.getNode(ISD::EXTRACT_SUBVECTOR, Dl,
- MemVT.getHalfNumVectorElementsVT(*DAG.getContext()),
- StoreNode->getValue(), DAG.getConstant(0, Dl, MVT::i64));
- SDValue Hi =
- DAG.getNode(ISD::EXTRACT_SUBVECTOR, Dl,
- MemVT.getHalfNumVectorElementsVT(*DAG.getContext()),
- StoreNode->getValue(),
- DAG.getConstant(EC.getKnownMinValue() / 2, Dl, MVT::i64));
- SDValue Result = DAG.getMemIntrinsicNode(
- AArch64ISD::STNP, Dl, DAG.getVTList(MVT::Other),
- {StoreNode->getChain(), Lo, Hi, StoreNode->getBasePtr()},
- StoreNode->getMemoryVT(), StoreNode->getMemOperand());
- return Result;
- }
- } else if (MemVT == MVT::i128 && StoreNode->isVolatile()) {
- assert(StoreNode->getValue()->getValueType(0) == MVT::i128);
- SDValue Lo =
- DAG.getNode(ISD::EXTRACT_ELEMENT, Dl, MVT::i64, StoreNode->getValue(),
- DAG.getConstant(0, Dl, MVT::i64));
- SDValue Hi =
- DAG.getNode(ISD::EXTRACT_ELEMENT, Dl, MVT::i64, StoreNode->getValue(),
- DAG.getConstant(1, Dl, MVT::i64));
- SDValue Result = DAG.getMemIntrinsicNode(
- AArch64ISD::STP, Dl, DAG.getVTList(MVT::Other),
- {StoreNode->getChain(), Lo, Hi, StoreNode->getBasePtr()},
- StoreNode->getMemoryVT(), StoreNode->getMemOperand());
- return Result;
- }
- return SDValue();
- }
- SDValue AArch64TargetLowering::LowerABS(SDValue Op, SelectionDAG &DAG) const {
- MVT VT = Op.getSimpleValueType();
- if (VT.isVector())
- return LowerToPredicatedOp(Op, DAG, AArch64ISD::ABS_MERGE_PASSTHRU);
- SDLoc DL(Op);
- SDValue Neg = DAG.getNode(ISD::SUB, DL, VT, DAG.getConstant(0, DL, VT),
- Op.getOperand(0));
-
- SDValue Cmp =
- DAG.getNode(AArch64ISD::SUBS, DL, DAG.getVTList(VT, MVT::i32),
- Op.getOperand(0), DAG.getConstant(0, DL, VT));
- return DAG.getNode(AArch64ISD::CSEL, DL, VT, Op.getOperand(0), Neg,
- DAG.getConstant(AArch64CC::PL, DL, MVT::i32),
- Cmp.getValue(1));
- }
- SDValue AArch64TargetLowering::LowerOperation(SDValue Op,
- SelectionDAG &DAG) const {
- LLVM_DEBUG(dbgs() << "Custom lowering: ");
- LLVM_DEBUG(Op.dump());
- switch (Op.getOpcode()) {
- default:
- llvm_unreachable("unimplemented operand");
- return SDValue();
- case ISD::BITCAST:
- return LowerBITCAST(Op, DAG);
- case ISD::GlobalAddress:
- return LowerGlobalAddress(Op, DAG);
- case ISD::GlobalTLSAddress:
- return LowerGlobalTLSAddress(Op, DAG);
- case ISD::SETCC:
- case ISD::STRICT_FSETCC:
- case ISD::STRICT_FSETCCS:
- return LowerSETCC(Op, DAG);
- case ISD::BR_CC:
- return LowerBR_CC(Op, DAG);
- case ISD::SELECT:
- return LowerSELECT(Op, DAG);
- case ISD::SELECT_CC:
- return LowerSELECT_CC(Op, DAG);
- case ISD::JumpTable:
- return LowerJumpTable(Op, DAG);
- case ISD::BR_JT:
- return LowerBR_JT(Op, DAG);
- case ISD::ConstantPool:
- return LowerConstantPool(Op, DAG);
- case ISD::BlockAddress:
- return LowerBlockAddress(Op, DAG);
- case ISD::VASTART:
- return LowerVASTART(Op, DAG);
- case ISD::VACOPY:
- return LowerVACOPY(Op, DAG);
- case ISD::VAARG:
- return LowerVAARG(Op, DAG);
- case ISD::ADDC:
- case ISD::ADDE:
- case ISD::SUBC:
- case ISD::SUBE:
- return LowerADDC_ADDE_SUBC_SUBE(Op, DAG);
- case ISD::SADDO:
- case ISD::UADDO:
- case ISD::SSUBO:
- case ISD::USUBO:
- case ISD::SMULO:
- case ISD::UMULO:
- return LowerXALUO(Op, DAG);
- case ISD::FADD:
- return LowerToPredicatedOp(Op, DAG, AArch64ISD::FADD_PRED);
- case ISD::FSUB:
- return LowerToPredicatedOp(Op, DAG, AArch64ISD::FSUB_PRED);
- case ISD::FMUL:
- return LowerToPredicatedOp(Op, DAG, AArch64ISD::FMUL_PRED);
- case ISD::FMA:
- return LowerToPredicatedOp(Op, DAG, AArch64ISD::FMA_PRED);
- case ISD::FDIV:
- return LowerToPredicatedOp(Op, DAG, AArch64ISD::FDIV_PRED);
- case ISD::FNEG:
- return LowerToPredicatedOp(Op, DAG, AArch64ISD::FNEG_MERGE_PASSTHRU);
- case ISD::FCEIL:
- return LowerToPredicatedOp(Op, DAG, AArch64ISD::FCEIL_MERGE_PASSTHRU);
- case ISD::FFLOOR:
- return LowerToPredicatedOp(Op, DAG, AArch64ISD::FFLOOR_MERGE_PASSTHRU);
- case ISD::FNEARBYINT:
- return LowerToPredicatedOp(Op, DAG, AArch64ISD::FNEARBYINT_MERGE_PASSTHRU);
- case ISD::FRINT:
- return LowerToPredicatedOp(Op, DAG, AArch64ISD::FRINT_MERGE_PASSTHRU);
- case ISD::FROUND:
- return LowerToPredicatedOp(Op, DAG, AArch64ISD::FROUND_MERGE_PASSTHRU);
- case ISD::FROUNDEVEN:
- return LowerToPredicatedOp(Op, DAG, AArch64ISD::FROUNDEVEN_MERGE_PASSTHRU);
- case ISD::FTRUNC:
- return LowerToPredicatedOp(Op, DAG, AArch64ISD::FTRUNC_MERGE_PASSTHRU);
- case ISD::FSQRT:
- return LowerToPredicatedOp(Op, DAG, AArch64ISD::FSQRT_MERGE_PASSTHRU);
- case ISD::FABS:
- return LowerToPredicatedOp(Op, DAG, AArch64ISD::FABS_MERGE_PASSTHRU);
- case ISD::FP_ROUND:
- case ISD::STRICT_FP_ROUND:
- return LowerFP_ROUND(Op, DAG);
- case ISD::FP_EXTEND:
- return LowerFP_EXTEND(Op, DAG);
- case ISD::FRAMEADDR:
- return LowerFRAMEADDR(Op, DAG);
- case ISD::SPONENTRY:
- return LowerSPONENTRY(Op, DAG);
- case ISD::RETURNADDR:
- return LowerRETURNADDR(Op, DAG);
- case ISD::ADDROFRETURNADDR:
- return LowerADDROFRETURNADDR(Op, DAG);
- case ISD::CONCAT_VECTORS:
- return LowerCONCAT_VECTORS(Op, DAG);
- case ISD::INSERT_VECTOR_ELT:
- return LowerINSERT_VECTOR_ELT(Op, DAG);
- case ISD::EXTRACT_VECTOR_ELT:
- return LowerEXTRACT_VECTOR_ELT(Op, DAG);
- case ISD::BUILD_VECTOR:
- return LowerBUILD_VECTOR(Op, DAG);
- case ISD::VECTOR_SHUFFLE:
- return LowerVECTOR_SHUFFLE(Op, DAG);
- case ISD::SPLAT_VECTOR:
- return LowerSPLAT_VECTOR(Op, DAG);
- case ISD::EXTRACT_SUBVECTOR:
- return LowerEXTRACT_SUBVECTOR(Op, DAG);
- case ISD::INSERT_SUBVECTOR:
- return LowerINSERT_SUBVECTOR(Op, DAG);
- case ISD::SDIV:
- case ISD::UDIV:
- return LowerDIV(Op, DAG);
- case ISD::SMIN:
- return LowerToPredicatedOp(Op, DAG, AArch64ISD::SMIN_PRED,
- true);
- case ISD::UMIN:
- return LowerToPredicatedOp(Op, DAG, AArch64ISD::UMIN_PRED,
- true);
- case ISD::SMAX:
- return LowerToPredicatedOp(Op, DAG, AArch64ISD::SMAX_PRED,
- true);
- case ISD::UMAX:
- return LowerToPredicatedOp(Op, DAG, AArch64ISD::UMAX_PRED,
- true);
- case ISD::SRA:
- case ISD::SRL:
- case ISD::SHL:
- return LowerVectorSRA_SRL_SHL(Op, DAG);
- case ISD::SHL_PARTS:
- return LowerShiftLeftParts(Op, DAG);
- case ISD::SRL_PARTS:
- case ISD::SRA_PARTS:
- return LowerShiftRightParts(Op, DAG);
- case ISD::CTPOP:
- return LowerCTPOP(Op, DAG);
- case ISD::FCOPYSIGN:
- return LowerFCOPYSIGN(Op, DAG);
- case ISD::OR:
- return LowerVectorOR(Op, DAG);
- case ISD::XOR:
- return LowerXOR(Op, DAG);
- case ISD::PREFETCH:
- return LowerPREFETCH(Op, DAG);
- case ISD::SINT_TO_FP:
- case ISD::UINT_TO_FP:
- case ISD::STRICT_SINT_TO_FP:
- case ISD::STRICT_UINT_TO_FP:
- return LowerINT_TO_FP(Op, DAG);
- case ISD::FP_TO_SINT:
- case ISD::FP_TO_UINT:
- case ISD::STRICT_FP_TO_SINT:
- case ISD::STRICT_FP_TO_UINT:
- return LowerFP_TO_INT(Op, DAG);
- case ISD::FSINCOS:
- return LowerFSINCOS(Op, DAG);
- case ISD::FLT_ROUNDS_:
- return LowerFLT_ROUNDS_(Op, DAG);
- case ISD::MUL:
- return LowerMUL(Op, DAG);
- case ISD::INTRINSIC_WO_CHAIN:
- return LowerINTRINSIC_WO_CHAIN(Op, DAG);
- case ISD::STORE:
- return LowerSTORE(Op, DAG);
- case ISD::MGATHER:
- return LowerMGATHER(Op, DAG);
- case ISD::MSCATTER:
- return LowerMSCATTER(Op, DAG);
- case ISD::VECREDUCE_SEQ_FADD:
- return LowerVECREDUCE_SEQ_FADD(Op, DAG);
- case ISD::VECREDUCE_ADD:
- case ISD::VECREDUCE_AND:
- case ISD::VECREDUCE_OR:
- case ISD::VECREDUCE_XOR:
- case ISD::VECREDUCE_SMAX:
- case ISD::VECREDUCE_SMIN:
- case ISD::VECREDUCE_UMAX:
- case ISD::VECREDUCE_UMIN:
- case ISD::VECREDUCE_FADD:
- case ISD::VECREDUCE_FMAX:
- case ISD::VECREDUCE_FMIN:
- return LowerVECREDUCE(Op, DAG);
- case ISD::ATOMIC_LOAD_SUB:
- return LowerATOMIC_LOAD_SUB(Op, DAG);
- case ISD::ATOMIC_LOAD_AND:
- return LowerATOMIC_LOAD_AND(Op, DAG);
- case ISD::DYNAMIC_STACKALLOC:
- return LowerDYNAMIC_STACKALLOC(Op, DAG);
- case ISD::VSCALE:
- return LowerVSCALE(Op, DAG);
- case ISD::ANY_EXTEND:
- case ISD::SIGN_EXTEND:
- case ISD::ZERO_EXTEND:
- return LowerFixedLengthVectorIntExtendToSVE(Op, DAG);
- case ISD::SIGN_EXTEND_INREG: {
-
- EVT ExtraVT = cast<VTSDNode>(Op.getOperand(1))->getVT();
- EVT ExtraEltVT = ExtraVT.getVectorElementType();
- if ((ExtraEltVT != MVT::i8) && (ExtraEltVT != MVT::i16) &&
- (ExtraEltVT != MVT::i32) && (ExtraEltVT != MVT::i64))
- return SDValue();
- return LowerToPredicatedOp(Op, DAG,
- AArch64ISD::SIGN_EXTEND_INREG_MERGE_PASSTHRU);
- }
- case ISD::TRUNCATE:
- return LowerTRUNCATE(Op, DAG);
- case ISD::LOAD:
- if (useSVEForFixedLengthVectorVT(Op.getValueType()))
- return LowerFixedLengthVectorLoadToSVE(Op, DAG);
- llvm_unreachable("Unexpected request to lower ISD::LOAD");
- case ISD::ADD:
- return LowerToPredicatedOp(Op, DAG, AArch64ISD::ADD_PRED);
- case ISD::AND:
- return LowerToScalableOp(Op, DAG);
- case ISD::SUB:
- return LowerToPredicatedOp(Op, DAG, AArch64ISD::SUB_PRED);
- case ISD::FMAXNUM:
- return LowerToPredicatedOp(Op, DAG, AArch64ISD::FMAXNM_PRED);
- case ISD::FMINNUM:
- return LowerToPredicatedOp(Op, DAG, AArch64ISD::FMINNM_PRED);
- case ISD::VSELECT:
- return LowerFixedLengthVectorSelectToSVE(Op, DAG);
- case ISD::ABS:
- return LowerABS(Op, DAG);
- case ISD::BITREVERSE:
- return LowerToPredicatedOp(Op, DAG, AArch64ISD::BITREVERSE_MERGE_PASSTHRU,
- true);
- case ISD::BSWAP:
- return LowerToPredicatedOp(Op, DAG, AArch64ISD::BSWAP_MERGE_PASSTHRU);
- case ISD::CTLZ:
- return LowerToPredicatedOp(Op, DAG, AArch64ISD::CTLZ_MERGE_PASSTHRU,
- true);
- case ISD::CTTZ:
- return LowerCTTZ(Op, DAG);
- }
- }
- bool AArch64TargetLowering::mergeStoresAfterLegalization(EVT VT) const {
- return !Subtarget->useSVEForFixedLengthVectors();
- }
- bool AArch64TargetLowering::useSVEForFixedLengthVectorVT(
- EVT VT, bool OverrideNEON) const {
- if (!Subtarget->useSVEForFixedLengthVectors())
- return false;
- if (!VT.isFixedLengthVector())
- return false;
-
- switch (VT.getVectorElementType().getSimpleVT().SimpleTy) {
-
-
- case MVT::i1:
- default:
- return false;
- case MVT::i8:
- case MVT::i16:
- case MVT::i32:
- case MVT::i64:
- case MVT::f16:
- case MVT::f32:
- case MVT::f64:
- break;
- }
-
- if (OverrideNEON && (VT.is128BitVector() || VT.is64BitVector()))
- return true;
-
- if (VT.getFixedSizeInBits() <= 128)
- return false;
-
- if (VT.getFixedSizeInBits() > Subtarget->getMinSVEVectorSizeInBits())
- return false;
-
-
- if (!VT.isPow2VectorType())
- return false;
- return true;
- }
- CCAssignFn *AArch64TargetLowering::CCAssignFnForCall(CallingConv::ID CC,
- bool IsVarArg) const {
- switch (CC) {
- default:
- report_fatal_error("Unsupported calling convention.");
- case CallingConv::WebKit_JS:
- return CC_AArch64_WebKit_JS;
- case CallingConv::GHC:
- return CC_AArch64_GHC;
- case CallingConv::C:
- case CallingConv::Fast:
- case CallingConv::PreserveMost:
- case CallingConv::CXX_FAST_TLS:
- case CallingConv::Swift:
- if (Subtarget->isTargetWindows() && IsVarArg)
- return CC_AArch64_Win64_VarArg;
- if (!Subtarget->isTargetDarwin())
- return CC_AArch64_AAPCS;
- if (!IsVarArg)
- return CC_AArch64_DarwinPCS;
- return Subtarget->isTargetILP32() ? CC_AArch64_DarwinPCS_ILP32_VarArg
- : CC_AArch64_DarwinPCS_VarArg;
- case CallingConv::Win64:
- return IsVarArg ? CC_AArch64_Win64_VarArg : CC_AArch64_AAPCS;
- case CallingConv::CFGuard_Check:
- return CC_AArch64_Win64_CFGuard_Check;
- case CallingConv::AArch64_VectorCall:
- case CallingConv::AArch64_SVE_VectorCall:
- return CC_AArch64_AAPCS;
- }
- }
- CCAssignFn *
- AArch64TargetLowering::CCAssignFnForReturn(CallingConv::ID CC) const {
- return CC == CallingConv::WebKit_JS ? RetCC_AArch64_WebKit_JS
- : RetCC_AArch64_AAPCS;
- }
- SDValue AArch64TargetLowering::LowerFormalArguments(
- SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
- const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &DL,
- SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals) const {
- MachineFunction &MF = DAG.getMachineFunction();
- MachineFrameInfo &MFI = MF.getFrameInfo();
- bool IsWin64 = Subtarget->isCallingConvWin64(MF.getFunction().getCallingConv());
-
- SmallVector<CCValAssign, 16> ArgLocs;
- DenseMap<unsigned, SDValue> CopiedRegs;
- CCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), ArgLocs,
- *DAG.getContext());
-
-
-
-
-
-
- unsigned NumArgs = Ins.size();
- Function::const_arg_iterator CurOrigArg = MF.getFunction().arg_begin();
- unsigned CurArgIdx = 0;
- for (unsigned i = 0; i != NumArgs; ++i) {
- MVT ValVT = Ins[i].VT;
- if (Ins[i].isOrigArg()) {
- std::advance(CurOrigArg, Ins[i].getOrigArgIndex() - CurArgIdx);
- CurArgIdx = Ins[i].getOrigArgIndex();
-
- EVT ActualVT = getValueType(DAG.getDataLayout(), CurOrigArg->getType(),
- true);
- MVT ActualMVT = ActualVT.isSimple() ? ActualVT.getSimpleVT() : MVT::Other;
-
- if (ActualMVT == MVT::i1 || ActualMVT == MVT::i8)
- ValVT = MVT::i8;
- else if (ActualMVT == MVT::i16)
- ValVT = MVT::i16;
- }
- CCAssignFn *AssignFn = CCAssignFnForCall(CallConv, false);
- bool Res =
- AssignFn(i, ValVT, ValVT, CCValAssign::Full, Ins[i].Flags, CCInfo);
- assert(!Res && "Call operand has unhandled type");
- (void)Res;
- }
- SmallVector<SDValue, 16> ArgValues;
- unsigned ExtraArgLocs = 0;
- for (unsigned i = 0, e = Ins.size(); i != e; ++i) {
- CCValAssign &VA = ArgLocs[i - ExtraArgLocs];
- if (Ins[i].Flags.isByVal()) {
-
-
- EVT PtrVT = getPointerTy(DAG.getDataLayout());
- int Size = Ins[i].Flags.getByValSize();
- unsigned NumRegs = (Size + 7) / 8;
-
-
- unsigned FrameIdx =
- MFI.CreateFixedObject(8 * NumRegs, VA.getLocMemOffset(), false);
- SDValue FrameIdxN = DAG.getFrameIndex(FrameIdx, PtrVT);
- InVals.push_back(FrameIdxN);
- continue;
- }
- SDValue ArgValue;
- if (VA.isRegLoc()) {
-
- EVT RegVT = VA.getLocVT();
- const TargetRegisterClass *RC;
- if (RegVT == MVT::i32)
- RC = &AArch64::GPR32RegClass;
- else if (RegVT == MVT::i64)
- RC = &AArch64::GPR64RegClass;
- else if (RegVT == MVT::f16 || RegVT == MVT::bf16)
- RC = &AArch64::FPR16RegClass;
- else if (RegVT == MVT::f32)
- RC = &AArch64::FPR32RegClass;
- else if (RegVT == MVT::f64 || RegVT.is64BitVector())
- RC = &AArch64::FPR64RegClass;
- else if (RegVT == MVT::f128 || RegVT.is128BitVector())
- RC = &AArch64::FPR128RegClass;
- else if (RegVT.isScalableVector() &&
- RegVT.getVectorElementType() == MVT::i1)
- RC = &AArch64::PPRRegClass;
- else if (RegVT.isScalableVector())
- RC = &AArch64::ZPRRegClass;
- else
- llvm_unreachable("RegVT not supported by FORMAL_ARGUMENTS Lowering");
-
- unsigned Reg = MF.addLiveIn(VA.getLocReg(), RC);
- ArgValue = DAG.getCopyFromReg(Chain, DL, Reg, RegVT);
-
-
-
- switch (VA.getLocInfo()) {
- default:
- llvm_unreachable("Unknown loc info!");
- case CCValAssign::Full:
- break;
- case CCValAssign::Indirect:
- assert(VA.getValVT().isScalableVector() &&
- "Only scalable vectors can be passed indirectly");
- break;
- case CCValAssign::BCvt:
- ArgValue = DAG.getNode(ISD::BITCAST, DL, VA.getValVT(), ArgValue);
- break;
- case CCValAssign::AExt:
- case CCValAssign::SExt:
- case CCValAssign::ZExt:
- break;
- case CCValAssign::AExtUpper:
- ArgValue = DAG.getNode(ISD::SRL, DL, RegVT, ArgValue,
- DAG.getConstant(32, DL, RegVT));
- ArgValue = DAG.getZExtOrTrunc(ArgValue, DL, VA.getValVT());
- break;
- }
- } else {
- assert(VA.isMemLoc() && "CCValAssign is neither reg nor mem");
- unsigned ArgOffset = VA.getLocMemOffset();
- unsigned ArgSize = (VA.getLocInfo() == CCValAssign::Indirect
- ? VA.getLocVT().getSizeInBits()
- : VA.getValVT().getSizeInBits()) / 8;
- uint32_t BEAlign = 0;
- if (!Subtarget->isLittleEndian() && ArgSize < 8 &&
- !Ins[i].Flags.isInConsecutiveRegs())
- BEAlign = 8 - ArgSize;
- int FI = MFI.CreateFixedObject(ArgSize, ArgOffset + BEAlign, true);
-
- SDValue FIN = DAG.getFrameIndex(FI, getPointerTy(DAG.getDataLayout()));
-
- ISD::LoadExtType ExtType = ISD::NON_EXTLOAD;
- MVT MemVT = VA.getValVT();
- switch (VA.getLocInfo()) {
- default:
- break;
- case CCValAssign::Trunc:
- case CCValAssign::BCvt:
- MemVT = VA.getLocVT();
- break;
- case CCValAssign::Indirect:
- assert(VA.getValVT().isScalableVector() &&
- "Only scalable vectors can be passed indirectly");
- MemVT = VA.getLocVT();
- break;
- case CCValAssign::SExt:
- ExtType = ISD::SEXTLOAD;
- break;
- case CCValAssign::ZExt:
- ExtType = ISD::ZEXTLOAD;
- break;
- case CCValAssign::AExt:
- ExtType = ISD::EXTLOAD;
- break;
- }
- ArgValue = DAG.getExtLoad(
- ExtType, DL, VA.getLocVT(), Chain, FIN,
- MachinePointerInfo::getFixedStack(DAG.getMachineFunction(), FI),
- MemVT);
- }
- if (VA.getLocInfo() == CCValAssign::Indirect) {
- assert(VA.getValVT().isScalableVector() &&
- "Only scalable vectors can be passed indirectly");
- uint64_t PartSize = VA.getValVT().getStoreSize().getKnownMinSize();
- unsigned NumParts = 1;
- if (Ins[i].Flags.isInConsecutiveRegs()) {
- assert(!Ins[i].Flags.isInConsecutiveRegsLast());
- while (!Ins[i + NumParts - 1].Flags.isInConsecutiveRegsLast())
- ++NumParts;
- }
- MVT PartLoad = VA.getValVT();
- SDValue Ptr = ArgValue;
-
-
- while (NumParts > 0) {
- ArgValue = DAG.getLoad(PartLoad, DL, Chain, Ptr, MachinePointerInfo());
- InVals.push_back(ArgValue);
- NumParts--;
- if (NumParts > 0) {
- SDValue BytesIncrement = DAG.getVScale(
- DL, Ptr.getValueType(),
- APInt(Ptr.getValueSizeInBits().getFixedSize(), PartSize));
- SDNodeFlags Flags;
- Flags.setNoUnsignedWrap(true);
- Ptr = DAG.getNode(ISD::ADD, DL, Ptr.getValueType(), Ptr,
- BytesIncrement, Flags);
- ExtraArgLocs++;
- i++;
- }
- }
- } else {
- if (Subtarget->isTargetILP32() && Ins[i].Flags.isPointer())
- ArgValue = DAG.getNode(ISD::AssertZext, DL, ArgValue.getValueType(),
- ArgValue, DAG.getValueType(MVT::i32));
- InVals.push_back(ArgValue);
- }
- }
- assert((ArgLocs.size() + ExtraArgLocs) == Ins.size());
-
- AArch64FunctionInfo *FuncInfo = MF.getInfo<AArch64FunctionInfo>();
- if (isVarArg) {
- if (!Subtarget->isTargetDarwin() || IsWin64) {
-
-
-
-
-
- saveVarArgRegisters(CCInfo, DAG, DL, Chain);
- }
-
- unsigned StackOffset = CCInfo.getNextStackOffset();
-
- StackOffset = alignTo(StackOffset, Subtarget->isTargetILP32() ? 4 : 8);
- FuncInfo->setVarArgsStackIndex(MFI.CreateFixedObject(4, StackOffset, true));
- if (MFI.hasMustTailInVarArgFunc()) {
- SmallVector<MVT, 2> RegParmTypes;
- RegParmTypes.push_back(MVT::i64);
- RegParmTypes.push_back(MVT::f128);
-
- SmallVectorImpl<ForwardedRegister> &Forwards =
- FuncInfo->getForwardedMustTailRegParms();
- CCInfo.analyzeMustTailForwardedRegisters(Forwards, RegParmTypes,
- CC_AArch64_AAPCS);
-
- if (!CCInfo.isAllocated(AArch64::X8)) {
- unsigned X8VReg = MF.addLiveIn(AArch64::X8, &AArch64::GPR64RegClass);
- Forwards.push_back(ForwardedRegister(X8VReg, AArch64::X8, MVT::i64));
- }
- }
- }
-
-
-
- if (IsWin64) {
- for (unsigned I = 0, E = Ins.size(); I != E; ++I) {
- if (Ins[I].Flags.isInReg()) {
- assert(!FuncInfo->getSRetReturnReg());
- MVT PtrTy = getPointerTy(DAG.getDataLayout());
- Register Reg =
- MF.getRegInfo().createVirtualRegister(getRegClassFor(PtrTy));
- FuncInfo->setSRetReturnReg(Reg);
- SDValue Copy = DAG.getCopyToReg(DAG.getEntryNode(), DL, Reg, InVals[I]);
- Chain = DAG.getNode(ISD::TokenFactor, DL, MVT::Other, Copy, Chain);
- break;
- }
- }
- }
- unsigned StackArgSize = CCInfo.getNextStackOffset();
- bool TailCallOpt = MF.getTarget().Options.GuaranteedTailCallOpt;
- if (DoesCalleeRestoreStack(CallConv, TailCallOpt)) {
-
-
-
- StackArgSize = alignTo(StackArgSize, 16);
-
-
- FuncInfo->setArgumentStackToRestore(StackArgSize);
-
-
-
- }
-
-
- FuncInfo->setBytesInStackArgArea(StackArgSize);
- if (Subtarget->hasCustomCallingConv())
- Subtarget->getRegisterInfo()->UpdateCustomCalleeSavedRegs(MF);
- return Chain;
- }
- void AArch64TargetLowering::saveVarArgRegisters(CCState &CCInfo,
- SelectionDAG &DAG,
- const SDLoc &DL,
- SDValue &Chain) const {
- MachineFunction &MF = DAG.getMachineFunction();
- MachineFrameInfo &MFI = MF.getFrameInfo();
- AArch64FunctionInfo *FuncInfo = MF.getInfo<AArch64FunctionInfo>();
- auto PtrVT = getPointerTy(DAG.getDataLayout());
- bool IsWin64 = Subtarget->isCallingConvWin64(MF.getFunction().getCallingConv());
- SmallVector<SDValue, 8> MemOps;
- static const MCPhysReg GPRArgRegs[] = { AArch64::X0, AArch64::X1, AArch64::X2,
- AArch64::X3, AArch64::X4, AArch64::X5,
- AArch64::X6, AArch64::X7 };
- static const unsigned NumGPRArgRegs = array_lengthof(GPRArgRegs);
- unsigned FirstVariadicGPR = CCInfo.getFirstUnallocated(GPRArgRegs);
- unsigned GPRSaveSize = 8 * (NumGPRArgRegs - FirstVariadicGPR);
- int GPRIdx = 0;
- if (GPRSaveSize != 0) {
- if (IsWin64) {
- GPRIdx = MFI.CreateFixedObject(GPRSaveSize, -(int)GPRSaveSize, false);
- if (GPRSaveSize & 15)
-
- MFI.CreateFixedObject(16 - (GPRSaveSize & 15), -(int)alignTo(GPRSaveSize, 16), false);
- } else
- GPRIdx = MFI.CreateStackObject(GPRSaveSize, Align(8), false);
- SDValue FIN = DAG.getFrameIndex(GPRIdx, PtrVT);
- for (unsigned i = FirstVariadicGPR; i < NumGPRArgRegs; ++i) {
- unsigned VReg = MF.addLiveIn(GPRArgRegs[i], &AArch64::GPR64RegClass);
- SDValue Val = DAG.getCopyFromReg(Chain, DL, VReg, MVT::i64);
- SDValue Store = DAG.getStore(
- Val.getValue(1), DL, Val, FIN,
- IsWin64
- ? MachinePointerInfo::getFixedStack(DAG.getMachineFunction(),
- GPRIdx,
- (i - FirstVariadicGPR) * 8)
- : MachinePointerInfo::getStack(DAG.getMachineFunction(), i * 8));
- MemOps.push_back(Store);
- FIN =
- DAG.getNode(ISD::ADD, DL, PtrVT, FIN, DAG.getConstant(8, DL, PtrVT));
- }
- }
- FuncInfo->setVarArgsGPRIndex(GPRIdx);
- FuncInfo->setVarArgsGPRSize(GPRSaveSize);
- if (Subtarget->hasFPARMv8() && !IsWin64) {
- static const MCPhysReg FPRArgRegs[] = {
- AArch64::Q0, AArch64::Q1, AArch64::Q2, AArch64::Q3,
- AArch64::Q4, AArch64::Q5, AArch64::Q6, AArch64::Q7};
- static const unsigned NumFPRArgRegs = array_lengthof(FPRArgRegs);
- unsigned FirstVariadicFPR = CCInfo.getFirstUnallocated(FPRArgRegs);
- unsigned FPRSaveSize = 16 * (NumFPRArgRegs - FirstVariadicFPR);
- int FPRIdx = 0;
- if (FPRSaveSize != 0) {
- FPRIdx = MFI.CreateStackObject(FPRSaveSize, Align(16), false);
- SDValue FIN = DAG.getFrameIndex(FPRIdx, PtrVT);
- for (unsigned i = FirstVariadicFPR; i < NumFPRArgRegs; ++i) {
- unsigned VReg = MF.addLiveIn(FPRArgRegs[i], &AArch64::FPR128RegClass);
- SDValue Val = DAG.getCopyFromReg(Chain, DL, VReg, MVT::f128);
- SDValue Store = DAG.getStore(
- Val.getValue(1), DL, Val, FIN,
- MachinePointerInfo::getStack(DAG.getMachineFunction(), i * 16));
- MemOps.push_back(Store);
- FIN = DAG.getNode(ISD::ADD, DL, PtrVT, FIN,
- DAG.getConstant(16, DL, PtrVT));
- }
- }
- FuncInfo->setVarArgsFPRIndex(FPRIdx);
- FuncInfo->setVarArgsFPRSize(FPRSaveSize);
- }
- if (!MemOps.empty()) {
- Chain = DAG.getNode(ISD::TokenFactor, DL, MVT::Other, MemOps);
- }
- }
- SDValue AArch64TargetLowering::LowerCallResult(
- SDValue Chain, SDValue InFlag, CallingConv::ID CallConv, bool isVarArg,
- const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &DL,
- SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals, bool isThisReturn,
- SDValue ThisVal) const {
- CCAssignFn *RetCC = CCAssignFnForReturn(CallConv);
-
- SmallVector<CCValAssign, 16> RVLocs;
- DenseMap<unsigned, SDValue> CopiedRegs;
- CCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), RVLocs,
- *DAG.getContext());
- CCInfo.AnalyzeCallResult(Ins, RetCC);
-
- for (unsigned i = 0; i != RVLocs.size(); ++i) {
- CCValAssign VA = RVLocs[i];
-
-
- if (i == 0 && isThisReturn) {
- assert(!VA.needsCustom() && VA.getLocVT() == MVT::i64 &&
- "unexpected return calling convention register assignment");
- InVals.push_back(ThisVal);
- continue;
- }
-
-
- SDValue Val = CopiedRegs.lookup(VA.getLocReg());
- if (!Val) {
- Val =
- DAG.getCopyFromReg(Chain, DL, VA.getLocReg(), VA.getLocVT(), InFlag);
- Chain = Val.getValue(1);
- InFlag = Val.getValue(2);
- CopiedRegs[VA.getLocReg()] = Val;
- }
- switch (VA.getLocInfo()) {
- default:
- llvm_unreachable("Unknown loc info!");
- case CCValAssign::Full:
- break;
- case CCValAssign::BCvt:
- Val = DAG.getNode(ISD::BITCAST, DL, VA.getValVT(), Val);
- break;
- case CCValAssign::AExtUpper:
- Val = DAG.getNode(ISD::SRL, DL, VA.getLocVT(), Val,
- DAG.getConstant(32, DL, VA.getLocVT()));
- LLVM_FALLTHROUGH;
- case CCValAssign::AExt:
- LLVM_FALLTHROUGH;
- case CCValAssign::ZExt:
- Val = DAG.getZExtOrTrunc(Val, DL, VA.getValVT());
- break;
- }
- InVals.push_back(Val);
- }
- return Chain;
- }
- static bool canGuaranteeTCO(CallingConv::ID CC) {
- return CC == CallingConv::Fast;
- }
- static bool mayTailCallThisCC(CallingConv::ID CC) {
- switch (CC) {
- case CallingConv::C:
- case CallingConv::AArch64_SVE_VectorCall:
- case CallingConv::PreserveMost:
- case CallingConv::Swift:
- return true;
- default:
- return canGuaranteeTCO(CC);
- }
- }
- bool AArch64TargetLowering::isEligibleForTailCallOptimization(
- SDValue Callee, CallingConv::ID CalleeCC, bool isVarArg,
- const SmallVectorImpl<ISD::OutputArg> &Outs,
- const SmallVectorImpl<SDValue> &OutVals,
- const SmallVectorImpl<ISD::InputArg> &Ins, SelectionDAG &DAG) const {
- if (!mayTailCallThisCC(CalleeCC))
- return false;
- MachineFunction &MF = DAG.getMachineFunction();
- const Function &CallerF = MF.getFunction();
- CallingConv::ID CallerCC = CallerF.getCallingConv();
-
-
-
-
- if (CallerCC == CallingConv::C &&
- AArch64RegisterInfo::hasSVEArgsOrReturn(&MF))
- CallerCC = CallingConv::AArch64_SVE_VectorCall;
- bool CCMatch = CallerCC == CalleeCC;
-
-
-
- if (CallerCC == CallingConv::Win64 && !Subtarget->isTargetWindows() &&
- CalleeCC != CallingConv::Win64)
- return false;
-
-
-
- for (Function::const_arg_iterator i = CallerF.arg_begin(),
- e = CallerF.arg_end();
- i != e; ++i) {
- if (i->hasByValAttr())
- return false;
-
-
-
-
-
- if (i->hasInRegAttr())
- return false;
- }
- if (getTargetMachine().Options.GuaranteedTailCallOpt)
- return canGuaranteeTCO(CalleeCC) && CCMatch;
-
-
-
-
-
-
-
- if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) {
- const GlobalValue *GV = G->getGlobal();
- const Triple &TT = getTargetMachine().getTargetTriple();
- if (GV->hasExternalWeakLinkage() &&
- (!TT.isOSWindows() || TT.isOSBinFormatELF() || TT.isOSBinFormatMachO()))
- return false;
- }
-
-
-
-
-
- assert((!isVarArg || CalleeCC == CallingConv::C) &&
- "Unexpected variadic calling convention");
- LLVMContext &C = *DAG.getContext();
- if (isVarArg && !Outs.empty()) {
-
-
-
-
-
- SmallVector<CCValAssign, 16> ArgLocs;
- CCState CCInfo(CalleeCC, isVarArg, MF, ArgLocs, C);
- CCInfo.AnalyzeCallOperands(Outs, CCAssignFnForCall(CalleeCC, true));
- for (const CCValAssign &ArgLoc : ArgLocs)
- if (!ArgLoc.isRegLoc())
- return false;
- }
-
- if (!CCState::resultsCompatible(CalleeCC, CallerCC, MF, C, Ins,
- CCAssignFnForCall(CalleeCC, isVarArg),
- CCAssignFnForCall(CallerCC, isVarArg)))
- return false;
-
- const AArch64RegisterInfo *TRI = Subtarget->getRegisterInfo();
- const uint32_t *CallerPreserved = TRI->getCallPreservedMask(MF, CallerCC);
- if (!CCMatch) {
- const uint32_t *CalleePreserved = TRI->getCallPreservedMask(MF, CalleeCC);
- if (Subtarget->hasCustomCallingConv()) {
- TRI->UpdateCustomCallPreservedMask(MF, &CallerPreserved);
- TRI->UpdateCustomCallPreservedMask(MF, &CalleePreserved);
- }
- if (!TRI->regmaskSubsetEqual(CallerPreserved, CalleePreserved))
- return false;
- }
-
- if (Outs.empty())
- return true;
- SmallVector<CCValAssign, 16> ArgLocs;
- CCState CCInfo(CalleeCC, isVarArg, MF, ArgLocs, C);
- CCInfo.AnalyzeCallOperands(Outs, CCAssignFnForCall(CalleeCC, isVarArg));
- const AArch64FunctionInfo *FuncInfo = MF.getInfo<AArch64FunctionInfo>();
-
-
-
-
- if (llvm::any_of(ArgLocs, [](CCValAssign &A) {
- assert((A.getLocInfo() != CCValAssign::Indirect ||
- A.getValVT().isScalableVector()) &&
- "Expected value to be scalable");
- return A.getLocInfo() == CCValAssign::Indirect;
- }))
- return false;
-
-
- if (CCInfo.getNextStackOffset() > FuncInfo->getBytesInStackArgArea())
- return false;
- const MachineRegisterInfo &MRI = MF.getRegInfo();
- if (!parametersInCSRMatch(MRI, CallerPreserved, ArgLocs, OutVals))
- return false;
- return true;
- }
- SDValue AArch64TargetLowering::addTokenForArgument(SDValue Chain,
- SelectionDAG &DAG,
- MachineFrameInfo &MFI,
- int ClobberedFI) const {
- SmallVector<SDValue, 8> ArgChains;
- int64_t FirstByte = MFI.getObjectOffset(ClobberedFI);
- int64_t LastByte = FirstByte + MFI.getObjectSize(ClobberedFI) - 1;
-
-
-
- ArgChains.push_back(Chain);
-
- for (SDNode::use_iterator U = DAG.getEntryNode().getNode()->use_begin(),
- UE = DAG.getEntryNode().getNode()->use_end();
- U != UE; ++U)
- if (LoadSDNode *L = dyn_cast<LoadSDNode>(*U))
- if (FrameIndexSDNode *FI = dyn_cast<FrameIndexSDNode>(L->getBasePtr()))
- if (FI->getIndex() < 0) {
- int64_t InFirstByte = MFI.getObjectOffset(FI->getIndex());
- int64_t InLastByte = InFirstByte;
- InLastByte += MFI.getObjectSize(FI->getIndex()) - 1;
- if ((InFirstByte <= FirstByte && FirstByte <= InLastByte) ||
- (FirstByte <= InFirstByte && InFirstByte <= LastByte))
- ArgChains.push_back(SDValue(L, 1));
- }
-
- return DAG.getNode(ISD::TokenFactor, SDLoc(Chain), MVT::Other, ArgChains);
- }
- bool AArch64TargetLowering::DoesCalleeRestoreStack(CallingConv::ID CallCC,
- bool TailCallOpt) const {
- return CallCC == CallingConv::Fast && TailCallOpt;
- }
- SDValue
- AArch64TargetLowering::LowerCall(CallLoweringInfo &CLI,
- SmallVectorImpl<SDValue> &InVals) const {
- SelectionDAG &DAG = CLI.DAG;
- SDLoc &DL = CLI.DL;
- SmallVector<ISD::OutputArg, 32> &Outs = CLI.Outs;
- SmallVector<SDValue, 32> &OutVals = CLI.OutVals;
- SmallVector<ISD::InputArg, 32> &Ins = CLI.Ins;
- SDValue Chain = CLI.Chain;
- SDValue Callee = CLI.Callee;
- bool &IsTailCall = CLI.IsTailCall;
- CallingConv::ID CallConv = CLI.CallConv;
- bool IsVarArg = CLI.IsVarArg;
- MachineFunction &MF = DAG.getMachineFunction();
- MachineFunction::CallSiteInfo CSInfo;
- bool IsThisReturn = false;
- AArch64FunctionInfo *FuncInfo = MF.getInfo<AArch64FunctionInfo>();
- bool TailCallOpt = MF.getTarget().Options.GuaranteedTailCallOpt;
- bool IsSibCall = false;
-
-
- if (CallConv == CallingConv::C) {
- bool CalleeOutSVE = any_of(Outs, [](ISD::OutputArg &Out){
- return Out.VT.isScalableVector();
- });
- bool CalleeInSVE = any_of(Ins, [](ISD::InputArg &In){
- return In.VT.isScalableVector();
- });
- if (CalleeInSVE || CalleeOutSVE)
- CallConv = CallingConv::AArch64_SVE_VectorCall;
- }
- if (IsTailCall) {
-
- IsTailCall = isEligibleForTailCallOptimization(
- Callee, CallConv, IsVarArg, Outs, OutVals, Ins, DAG);
- if (!IsTailCall && CLI.CB && CLI.CB->isMustTailCall())
- report_fatal_error("failed to perform tail call elimination on a call "
- "site marked musttail");
-
-
- if (!TailCallOpt && IsTailCall)
- IsSibCall = true;
- if (IsTailCall)
- ++NumTailCalls;
- }
-
- SmallVector<CCValAssign, 16> ArgLocs;
- CCState CCInfo(CallConv, IsVarArg, DAG.getMachineFunction(), ArgLocs,
- *DAG.getContext());
- if (IsVarArg) {
-
-
- unsigned NumArgs = Outs.size();
- for (unsigned i = 0; i != NumArgs; ++i) {
- MVT ArgVT = Outs[i].VT;
- if (!Outs[i].IsFixed && ArgVT.isScalableVector())
- report_fatal_error("Passing SVE types to variadic functions is "
- "currently not supported");
- ISD::ArgFlagsTy ArgFlags = Outs[i].Flags;
- CCAssignFn *AssignFn = CCAssignFnForCall(CallConv,
- !Outs[i].IsFixed);
- bool Res = AssignFn(i, ArgVT, ArgVT, CCValAssign::Full, ArgFlags, CCInfo);
- assert(!Res && "Call operand has unhandled type");
- (void)Res;
- }
- } else {
-
-
-
-
-
-
- unsigned NumArgs = Outs.size();
- for (unsigned i = 0; i != NumArgs; ++i) {
- MVT ValVT = Outs[i].VT;
-
- EVT ActualVT = getValueType(DAG.getDataLayout(),
- CLI.getArgs()[Outs[i].OrigArgIndex].Ty,
- true);
- MVT ActualMVT = ActualVT.isSimple() ? ActualVT.getSimpleVT() : ValVT;
- ISD::ArgFlagsTy ArgFlags = Outs[i].Flags;
-
- if (ActualMVT == MVT::i1 || ActualMVT == MVT::i8)
- ValVT = MVT::i8;
- else if (ActualMVT == MVT::i16)
- ValVT = MVT::i16;
- CCAssignFn *AssignFn = CCAssignFnForCall(CallConv, false);
- bool Res = AssignFn(i, ValVT, ValVT, CCValAssign::Full, ArgFlags, CCInfo);
- assert(!Res && "Call operand has unhandled type");
- (void)Res;
- }
- }
-
- unsigned NumBytes = CCInfo.getNextStackOffset();
- if (IsSibCall) {
-
-
- NumBytes = 0;
- }
-
-
-
-
-
- int FPDiff = 0;
- if (IsTailCall && !IsSibCall) {
- unsigned NumReusableBytes = FuncInfo->getBytesInStackArgArea();
-
-
- NumBytes = alignTo(NumBytes, 16);
-
-
-
- FPDiff = NumReusableBytes - NumBytes;
-
-
-
-
-
- assert(FPDiff % 16 == 0 && "unaligned stack on tail call");
- }
-
-
- if (!IsSibCall)
- Chain = DAG.getCALLSEQ_START(Chain, NumBytes, 0, DL);
- SDValue StackPtr = DAG.getCopyFromReg(Chain, DL, AArch64::SP,
- getPointerTy(DAG.getDataLayout()));
- SmallVector<std::pair<unsigned, SDValue>, 8> RegsToPass;
- SmallSet<unsigned, 8> RegsUsed;
- SmallVector<SDValue, 8> MemOpChains;
- auto PtrVT = getPointerTy(DAG.getDataLayout());
- if (IsVarArg && CLI.CB && CLI.CB->isMustTailCall()) {
- const auto &Forwards = FuncInfo->getForwardedMustTailRegParms();
- for (const auto &F : Forwards) {
- SDValue Val = DAG.getCopyFromReg(Chain, DL, F.VReg, F.VT);
- RegsToPass.emplace_back(F.PReg, Val);
- }
- }
-
- unsigned ExtraArgLocs = 0;
- for (unsigned i = 0, e = Outs.size(); i != e; ++i) {
- CCValAssign &VA = ArgLocs[i - ExtraArgLocs];
- SDValue Arg = OutVals[i];
- ISD::ArgFlagsTy Flags = Outs[i].Flags;
-
- switch (VA.getLocInfo()) {
- default:
- llvm_unreachable("Unknown loc info!");
- case CCValAssign::Full:
- break;
- case CCValAssign::SExt:
- Arg = DAG.getNode(ISD::SIGN_EXTEND, DL, VA.getLocVT(), Arg);
- break;
- case CCValAssign::ZExt:
- Arg = DAG.getNode(ISD::ZERO_EXTEND, DL, VA.getLocVT(), Arg);
- break;
- case CCValAssign::AExt:
- if (Outs[i].ArgVT == MVT::i1) {
-
- Arg = DAG.getNode(ISD::TRUNCATE, DL, MVT::i1, Arg);
- Arg = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::i8, Arg);
- }
- Arg = DAG.getNode(ISD::ANY_EXTEND, DL, VA.getLocVT(), Arg);
- break;
- case CCValAssign::AExtUpper:
- assert(VA.getValVT() == MVT::i32 && "only expect 32 -> 64 upper bits");
- Arg = DAG.getNode(ISD::ANY_EXTEND, DL, VA.getLocVT(), Arg);
- Arg = DAG.getNode(ISD::SHL, DL, VA.getLocVT(), Arg,
- DAG.getConstant(32, DL, VA.getLocVT()));
- break;
- case CCValAssign::BCvt:
- Arg = DAG.getBitcast(VA.getLocVT(), Arg);
- break;
- case CCValAssign::Trunc:
- Arg = DAG.getZExtOrTrunc(Arg, DL, VA.getLocVT());
- break;
- case CCValAssign::FPExt:
- Arg = DAG.getNode(ISD::FP_EXTEND, DL, VA.getLocVT(), Arg);
- break;
- case CCValAssign::Indirect:
- assert(VA.getValVT().isScalableVector() &&
- "Only scalable vectors can be passed indirectly");
- uint64_t StoreSize = VA.getValVT().getStoreSize().getKnownMinSize();
- uint64_t PartSize = StoreSize;
- unsigned NumParts = 1;
- if (Outs[i].Flags.isInConsecutiveRegs()) {
- assert(!Outs[i].Flags.isInConsecutiveRegsLast());
- while (!Outs[i + NumParts - 1].Flags.isInConsecutiveRegsLast())
- ++NumParts;
- StoreSize *= NumParts;
- }
- MachineFrameInfo &MFI = DAG.getMachineFunction().getFrameInfo();
- Type *Ty = EVT(VA.getValVT()).getTypeForEVT(*DAG.getContext());
- Align Alignment = DAG.getDataLayout().getPrefTypeAlign(Ty);
- int FI = MFI.CreateStackObject(StoreSize, Alignment, false);
- MFI.setStackID(FI, TargetStackID::ScalableVector);
- MachinePointerInfo MPI =
- MachinePointerInfo::getFixedStack(DAG.getMachineFunction(), FI);
- SDValue Ptr = DAG.getFrameIndex(
- FI, DAG.getTargetLoweringInfo().getFrameIndexTy(DAG.getDataLayout()));
- SDValue SpillSlot = Ptr;
-
-
- while (NumParts) {
- Chain = DAG.getStore(Chain, DL, OutVals[i], Ptr, MPI);
- NumParts--;
- if (NumParts > 0) {
- SDValue BytesIncrement = DAG.getVScale(
- DL, Ptr.getValueType(),
- APInt(Ptr.getValueSizeInBits().getFixedSize(), PartSize));
- SDNodeFlags Flags;
- Flags.setNoUnsignedWrap(true);
- MPI = MachinePointerInfo(MPI.getAddrSpace());
- Ptr = DAG.getNode(ISD::ADD, DL, Ptr.getValueType(), Ptr,
- BytesIncrement, Flags);
- ExtraArgLocs++;
- i++;
- }
- }
- Arg = SpillSlot;
- break;
- }
- if (VA.isRegLoc()) {
- if (i == 0 && Flags.isReturned() && !Flags.isSwiftSelf() &&
- Outs[0].VT == MVT::i64) {
- assert(VA.getLocVT() == MVT::i64 &&
- "unexpected calling convention register assignment");
- assert(!Ins.empty() && Ins[0].VT == MVT::i64 &&
- "unexpected use of 'returned'");
- IsThisReturn = true;
- }
- if (RegsUsed.count(VA.getLocReg())) {
-
-
-
-
- SDValue &Bits =
- llvm::find_if(RegsToPass,
- [=](const std::pair<unsigned, SDValue> &Elt) {
- return Elt.first == VA.getLocReg();
- })
- ->second;
- Bits = DAG.getNode(ISD::OR, DL, Bits.getValueType(), Bits, Arg);
-
-
-
- llvm::erase_if(CSInfo, [&VA](MachineFunction::ArgRegPair ArgReg) {
- return ArgReg.Reg == VA.getLocReg();
- });
- } else {
- RegsToPass.emplace_back(VA.getLocReg(), Arg);
- RegsUsed.insert(VA.getLocReg());
- const TargetOptions &Options = DAG.getTarget().Options;
- if (Options.EmitCallSiteInfo)
- CSInfo.emplace_back(VA.getLocReg(), i);
- }
- } else {
- assert(VA.isMemLoc());
- SDValue DstAddr;
- MachinePointerInfo DstInfo;
-
-
- uint32_t BEAlign = 0;
- unsigned OpSize;
- if (VA.getLocInfo() == CCValAssign::Indirect)
- OpSize = VA.getLocVT().getFixedSizeInBits();
- else
- OpSize = Flags.isByVal() ? Flags.getByValSize() * 8
- : VA.getValVT().getSizeInBits();
- OpSize = (OpSize + 7) / 8;
- if (!Subtarget->isLittleEndian() && !Flags.isByVal() &&
- !Flags.isInConsecutiveRegs()) {
- if (OpSize < 8)
- BEAlign = 8 - OpSize;
- }
- unsigned LocMemOffset = VA.getLocMemOffset();
- int32_t Offset = LocMemOffset + BEAlign;
- SDValue PtrOff = DAG.getIntPtrConstant(Offset, DL);
- PtrOff = DAG.getNode(ISD::ADD, DL, PtrVT, StackPtr, PtrOff);
- if (IsTailCall) {
- Offset = Offset + FPDiff;
- int FI = MF.getFrameInfo().CreateFixedObject(OpSize, Offset, true);
- DstAddr = DAG.getFrameIndex(FI, PtrVT);
- DstInfo =
- MachinePointerInfo::getFixedStack(DAG.getMachineFunction(), FI);
-
-
-
- Chain = addTokenForArgument(Chain, DAG, MF.getFrameInfo(), FI);
- } else {
- SDValue PtrOff = DAG.getIntPtrConstant(Offset, DL);
- DstAddr = DAG.getNode(ISD::ADD, DL, PtrVT, StackPtr, PtrOff);
- DstInfo = MachinePointerInfo::getStack(DAG.getMachineFunction(),
- LocMemOffset);
- }
- if (Outs[i].Flags.isByVal()) {
- SDValue SizeNode =
- DAG.getConstant(Outs[i].Flags.getByValSize(), DL, MVT::i64);
- SDValue Cpy = DAG.getMemcpy(
- Chain, DL, DstAddr, Arg, SizeNode,
- Outs[i].Flags.getNonZeroByValAlign(),
- false, false,
- false, DstInfo, MachinePointerInfo());
- MemOpChains.push_back(Cpy);
- } else {
-
-
-
- if (VA.getValVT() == MVT::i1 || VA.getValVT() == MVT::i8 ||
- VA.getValVT() == MVT::i16)
- Arg = DAG.getNode(ISD::TRUNCATE, DL, VA.getValVT(), Arg);
- SDValue Store = DAG.getStore(Chain, DL, Arg, DstAddr, DstInfo);
- MemOpChains.push_back(Store);
- }
- }
- }
- if (!MemOpChains.empty())
- Chain = DAG.getNode(ISD::TokenFactor, DL, MVT::Other, MemOpChains);
-
-
- SDValue InFlag;
- for (auto &RegToPass : RegsToPass) {
- Chain = DAG.getCopyToReg(Chain, DL, RegToPass.first,
- RegToPass.second, InFlag);
- InFlag = Chain.getValue(1);
- }
-
-
-
- if (auto *G = dyn_cast<GlobalAddressSDNode>(Callee)) {
- auto GV = G->getGlobal();
- unsigned OpFlags =
- Subtarget->classifyGlobalFunctionReference(GV, getTargetMachine());
- if (OpFlags & AArch64II::MO_GOT) {
- Callee = DAG.getTargetGlobalAddress(GV, DL, PtrVT, 0, OpFlags);
- Callee = DAG.getNode(AArch64ISD::LOADgot, DL, PtrVT, Callee);
- } else {
- const GlobalValue *GV = G->getGlobal();
- Callee = DAG.getTargetGlobalAddress(GV, DL, PtrVT, 0, 0);
- }
- } else if (auto *S = dyn_cast<ExternalSymbolSDNode>(Callee)) {
- if (getTargetMachine().getCodeModel() == CodeModel::Large &&
- Subtarget->isTargetMachO()) {
- const char *Sym = S->getSymbol();
- Callee = DAG.getTargetExternalSymbol(Sym, PtrVT, AArch64II::MO_GOT);
- Callee = DAG.getNode(AArch64ISD::LOADgot, DL, PtrVT, Callee);
- } else {
- const char *Sym = S->getSymbol();
- Callee = DAG.getTargetExternalSymbol(Sym, PtrVT, 0);
- }
- }
-
-
-
-
- if (IsTailCall && !IsSibCall) {
- Chain = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(NumBytes, DL, true),
- DAG.getIntPtrConstant(0, DL, true), InFlag, DL);
- InFlag = Chain.getValue(1);
- }
- std::vector<SDValue> Ops;
- Ops.push_back(Chain);
- Ops.push_back(Callee);
- if (IsTailCall) {
-
-
-
- Ops.push_back(DAG.getTargetConstant(FPDiff, DL, MVT::i32));
- }
-
-
- for (auto &RegToPass : RegsToPass)
- Ops.push_back(DAG.getRegister(RegToPass.first,
- RegToPass.second.getValueType()));
-
- const uint32_t *Mask;
- const AArch64RegisterInfo *TRI = Subtarget->getRegisterInfo();
- if (IsThisReturn) {
-
- Mask = TRI->getThisReturnPreservedMask(MF, CallConv);
- if (!Mask) {
- IsThisReturn = false;
- Mask = TRI->getCallPreservedMask(MF, CallConv);
- }
- } else
- Mask = TRI->getCallPreservedMask(MF, CallConv);
- if (Subtarget->hasCustomCallingConv())
- TRI->UpdateCustomCallPreservedMask(MF, &Mask);
- if (TRI->isAnyArgRegReserved(MF))
- TRI->emitReservedArgRegCallError(MF);
- assert(Mask && "Missing call preserved mask for calling convention");
- Ops.push_back(DAG.getRegisterMask(Mask));
- if (InFlag.getNode())
- Ops.push_back(InFlag);
- SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue);
-
-
- if (IsTailCall) {
- MF.getFrameInfo().setHasTailCall();
- SDValue Ret = DAG.getNode(AArch64ISD::TC_RETURN, DL, NodeTys, Ops);
- DAG.addCallSiteInfo(Ret.getNode(), std::move(CSInfo));
- return Ret;
- }
- unsigned CallOpc = AArch64ISD::CALL;
-
-
-
- if (CLI.CB && CLI.CB->hasRetAttr("rv_marker")) {
- assert(!IsTailCall && "tail calls cannot be marked with rv_marker");
- CallOpc = AArch64ISD::CALL_RVMARKER;
- }
-
- Chain = DAG.getNode(CallOpc, DL, NodeTys, Ops);
- DAG.addNoMergeSiteInfo(Chain.getNode(), CLI.NoMerge);
- InFlag = Chain.getValue(1);
- DAG.addCallSiteInfo(Chain.getNode(), std::move(CSInfo));
- uint64_t CalleePopBytes =
- DoesCalleeRestoreStack(CallConv, TailCallOpt) ? alignTo(NumBytes, 16) : 0;
- Chain = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(NumBytes, DL, true),
- DAG.getIntPtrConstant(CalleePopBytes, DL, true),
- InFlag, DL);
- if (!Ins.empty())
- InFlag = Chain.getValue(1);
-
-
- return LowerCallResult(Chain, InFlag, CallConv, IsVarArg, Ins, DL, DAG,
- InVals, IsThisReturn,
- IsThisReturn ? OutVals[0] : SDValue());
- }
- bool AArch64TargetLowering::CanLowerReturn(
- CallingConv::ID CallConv, MachineFunction &MF, bool isVarArg,
- const SmallVectorImpl<ISD::OutputArg> &Outs, LLVMContext &Context) const {
- CCAssignFn *RetCC = CCAssignFnForReturn(CallConv);
- SmallVector<CCValAssign, 16> RVLocs;
- CCState CCInfo(CallConv, isVarArg, MF, RVLocs, Context);
- return CCInfo.CheckReturn(Outs, RetCC);
- }
- SDValue
- AArch64TargetLowering::LowerReturn(SDValue Chain, CallingConv::ID CallConv,
- bool isVarArg,
- const SmallVectorImpl<ISD::OutputArg> &Outs,
- const SmallVectorImpl<SDValue> &OutVals,
- const SDLoc &DL, SelectionDAG &DAG) const {
- auto &MF = DAG.getMachineFunction();
- auto *FuncInfo = MF.getInfo<AArch64FunctionInfo>();
- CCAssignFn *RetCC = CCAssignFnForReturn(CallConv);
- SmallVector<CCValAssign, 16> RVLocs;
- CCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), RVLocs,
- *DAG.getContext());
- CCInfo.AnalyzeReturn(Outs, RetCC);
-
- SDValue Flag;
- SmallVector<std::pair<unsigned, SDValue>, 4> RetVals;
- SmallSet<unsigned, 4> RegsUsed;
- for (unsigned i = 0, realRVLocIdx = 0; i != RVLocs.size();
- ++i, ++realRVLocIdx) {
- CCValAssign &VA = RVLocs[i];
- assert(VA.isRegLoc() && "Can only return in registers!");
- SDValue Arg = OutVals[realRVLocIdx];
- switch (VA.getLocInfo()) {
- default:
- llvm_unreachable("Unknown loc info!");
- case CCValAssign::Full:
- if (Outs[i].ArgVT == MVT::i1) {
-
-
-
- Arg = DAG.getNode(ISD::TRUNCATE, DL, MVT::i1, Arg);
- Arg = DAG.getNode(ISD::ZERO_EXTEND, DL, VA.getLocVT(), Arg);
- }
- break;
- case CCValAssign::BCvt:
- Arg = DAG.getNode(ISD::BITCAST, DL, VA.getLocVT(), Arg);
- break;
- case CCValAssign::AExt:
- case CCValAssign::ZExt:
- Arg = DAG.getZExtOrTrunc(Arg, DL, VA.getLocVT());
- break;
- case CCValAssign::AExtUpper:
- assert(VA.getValVT() == MVT::i32 && "only expect 32 -> 64 upper bits");
- Arg = DAG.getZExtOrTrunc(Arg, DL, VA.getLocVT());
- Arg = DAG.getNode(ISD::SHL, DL, VA.getLocVT(), Arg,
- DAG.getConstant(32, DL, VA.getLocVT()));
- break;
- }
- if (RegsUsed.count(VA.getLocReg())) {
- SDValue &Bits =
- llvm::find_if(RetVals, [=](const std::pair<unsigned, SDValue> &Elt) {
- return Elt.first == VA.getLocReg();
- })->second;
- Bits = DAG.getNode(ISD::OR, DL, Bits.getValueType(), Bits, Arg);
- } else {
- RetVals.emplace_back(VA.getLocReg(), Arg);
- RegsUsed.insert(VA.getLocReg());
- }
- }
- SmallVector<SDValue, 4> RetOps(1, Chain);
- for (auto &RetVal : RetVals) {
- Chain = DAG.getCopyToReg(Chain, DL, RetVal.first, RetVal.second, Flag);
- Flag = Chain.getValue(1);
- RetOps.push_back(
- DAG.getRegister(RetVal.first, RetVal.second.getValueType()));
- }
-
-
-
-
- if (unsigned SRetReg = FuncInfo->getSRetReturnReg()) {
- SDValue Val = DAG.getCopyFromReg(RetOps[0], DL, SRetReg,
- getPointerTy(MF.getDataLayout()));
- unsigned RetValReg = AArch64::X0;
- Chain = DAG.getCopyToReg(Chain, DL, RetValReg, Val, Flag);
- Flag = Chain.getValue(1);
- RetOps.push_back(
- DAG.getRegister(RetValReg, getPointerTy(DAG.getDataLayout())));
- }
- const AArch64RegisterInfo *TRI = Subtarget->getRegisterInfo();
- const MCPhysReg *I =
- TRI->getCalleeSavedRegsViaCopy(&DAG.getMachineFunction());
- if (I) {
- for (; *I; ++I) {
- if (AArch64::GPR64RegClass.contains(*I))
- RetOps.push_back(DAG.getRegister(*I, MVT::i64));
- else if (AArch64::FPR64RegClass.contains(*I))
- RetOps.push_back(DAG.getRegister(*I, MVT::getFloatingPointVT(64)));
- else
- llvm_unreachable("Unexpected register class in CSRsViaCopy!");
- }
- }
- RetOps[0] = Chain;
-
- if (Flag.getNode())
- RetOps.push_back(Flag);
- return DAG.getNode(AArch64ISD::RET_FLAG, DL, MVT::Other, RetOps);
- }
- SDValue AArch64TargetLowering::getTargetNode(GlobalAddressSDNode *N, EVT Ty,
- SelectionDAG &DAG,
- unsigned Flag) const {
- return DAG.getTargetGlobalAddress(N->getGlobal(), SDLoc(N), Ty,
- N->getOffset(), Flag);
- }
- SDValue AArch64TargetLowering::getTargetNode(JumpTableSDNode *N, EVT Ty,
- SelectionDAG &DAG,
- unsigned Flag) const {
- return DAG.getTargetJumpTable(N->getIndex(), Ty, Flag);
- }
- SDValue AArch64TargetLowering::getTargetNode(ConstantPoolSDNode *N, EVT Ty,
- SelectionDAG &DAG,
- unsigned Flag) const {
- return DAG.getTargetConstantPool(N->getConstVal(), Ty, N->getAlign(),
- N->getOffset(), Flag);
- }
- SDValue AArch64TargetLowering::getTargetNode(BlockAddressSDNode* N, EVT Ty,
- SelectionDAG &DAG,
- unsigned Flag) const {
- return DAG.getTargetBlockAddress(N->getBlockAddress(), Ty, 0, Flag);
- }
- template <class NodeTy>
- SDValue AArch64TargetLowering::getGOT(NodeTy *N, SelectionDAG &DAG,
- unsigned Flags) const {
- LLVM_DEBUG(dbgs() << "AArch64TargetLowering::getGOT\n");
- SDLoc DL(N);
- EVT Ty = getPointerTy(DAG.getDataLayout());
- SDValue GotAddr = getTargetNode(N, Ty, DAG, AArch64II::MO_GOT | Flags);
-
-
- return DAG.getNode(AArch64ISD::LOADgot, DL, Ty, GotAddr);
- }
- template <class NodeTy>
- SDValue AArch64TargetLowering::getAddrLarge(NodeTy *N, SelectionDAG &DAG,
- unsigned Flags) const {
- LLVM_DEBUG(dbgs() << "AArch64TargetLowering::getAddrLarge\n");
- SDLoc DL(N);
- EVT Ty = getPointerTy(DAG.getDataLayout());
- const unsigned char MO_NC = AArch64II::MO_NC;
- return DAG.getNode(
- AArch64ISD::WrapperLarge, DL, Ty,
- getTargetNode(N, Ty, DAG, AArch64II::MO_G3 | Flags),
- getTargetNode(N, Ty, DAG, AArch64II::MO_G2 | MO_NC | Flags),
- getTargetNode(N, Ty, DAG, AArch64II::MO_G1 | MO_NC | Flags),
- getTargetNode(N, Ty, DAG, AArch64II::MO_G0 | MO_NC | Flags));
- }
- template <class NodeTy>
- SDValue AArch64TargetLowering::getAddr(NodeTy *N, SelectionDAG &DAG,
- unsigned Flags) const {
- LLVM_DEBUG(dbgs() << "AArch64TargetLowering::getAddr\n");
- SDLoc DL(N);
- EVT Ty = getPointerTy(DAG.getDataLayout());
- SDValue Hi = getTargetNode(N, Ty, DAG, AArch64II::MO_PAGE | Flags);
- SDValue Lo = getTargetNode(N, Ty, DAG,
- AArch64II::MO_PAGEOFF | AArch64II::MO_NC | Flags);
- SDValue ADRP = DAG.getNode(AArch64ISD::ADRP, DL, Ty, Hi);
- return DAG.getNode(AArch64ISD::ADDlow, DL, Ty, ADRP, Lo);
- }
- template <class NodeTy>
- SDValue AArch64TargetLowering::getAddrTiny(NodeTy *N, SelectionDAG &DAG,
- unsigned Flags) const {
- LLVM_DEBUG(dbgs() << "AArch64TargetLowering::getAddrTiny\n");
- SDLoc DL(N);
- EVT Ty = getPointerTy(DAG.getDataLayout());
- SDValue Sym = getTargetNode(N, Ty, DAG, Flags);
- return DAG.getNode(AArch64ISD::ADR, DL, Ty, Sym);
- }
- SDValue AArch64TargetLowering::LowerGlobalAddress(SDValue Op,
- SelectionDAG &DAG) const {
- GlobalAddressSDNode *GN = cast<GlobalAddressSDNode>(Op);
- const GlobalValue *GV = GN->getGlobal();
- unsigned OpFlags = Subtarget->ClassifyGlobalReference(GV, getTargetMachine());
- if (OpFlags != AArch64II::MO_NO_FLAG)
- assert(cast<GlobalAddressSDNode>(Op)->getOffset() == 0 &&
- "unexpected offset in global node");
-
-
- if ((OpFlags & AArch64II::MO_GOT) != 0) {
- return getGOT(GN, DAG, OpFlags);
- }
- SDValue Result;
- if (getTargetMachine().getCodeModel() == CodeModel::Large) {
- Result = getAddrLarge(GN, DAG, OpFlags);
- } else if (getTargetMachine().getCodeModel() == CodeModel::Tiny) {
- Result = getAddrTiny(GN, DAG, OpFlags);
- } else {
- Result = getAddr(GN, DAG, OpFlags);
- }
- EVT PtrVT = getPointerTy(DAG.getDataLayout());
- SDLoc DL(GN);
- if (OpFlags & (AArch64II::MO_DLLIMPORT | AArch64II::MO_COFFSTUB))
- Result = DAG.getLoad(PtrVT, DL, DAG.getEntryNode(), Result,
- MachinePointerInfo::getGOT(DAG.getMachineFunction()));
- return Result;
- }
- SDValue
- AArch64TargetLowering::LowerDarwinGlobalTLSAddress(SDValue Op,
- SelectionDAG &DAG) const {
- assert(Subtarget->isTargetDarwin() &&
- "This function expects a Darwin target");
- SDLoc DL(Op);
- MVT PtrVT = getPointerTy(DAG.getDataLayout());
- MVT PtrMemVT = getPointerMemTy(DAG.getDataLayout());
- const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal();
- SDValue TLVPAddr =
- DAG.getTargetGlobalAddress(GV, DL, PtrVT, 0, AArch64II::MO_TLS);
- SDValue DescAddr = DAG.getNode(AArch64ISD::LOADgot, DL, PtrVT, TLVPAddr);
-
-
- SDValue Chain = DAG.getEntryNode();
- SDValue FuncTLVGet = DAG.getLoad(
- PtrMemVT, DL, Chain, DescAddr,
- MachinePointerInfo::getGOT(DAG.getMachineFunction()),
- Align(PtrMemVT.getSizeInBits() / 8),
- MachineMemOperand::MOInvariant | MachineMemOperand::MODereferenceable);
- Chain = FuncTLVGet.getValue(1);
-
- FuncTLVGet = DAG.getZExtOrTrunc(FuncTLVGet, DL, PtrVT);
- MachineFrameInfo &MFI = DAG.getMachineFunction().getFrameInfo();
- MFI.setAdjustsStack(true);
-
-
-
- const AArch64RegisterInfo *TRI = Subtarget->getRegisterInfo();
- const uint32_t *Mask = TRI->getTLSCallPreservedMask();
- if (Subtarget->hasCustomCallingConv())
- TRI->UpdateCustomCallPreservedMask(DAG.getMachineFunction(), &Mask);
-
-
-
- Chain = DAG.getCopyToReg(Chain, DL, AArch64::X0, DescAddr, SDValue());
- Chain =
- DAG.getNode(AArch64ISD::CALL, DL, DAG.getVTList(MVT::Other, MVT::Glue),
- Chain, FuncTLVGet, DAG.getRegister(AArch64::X0, MVT::i64),
- DAG.getRegisterMask(Mask), Chain.getValue(1));
- return DAG.getCopyFromReg(Chain, DL, AArch64::X0, PtrVT, Chain.getValue(1));
- }
- SDValue AArch64TargetLowering::LowerELFTLSLocalExec(const GlobalValue *GV,
- SDValue ThreadBase,
- const SDLoc &DL,
- SelectionDAG &DAG) const {
- EVT PtrVT = getPointerTy(DAG.getDataLayout());
- SDValue TPOff, Addr;
- switch (DAG.getTarget().Options.TLSSize) {
- default:
- llvm_unreachable("Unexpected TLS size");
- case 12: {
-
-
- SDValue Var = DAG.getTargetGlobalAddress(
- GV, DL, PtrVT, 0, AArch64II::MO_TLS | AArch64II::MO_PAGEOFF);
- return SDValue(DAG.getMachineNode(AArch64::ADDXri, DL, PtrVT, ThreadBase,
- Var,
- DAG.getTargetConstant(0, DL, MVT::i32)),
- 0);
- }
- case 24: {
-
-
-
- SDValue HiVar = DAG.getTargetGlobalAddress(
- GV, DL, PtrVT, 0, AArch64II::MO_TLS | AArch64II::MO_HI12);
- SDValue LoVar = DAG.getTargetGlobalAddress(
- GV, DL, PtrVT, 0,
- AArch64II::MO_TLS | AArch64II::MO_PAGEOFF | AArch64II::MO_NC);
- Addr = SDValue(DAG.getMachineNode(AArch64::ADDXri, DL, PtrVT, ThreadBase,
- HiVar,
- DAG.getTargetConstant(0, DL, MVT::i32)),
- 0);
- return SDValue(DAG.getMachineNode(AArch64::ADDXri, DL, PtrVT, Addr,
- LoVar,
- DAG.getTargetConstant(0, DL, MVT::i32)),
- 0);
- }
- case 32: {
-
-
-
-
- SDValue HiVar = DAG.getTargetGlobalAddress(
- GV, DL, PtrVT, 0, AArch64II::MO_TLS | AArch64II::MO_G1);
- SDValue LoVar = DAG.getTargetGlobalAddress(
- GV, DL, PtrVT, 0,
- AArch64II::MO_TLS | AArch64II::MO_G0 | AArch64II::MO_NC);
- TPOff = SDValue(DAG.getMachineNode(AArch64::MOVZXi, DL, PtrVT, HiVar,
- DAG.getTargetConstant(16, DL, MVT::i32)),
- 0);
- TPOff = SDValue(DAG.getMachineNode(AArch64::MOVKXi, DL, PtrVT, TPOff, LoVar,
- DAG.getTargetConstant(0, DL, MVT::i32)),
- 0);
- return DAG.getNode(ISD::ADD, DL, PtrVT, ThreadBase, TPOff);
- }
- case 48: {
-
-
-
-
-
- SDValue HiVar = DAG.getTargetGlobalAddress(
- GV, DL, PtrVT, 0, AArch64II::MO_TLS | AArch64II::MO_G2);
- SDValue MiVar = DAG.getTargetGlobalAddress(
- GV, DL, PtrVT, 0,
- AArch64II::MO_TLS | AArch64II::MO_G1 | AArch64II::MO_NC);
- SDValue LoVar = DAG.getTargetGlobalAddress(
- GV, DL, PtrVT, 0,
- AArch64II::MO_TLS | AArch64II::MO_G0 | AArch64II::MO_NC);
- TPOff = SDValue(DAG.getMachineNode(AArch64::MOVZXi, DL, PtrVT, HiVar,
- DAG.getTargetConstant(32, DL, MVT::i32)),
- 0);
- TPOff = SDValue(DAG.getMachineNode(AArch64::MOVKXi, DL, PtrVT, TPOff, MiVar,
- DAG.getTargetConstant(16, DL, MVT::i32)),
- 0);
- TPOff = SDValue(DAG.getMachineNode(AArch64::MOVKXi, DL, PtrVT, TPOff, LoVar,
- DAG.getTargetConstant(0, DL, MVT::i32)),
- 0);
- return DAG.getNode(ISD::ADD, DL, PtrVT, ThreadBase, TPOff);
- }
- }
- }
- SDValue AArch64TargetLowering::LowerELFTLSDescCallSeq(SDValue SymAddr,
- const SDLoc &DL,
- SelectionDAG &DAG) const {
- EVT PtrVT = getPointerTy(DAG.getDataLayout());
- SDValue Chain = DAG.getEntryNode();
- SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue);
- Chain =
- DAG.getNode(AArch64ISD::TLSDESC_CALLSEQ, DL, NodeTys, {Chain, SymAddr});
- SDValue Glue = Chain.getValue(1);
- return DAG.getCopyFromReg(Chain, DL, AArch64::X0, PtrVT, Glue);
- }
- SDValue
- AArch64TargetLowering::LowerELFGlobalTLSAddress(SDValue Op,
- SelectionDAG &DAG) const {
- assert(Subtarget->isTargetELF() && "This function expects an ELF target");
- const GlobalAddressSDNode *GA = cast<GlobalAddressSDNode>(Op);
- TLSModel::Model Model = getTargetMachine().getTLSModel(GA->getGlobal());
- if (!EnableAArch64ELFLocalDynamicTLSGeneration) {
- if (Model == TLSModel::LocalDynamic)
- Model = TLSModel::GeneralDynamic;
- }
- if (getTargetMachine().getCodeModel() == CodeModel::Large &&
- Model != TLSModel::LocalExec)
- report_fatal_error("ELF TLS only supported in small memory model or "
- "in local exec TLS model");
-
-
-
-
-
-
- SDValue TPOff;
- EVT PtrVT = getPointerTy(DAG.getDataLayout());
- SDLoc DL(Op);
- const GlobalValue *GV = GA->getGlobal();
- SDValue ThreadBase = DAG.getNode(AArch64ISD::THREAD_POINTER, DL, PtrVT);
- if (Model == TLSModel::LocalExec) {
- return LowerELFTLSLocalExec(GV, ThreadBase, DL, DAG);
- } else if (Model == TLSModel::InitialExec) {
- TPOff = DAG.getTargetGlobalAddress(GV, DL, PtrVT, 0, AArch64II::MO_TLS);
- TPOff = DAG.getNode(AArch64ISD::LOADgot, DL, PtrVT, TPOff);
- } else if (Model == TLSModel::LocalDynamic) {
-
-
-
-
-
- AArch64FunctionInfo *MFI =
- DAG.getMachineFunction().getInfo<AArch64FunctionInfo>();
- MFI->incNumLocalDynamicTLSAccesses();
-
-
-
- SDValue SymAddr = DAG.getTargetExternalSymbol("_TLS_MODULE_BASE_", PtrVT,
- AArch64II::MO_TLS);
-
-
- TPOff = LowerELFTLSDescCallSeq(SymAddr, DL, DAG);
-
-
- SDValue HiVar = DAG.getTargetGlobalAddress(
- GV, DL, MVT::i64, 0, AArch64II::MO_TLS | AArch64II::MO_HI12);
- SDValue LoVar = DAG.getTargetGlobalAddress(
- GV, DL, MVT::i64, 0,
- AArch64II::MO_TLS | AArch64II::MO_PAGEOFF | AArch64II::MO_NC);
- TPOff = SDValue(DAG.getMachineNode(AArch64::ADDXri, DL, PtrVT, TPOff, HiVar,
- DAG.getTargetConstant(0, DL, MVT::i32)),
- 0);
- TPOff = SDValue(DAG.getMachineNode(AArch64::ADDXri, DL, PtrVT, TPOff, LoVar,
- DAG.getTargetConstant(0, DL, MVT::i32)),
- 0);
- } else if (Model == TLSModel::GeneralDynamic) {
-
-
-
- SDValue SymAddr =
- DAG.getTargetGlobalAddress(GV, DL, PtrVT, 0, AArch64II::MO_TLS);
-
- TPOff = LowerELFTLSDescCallSeq(SymAddr, DL, DAG);
- } else
- llvm_unreachable("Unsupported ELF TLS access model");
- return DAG.getNode(ISD::ADD, DL, PtrVT, ThreadBase, TPOff);
- }
- SDValue
- AArch64TargetLowering::LowerWindowsGlobalTLSAddress(SDValue Op,
- SelectionDAG &DAG) const {
- assert(Subtarget->isTargetWindows() && "Windows specific TLS lowering");
- SDValue Chain = DAG.getEntryNode();
- EVT PtrVT = getPointerTy(DAG.getDataLayout());
- SDLoc DL(Op);
- SDValue TEB = DAG.getRegister(AArch64::X18, MVT::i64);
-
-
- SDValue TLSArray =
- DAG.getNode(ISD::ADD, DL, PtrVT, TEB, DAG.getIntPtrConstant(0x58, DL));
- TLSArray = DAG.getLoad(PtrVT, DL, Chain, TLSArray, MachinePointerInfo());
- Chain = TLSArray.getValue(1);
-
-
-
-
- SDValue TLSIndexHi =
- DAG.getTargetExternalSymbol("_tls_index", PtrVT, AArch64II::MO_PAGE);
- SDValue TLSIndexLo = DAG.getTargetExternalSymbol(
- "_tls_index", PtrVT, AArch64II::MO_PAGEOFF | AArch64II::MO_NC);
- SDValue ADRP = DAG.getNode(AArch64ISD::ADRP, DL, PtrVT, TLSIndexHi);
- SDValue TLSIndex =
- DAG.getNode(AArch64ISD::ADDlow, DL, PtrVT, ADRP, TLSIndexLo);
- TLSIndex = DAG.getLoad(MVT::i32, DL, Chain, TLSIndex, MachinePointerInfo());
- Chain = TLSIndex.getValue(1);
-
-
- TLSIndex = DAG.getNode(ISD::ZERO_EXTEND, DL, PtrVT, TLSIndex);
- SDValue Slot = DAG.getNode(ISD::SHL, DL, PtrVT, TLSIndex,
- DAG.getConstant(3, DL, PtrVT));
- SDValue TLS = DAG.getLoad(PtrVT, DL, Chain,
- DAG.getNode(ISD::ADD, DL, PtrVT, TLSArray, Slot),
- MachinePointerInfo());
- Chain = TLS.getValue(1);
- const GlobalAddressSDNode *GA = cast<GlobalAddressSDNode>(Op);
- const GlobalValue *GV = GA->getGlobal();
- SDValue TGAHi = DAG.getTargetGlobalAddress(
- GV, DL, PtrVT, 0, AArch64II::MO_TLS | AArch64II::MO_HI12);
- SDValue TGALo = DAG.getTargetGlobalAddress(
- GV, DL, PtrVT, 0,
- AArch64II::MO_TLS | AArch64II::MO_PAGEOFF | AArch64II::MO_NC);
-
- SDValue Addr =
- SDValue(DAG.getMachineNode(AArch64::ADDXri, DL, PtrVT, TLS, TGAHi,
- DAG.getTargetConstant(0, DL, MVT::i32)),
- 0);
- Addr = DAG.getNode(AArch64ISD::ADDlow, DL, PtrVT, Addr, TGALo);
- return Addr;
- }
- SDValue AArch64TargetLowering::LowerGlobalTLSAddress(SDValue Op,
- SelectionDAG &DAG) const {
- const GlobalAddressSDNode *GA = cast<GlobalAddressSDNode>(Op);
- if (DAG.getTarget().useEmulatedTLS())
- return LowerToTLSEmulatedModel(GA, DAG);
- if (Subtarget->isTargetDarwin())
- return LowerDarwinGlobalTLSAddress(Op, DAG);
- if (Subtarget->isTargetELF())
- return LowerELFGlobalTLSAddress(Op, DAG);
- if (Subtarget->isTargetWindows())
- return LowerWindowsGlobalTLSAddress(Op, DAG);
- llvm_unreachable("Unexpected platform trying to use TLS");
- }
- std::pair<SDValue, uint64_t> lookThroughSignExtension(SDValue Val) {
- if (Val.getOpcode() == ISD::SIGN_EXTEND_INREG)
- return {Val.getOperand(0),
- cast<VTSDNode>(Val.getOperand(1))->getVT().getFixedSizeInBits() -
- 1};
- if (Val.getOpcode() == ISD::SIGN_EXTEND)
- return {Val.getOperand(0),
- Val.getOperand(0)->getValueType(0).getFixedSizeInBits() - 1};
- return {Val, Val.getValueSizeInBits() - 1};
- }
- SDValue AArch64TargetLowering::LowerBR_CC(SDValue Op, SelectionDAG &DAG) const {
- SDValue Chain = Op.getOperand(0);
- ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(1))->get();
- SDValue LHS = Op.getOperand(2);
- SDValue RHS = Op.getOperand(3);
- SDValue Dest = Op.getOperand(4);
- SDLoc dl(Op);
- MachineFunction &MF = DAG.getMachineFunction();
-
-
-
- bool ProduceNonFlagSettingCondBr =
- !MF.getFunction().hasFnAttribute(Attribute::SpeculativeLoadHardening);
-
-
-
- if (LHS.getValueType() == MVT::f128) {
- softenSetCCOperands(DAG, MVT::f128, LHS, RHS, CC, dl, LHS, RHS);
-
-
- if (!RHS.getNode()) {
- RHS = DAG.getConstant(0, dl, LHS.getValueType());
- CC = ISD::SETNE;
- }
- }
-
-
- if (ISD::isOverflowIntrOpRes(LHS) && isOneConstant(RHS) &&
- (CC == ISD::SETEQ || CC == ISD::SETNE)) {
-
- if (!DAG.getTargetLoweringInfo().isTypeLegal(LHS->getValueType(0)))
- return SDValue();
-
- AArch64CC::CondCode OFCC;
- SDValue Value, Overflow;
- std::tie(Value, Overflow) = getAArch64XALUOOp(OFCC, LHS.getValue(0), DAG);
- if (CC == ISD::SETNE)
- OFCC = getInvertedCondCode(OFCC);
- SDValue CCVal = DAG.getConstant(OFCC, dl, MVT::i32);
- return DAG.getNode(AArch64ISD::BRCOND, dl, MVT::Other, Chain, Dest, CCVal,
- Overflow);
- }
- if (LHS.getValueType().isInteger()) {
- assert((LHS.getValueType() == RHS.getValueType()) &&
- (LHS.getValueType() == MVT::i32 || LHS.getValueType() == MVT::i64));
-
-
- const ConstantSDNode *RHSC = dyn_cast<ConstantSDNode>(RHS);
- if (RHSC && RHSC->getZExtValue() == 0 && ProduceNonFlagSettingCondBr) {
- if (CC == ISD::SETEQ) {
-
-
-
-
- if (LHS.getOpcode() == ISD::AND &&
- isa<ConstantSDNode>(LHS.getOperand(1)) &&
- isPowerOf2_64(LHS.getConstantOperandVal(1))) {
- SDValue Test = LHS.getOperand(0);
- uint64_t Mask = LHS.getConstantOperandVal(1);
- return DAG.getNode(AArch64ISD::TBZ, dl, MVT::Other, Chain, Test,
- DAG.getConstant(Log2_64(Mask), dl, MVT::i64),
- Dest);
- }
- return DAG.getNode(AArch64ISD::CBZ, dl, MVT::Other, Chain, LHS, Dest);
- } else if (CC == ISD::SETNE) {
-
-
-
-
- if (LHS.getOpcode() == ISD::AND &&
- isa<ConstantSDNode>(LHS.getOperand(1)) &&
- isPowerOf2_64(LHS.getConstantOperandVal(1))) {
- SDValue Test = LHS.getOperand(0);
- uint64_t Mask = LHS.getConstantOperandVal(1);
- return DAG.getNode(AArch64ISD::TBNZ, dl, MVT::Other, Chain, Test,
- DAG.getConstant(Log2_64(Mask), dl, MVT::i64),
- Dest);
- }
- return DAG.getNode(AArch64ISD::CBNZ, dl, MVT::Other, Chain, LHS, Dest);
- } else if (CC == ISD::SETLT && LHS.getOpcode() != ISD::AND) {
-
-
-
- uint64_t SignBitPos;
- std::tie(LHS, SignBitPos) = lookThroughSignExtension(LHS);
- return DAG.getNode(AArch64ISD::TBNZ, dl, MVT::Other, Chain, LHS,
- DAG.getConstant(SignBitPos, dl, MVT::i64), Dest);
- }
- }
- if (RHSC && RHSC->getSExtValue() == -1 && CC == ISD::SETGT &&
- LHS.getOpcode() != ISD::AND && ProduceNonFlagSettingCondBr) {
-
-
-
- uint64_t SignBitPos;
- std::tie(LHS, SignBitPos) = lookThroughSignExtension(LHS);
- return DAG.getNode(AArch64ISD::TBZ, dl, MVT::Other, Chain, LHS,
- DAG.getConstant(SignBitPos, dl, MVT::i64), Dest);
- }
- SDValue CCVal;
- SDValue Cmp = getAArch64Cmp(LHS, RHS, CC, CCVal, DAG, dl);
- return DAG.getNode(AArch64ISD::BRCOND, dl, MVT::Other, Chain, Dest, CCVal,
- Cmp);
- }
- assert(LHS.getValueType() == MVT::f16 || LHS.getValueType() == MVT::bf16 ||
- LHS.getValueType() == MVT::f32 || LHS.getValueType() == MVT::f64);
-
-
- SDValue Cmp = emitComparison(LHS, RHS, CC, dl, DAG);
- AArch64CC::CondCode CC1, CC2;
- changeFPCCToAArch64CC(CC, CC1, CC2);
- SDValue CC1Val = DAG.getConstant(CC1, dl, MVT::i32);
- SDValue BR1 =
- DAG.getNode(AArch64ISD::BRCOND, dl, MVT::Other, Chain, Dest, CC1Val, Cmp);
- if (CC2 != AArch64CC::AL) {
- SDValue CC2Val = DAG.getConstant(CC2, dl, MVT::i32);
- return DAG.getNode(AArch64ISD::BRCOND, dl, MVT::Other, BR1, Dest, CC2Val,
- Cmp);
- }
- return BR1;
- }
- SDValue AArch64TargetLowering::LowerFCOPYSIGN(SDValue Op,
- SelectionDAG &DAG) const {
- EVT VT = Op.getValueType();
- SDLoc DL(Op);
- SDValue In1 = Op.getOperand(0);
- SDValue In2 = Op.getOperand(1);
- EVT SrcVT = In2.getValueType();
- if (SrcVT.bitsLT(VT))
- In2 = DAG.getNode(ISD::FP_EXTEND, DL, VT, In2);
- else if (SrcVT.bitsGT(VT))
- In2 = DAG.getNode(ISD::FP_ROUND, DL, VT, In2, DAG.getIntPtrConstant(0, DL));
- EVT VecVT;
- uint64_t EltMask;
- SDValue VecVal1, VecVal2;
- auto setVecVal = [&] (int Idx) {
- if (!VT.isVector()) {
- VecVal1 = DAG.getTargetInsertSubreg(Idx, DL, VecVT,
- DAG.getUNDEF(VecVT), In1);
- VecVal2 = DAG.getTargetInsertSubreg(Idx, DL, VecVT,
- DAG.getUNDEF(VecVT), In2);
- } else {
- VecVal1 = DAG.getNode(ISD::BITCAST, DL, VecVT, In1);
- VecVal2 = DAG.getNode(ISD::BITCAST, DL, VecVT, In2);
- }
- };
- if (VT == MVT::f32 || VT == MVT::v2f32 || VT == MVT::v4f32) {
- VecVT = (VT == MVT::v2f32 ? MVT::v2i32 : MVT::v4i32);
- EltMask = 0x80000000ULL;
- setVecVal(AArch64::ssub);
- } else if (VT == MVT::f64 || VT == MVT::v2f64) {
- VecVT = MVT::v2i64;
-
-
-
- EltMask = 0;
- setVecVal(AArch64::dsub);
- } else if (VT == MVT::f16 || VT == MVT::v4f16 || VT == MVT::v8f16) {
- VecVT = (VT == MVT::v4f16 ? MVT::v4i16 : MVT::v8i16);
- EltMask = 0x8000ULL;
- setVecVal(AArch64::hsub);
- } else {
- llvm_unreachable("Invalid type for copysign!");
- }
- SDValue BuildVec = DAG.getConstant(EltMask, DL, VecVT);
-
-
- if (VT == MVT::f64 || VT == MVT::v2f64) {
- BuildVec = DAG.getNode(ISD::BITCAST, DL, MVT::v2f64, BuildVec);
- BuildVec = DAG.getNode(ISD::FNEG, DL, MVT::v2f64, BuildVec);
- BuildVec = DAG.getNode(ISD::BITCAST, DL, MVT::v2i64, BuildVec);
- }
- SDValue Sel =
- DAG.getNode(AArch64ISD::BIT, DL, VecVT, VecVal1, VecVal2, BuildVec);
- if (VT == MVT::f16)
- return DAG.getTargetExtractSubreg(AArch64::hsub, DL, VT, Sel);
- if (VT == MVT::f32)
- return DAG.getTargetExtractSubreg(AArch64::ssub, DL, VT, Sel);
- else if (VT == MVT::f64)
- return DAG.getTargetExtractSubreg(AArch64::dsub, DL, VT, Sel);
- else
- return DAG.getNode(ISD::BITCAST, DL, VT, Sel);
- }
- SDValue AArch64TargetLowering::LowerCTPOP(SDValue Op, SelectionDAG &DAG) const {
- if (DAG.getMachineFunction().getFunction().hasFnAttribute(
- Attribute::NoImplicitFloat))
- return SDValue();
- if (!Subtarget->hasNEON())
- return SDValue();
-
-
-
-
-
-
-
-
- SDValue Val = Op.getOperand(0);
- SDLoc DL(Op);
- EVT VT = Op.getValueType();
- if (VT == MVT::i32 || VT == MVT::i64) {
- if (VT == MVT::i32)
- Val = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::i64, Val);
- Val = DAG.getNode(ISD::BITCAST, DL, MVT::v8i8, Val);
- SDValue CtPop = DAG.getNode(ISD::CTPOP, DL, MVT::v8i8, Val);
- SDValue UaddLV = DAG.getNode(
- ISD::INTRINSIC_WO_CHAIN, DL, MVT::i32,
- DAG.getConstant(Intrinsic::aarch64_neon_uaddlv, DL, MVT::i32), CtPop);
- if (VT == MVT::i64)
- UaddLV = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::i64, UaddLV);
- return UaddLV;
- } else if (VT == MVT::i128) {
- Val = DAG.getNode(ISD::BITCAST, DL, MVT::v16i8, Val);
- SDValue CtPop = DAG.getNode(ISD::CTPOP, DL, MVT::v16i8, Val);
- SDValue UaddLV = DAG.getNode(
- ISD::INTRINSIC_WO_CHAIN, DL, MVT::i32,
- DAG.getConstant(Intrinsic::aarch64_neon_uaddlv, DL, MVT::i32), CtPop);
- return DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::i128, UaddLV);
- }
- if (VT.isScalableVector() || useSVEForFixedLengthVectorVT(VT))
- return LowerToPredicatedOp(Op, DAG, AArch64ISD::CTPOP_MERGE_PASSTHRU);
- assert((VT == MVT::v1i64 || VT == MVT::v2i64 || VT == MVT::v2i32 ||
- VT == MVT::v4i32 || VT == MVT::v4i16 || VT == MVT::v8i16) &&
- "Unexpected type for custom ctpop lowering");
- EVT VT8Bit = VT.is64BitVector() ? MVT::v8i8 : MVT::v16i8;
- Val = DAG.getBitcast(VT8Bit, Val);
- Val = DAG.getNode(ISD::CTPOP, DL, VT8Bit, Val);
-
- unsigned EltSize = 8;
- unsigned NumElts = VT.is64BitVector() ? 8 : 16;
- while (EltSize != VT.getScalarSizeInBits()) {
- EltSize *= 2;
- NumElts /= 2;
- MVT WidenVT = MVT::getVectorVT(MVT::getIntegerVT(EltSize), NumElts);
- Val = DAG.getNode(
- ISD::INTRINSIC_WO_CHAIN, DL, WidenVT,
- DAG.getConstant(Intrinsic::aarch64_neon_uaddlp, DL, MVT::i32), Val);
- }
- return Val;
- }
- SDValue AArch64TargetLowering::LowerCTTZ(SDValue Op, SelectionDAG &DAG) const {
- EVT VT = Op.getValueType();
- assert(VT.isScalableVector() ||
- useSVEForFixedLengthVectorVT(VT, true));
- SDLoc DL(Op);
- SDValue RBIT = DAG.getNode(ISD::BITREVERSE, DL, VT, Op.getOperand(0));
- return DAG.getNode(ISD::CTLZ, DL, VT, RBIT);
- }
- SDValue AArch64TargetLowering::LowerSETCC(SDValue Op, SelectionDAG &DAG) const {
- if (Op.getValueType().isVector())
- return LowerVSETCC(Op, DAG);
- bool IsStrict = Op->isStrictFPOpcode();
- bool IsSignaling = Op.getOpcode() == ISD::STRICT_FSETCCS;
- unsigned OpNo = IsStrict ? 1 : 0;
- SDValue Chain;
- if (IsStrict)
- Chain = Op.getOperand(0);
- SDValue LHS = Op.getOperand(OpNo + 0);
- SDValue RHS = Op.getOperand(OpNo + 1);
- ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(OpNo + 2))->get();
- SDLoc dl(Op);
-
- EVT VT = Op.getValueType();
- SDValue TVal = DAG.getConstant(1, dl, VT);
- SDValue FVal = DAG.getConstant(0, dl, VT);
-
-
- if (LHS.getValueType() == MVT::f128) {
- softenSetCCOperands(DAG, MVT::f128, LHS, RHS, CC, dl, LHS, RHS, Chain,
- IsSignaling);
-
- if (!RHS.getNode()) {
- assert(LHS.getValueType() == Op.getValueType() &&
- "Unexpected setcc expansion!");
- return IsStrict ? DAG.getMergeValues({LHS, Chain}, dl) : LHS;
- }
- }
- if (LHS.getValueType().isInteger()) {
- SDValue CCVal;
- SDValue Cmp = getAArch64Cmp(
- LHS, RHS, ISD::getSetCCInverse(CC, LHS.getValueType()), CCVal, DAG, dl);
-
-
-
- SDValue Res = DAG.getNode(AArch64ISD::CSEL, dl, VT, FVal, TVal, CCVal, Cmp);
- return IsStrict ? DAG.getMergeValues({Res, Chain}, dl) : Res;
- }
-
- assert(LHS.getValueType() == MVT::f16 || LHS.getValueType() == MVT::f32 ||
- LHS.getValueType() == MVT::f64);
-
-
- SDValue Cmp;
- if (IsStrict)
- Cmp = emitStrictFPComparison(LHS, RHS, dl, DAG, Chain, IsSignaling);
- else
- Cmp = emitComparison(LHS, RHS, CC, dl, DAG);
- AArch64CC::CondCode CC1, CC2;
- changeFPCCToAArch64CC(CC, CC1, CC2);
- SDValue Res;
- if (CC2 == AArch64CC::AL) {
- changeFPCCToAArch64CC(ISD::getSetCCInverse(CC, LHS.getValueType()), CC1,
- CC2);
- SDValue CC1Val = DAG.getConstant(CC1, dl, MVT::i32);
-
-
-
- Res = DAG.getNode(AArch64ISD::CSEL, dl, VT, FVal, TVal, CC1Val, Cmp);
- } else {
-
-
-
-
-
- SDValue CC1Val = DAG.getConstant(CC1, dl, MVT::i32);
- SDValue CS1 =
- DAG.getNode(AArch64ISD::CSEL, dl, VT, TVal, FVal, CC1Val, Cmp);
- SDValue CC2Val = DAG.getConstant(CC2, dl, MVT::i32);
- Res = DAG.getNode(AArch64ISD::CSEL, dl, VT, TVal, CS1, CC2Val, Cmp);
- }
- return IsStrict ? DAG.getMergeValues({Res, Cmp.getValue(1)}, dl) : Res;
- }
- SDValue AArch64TargetLowering::LowerSELECT_CC(ISD::CondCode CC, SDValue LHS,
- SDValue RHS, SDValue TVal,
- SDValue FVal, const SDLoc &dl,
- SelectionDAG &DAG) const {
-
-
- if (LHS.getValueType() == MVT::f128) {
- softenSetCCOperands(DAG, MVT::f128, LHS, RHS, CC, dl, LHS, RHS);
-
-
- if (!RHS.getNode()) {
- RHS = DAG.getConstant(0, dl, LHS.getValueType());
- CC = ISD::SETNE;
- }
- }
-
- if (LHS.getValueType() == MVT::f16 && !Subtarget->hasFullFP16()) {
- LHS = DAG.getNode(ISD::FP_EXTEND, dl, MVT::f32, LHS);
- RHS = DAG.getNode(ISD::FP_EXTEND, dl, MVT::f32, RHS);
- }
-
- if (LHS.getValueType().isInteger()) {
- assert((LHS.getValueType() == RHS.getValueType()) &&
- (LHS.getValueType() == MVT::i32 || LHS.getValueType() == MVT::i64));
- unsigned Opcode = AArch64ISD::CSEL;
-
-
- ConstantSDNode *CFVal = dyn_cast<ConstantSDNode>(FVal);
- ConstantSDNode *CTVal = dyn_cast<ConstantSDNode>(TVal);
- if (CTVal && CFVal && CTVal->isAllOnesValue() && CFVal->isNullValue()) {
- std::swap(TVal, FVal);
- std::swap(CTVal, CFVal);
- CC = ISD::getSetCCInverse(CC, LHS.getValueType());
- } else if (CTVal && CFVal && CTVal->isOne() && CFVal->isNullValue()) {
- std::swap(TVal, FVal);
- std::swap(CTVal, CFVal);
- CC = ISD::getSetCCInverse(CC, LHS.getValueType());
- } else if (TVal.getOpcode() == ISD::XOR) {
-
-
- if (isAllOnesConstant(TVal.getOperand(1))) {
- std::swap(TVal, FVal);
- std::swap(CTVal, CFVal);
- CC = ISD::getSetCCInverse(CC, LHS.getValueType());
- }
- } else if (TVal.getOpcode() == ISD::SUB) {
-
-
- if (isNullConstant(TVal.getOperand(0))) {
- std::swap(TVal, FVal);
- std::swap(CTVal, CFVal);
- CC = ISD::getSetCCInverse(CC, LHS.getValueType());
- }
- } else if (CTVal && CFVal) {
- const int64_t TrueVal = CTVal->getSExtValue();
- const int64_t FalseVal = CFVal->getSExtValue();
- bool Swap = false;
-
-
-
- if (TrueVal == ~FalseVal) {
- Opcode = AArch64ISD::CSINV;
- } else if (FalseVal > std::numeric_limits<int64_t>::min() &&
- TrueVal == -FalseVal) {
- Opcode = AArch64ISD::CSNEG;
- } else if (TVal.getValueType() == MVT::i32) {
-
-
-
-
-
- const uint32_t TrueVal32 = CTVal->getZExtValue();
- const uint32_t FalseVal32 = CFVal->getZExtValue();
- if ((TrueVal32 == FalseVal32 + 1) || (TrueVal32 + 1 == FalseVal32)) {
- Opcode = AArch64ISD::CSINC;
- if (TrueVal32 > FalseVal32) {
- Swap = true;
- }
- }
-
- } else if ((TrueVal == FalseVal + 1) || (TrueVal + 1 == FalseVal)) {
- Opcode = AArch64ISD::CSINC;
- if (TrueVal > FalseVal) {
- Swap = true;
- }
- }
-
- if (Swap) {
- std::swap(TVal, FVal);
- std::swap(CTVal, CFVal);
- CC = ISD::getSetCCInverse(CC, LHS.getValueType());
- }
- if (Opcode != AArch64ISD::CSEL) {
-
-
- FVal = TVal;
- }
- }
-
-
-
-
-
- ConstantSDNode *RHSVal = dyn_cast<ConstantSDNode>(RHS);
- if (Opcode == AArch64ISD::CSEL && RHSVal && !RHSVal->isOne() &&
- !RHSVal->isNullValue() && !RHSVal->isAllOnesValue()) {
- AArch64CC::CondCode AArch64CC = changeIntCCToAArch64CC(CC);
-
-
- if (CTVal && CTVal == RHSVal && AArch64CC == AArch64CC::EQ)
- TVal = LHS;
- else if (CFVal && CFVal == RHSVal && AArch64CC == AArch64CC::NE)
- FVal = LHS;
- } else if (Opcode == AArch64ISD::CSNEG && RHSVal && RHSVal->isOne()) {
- assert (CTVal && CFVal && "Expected constant operands for CSNEG.");
-
-
- AArch64CC::CondCode AArch64CC = changeIntCCToAArch64CC(CC);
- if (CTVal == RHSVal && AArch64CC == AArch64CC::EQ) {
- Opcode = AArch64ISD::CSINV;
- TVal = LHS;
- FVal = DAG.getConstant(0, dl, FVal.getValueType());
- }
- }
- SDValue CCVal;
- SDValue Cmp = getAArch64Cmp(LHS, RHS, CC, CCVal, DAG, dl);
- EVT VT = TVal.getValueType();
- return DAG.getNode(Opcode, dl, VT, TVal, FVal, CCVal, Cmp);
- }
-
- assert(LHS.getValueType() == MVT::f16 || LHS.getValueType() == MVT::f32 ||
- LHS.getValueType() == MVT::f64);
- assert(LHS.getValueType() == RHS.getValueType());
- EVT VT = TVal.getValueType();
- SDValue Cmp = emitComparison(LHS, RHS, CC, dl, DAG);
-
-
- AArch64CC::CondCode CC1, CC2;
- changeFPCCToAArch64CC(CC, CC1, CC2);
- if (DAG.getTarget().Options.UnsafeFPMath) {
-
-
- ConstantFPSDNode *RHSVal = dyn_cast<ConstantFPSDNode>(RHS);
- if (RHSVal && RHSVal->isZero()) {
- ConstantFPSDNode *CFVal = dyn_cast<ConstantFPSDNode>(FVal);
- ConstantFPSDNode *CTVal = dyn_cast<ConstantFPSDNode>(TVal);
- if ((CC == ISD::SETEQ || CC == ISD::SETOEQ || CC == ISD::SETUEQ) &&
- CTVal && CTVal->isZero() && TVal.getValueType() == LHS.getValueType())
- TVal = LHS;
- else if ((CC == ISD::SETNE || CC == ISD::SETONE || CC == ISD::SETUNE) &&
- CFVal && CFVal->isZero() &&
- FVal.getValueType() == LHS.getValueType())
- FVal = LHS;
- }
- }
-
- SDValue CC1Val = DAG.getConstant(CC1, dl, MVT::i32);
- SDValue CS1 = DAG.getNode(AArch64ISD::CSEL, dl, VT, TVal, FVal, CC1Val, Cmp);
-
-
- if (CC2 != AArch64CC::AL) {
- SDValue CC2Val = DAG.getConstant(CC2, dl, MVT::i32);
- return DAG.getNode(AArch64ISD::CSEL, dl, VT, TVal, CS1, CC2Val, Cmp);
- }
-
- return CS1;
- }
- SDValue AArch64TargetLowering::LowerSELECT_CC(SDValue Op,
- SelectionDAG &DAG) const {
- ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(4))->get();
- SDValue LHS = Op.getOperand(0);
- SDValue RHS = Op.getOperand(1);
- SDValue TVal = Op.getOperand(2);
- SDValue FVal = Op.getOperand(3);
- SDLoc DL(Op);
- return LowerSELECT_CC(CC, LHS, RHS, TVal, FVal, DL, DAG);
- }
- SDValue AArch64TargetLowering::LowerSELECT(SDValue Op,
- SelectionDAG &DAG) const {
- SDValue CCVal = Op->getOperand(0);
- SDValue TVal = Op->getOperand(1);
- SDValue FVal = Op->getOperand(2);
- SDLoc DL(Op);
- EVT Ty = Op.getValueType();
- if (Ty.isScalableVector()) {
- SDValue TruncCC = DAG.getNode(ISD::TRUNCATE, DL, MVT::i1, CCVal);
- MVT PredVT = MVT::getVectorVT(MVT::i1, Ty.getVectorElementCount());
- SDValue SplatPred = DAG.getNode(ISD::SPLAT_VECTOR, DL, PredVT, TruncCC);
- return DAG.getNode(ISD::VSELECT, DL, Ty, SplatPred, TVal, FVal);
- }
-
-
- if (ISD::isOverflowIntrOpRes(CCVal)) {
-
- if (!DAG.getTargetLoweringInfo().isTypeLegal(CCVal->getValueType(0)))
- return SDValue();
- AArch64CC::CondCode OFCC;
- SDValue Value, Overflow;
- std::tie(Value, Overflow) = getAArch64XALUOOp(OFCC, CCVal.getValue(0), DAG);
- SDValue CCVal = DAG.getConstant(OFCC, DL, MVT::i32);
- return DAG.getNode(AArch64ISD::CSEL, DL, Op.getValueType(), TVal, FVal,
- CCVal, Overflow);
- }
-
- ISD::CondCode CC;
- SDValue LHS, RHS;
- if (CCVal.getOpcode() == ISD::SETCC) {
- LHS = CCVal.getOperand(0);
- RHS = CCVal.getOperand(1);
- CC = cast<CondCodeSDNode>(CCVal->getOperand(2))->get();
- } else {
- LHS = CCVal;
- RHS = DAG.getConstant(0, DL, CCVal.getValueType());
- CC = ISD::SETNE;
- }
- return LowerSELECT_CC(CC, LHS, RHS, TVal, FVal, DL, DAG);
- }
- SDValue AArch64TargetLowering::LowerJumpTable(SDValue Op,
- SelectionDAG &DAG) const {
-
-
- JumpTableSDNode *JT = cast<JumpTableSDNode>(Op);
- if (getTargetMachine().getCodeModel() == CodeModel::Large &&
- !Subtarget->isTargetMachO()) {
- return getAddrLarge(JT, DAG);
- } else if (getTargetMachine().getCodeModel() == CodeModel::Tiny) {
- return getAddrTiny(JT, DAG);
- }
- return getAddr(JT, DAG);
- }
- SDValue AArch64TargetLowering::LowerBR_JT(SDValue Op,
- SelectionDAG &DAG) const {
-
-
- SDLoc DL(Op);
- SDValue JT = Op.getOperand(1);
- SDValue Entry = Op.getOperand(2);
- int JTI = cast<JumpTableSDNode>(JT.getNode())->getIndex();
- auto *AFI = DAG.getMachineFunction().getInfo<AArch64FunctionInfo>();
- AFI->setJumpTableEntryInfo(JTI, 4, nullptr);
- SDNode *Dest =
- DAG.getMachineNode(AArch64::JumpTableDest32, DL, MVT::i64, MVT::i64, JT,
- Entry, DAG.getTargetJumpTable(JTI, MVT::i32));
- return DAG.getNode(ISD::BRIND, DL, MVT::Other, Op.getOperand(0),
- SDValue(Dest, 0));
- }
- SDValue AArch64TargetLowering::LowerConstantPool(SDValue Op,
- SelectionDAG &DAG) const {
- ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(Op);
- if (getTargetMachine().getCodeModel() == CodeModel::Large) {
-
- if (Subtarget->isTargetMachO()) {
- return getGOT(CP, DAG);
- }
- return getAddrLarge(CP, DAG);
- } else if (getTargetMachine().getCodeModel() == CodeModel::Tiny) {
- return getAddrTiny(CP, DAG);
- } else {
- return getAddr(CP, DAG);
- }
- }
- SDValue AArch64TargetLowering::LowerBlockAddress(SDValue Op,
- SelectionDAG &DAG) const {
- BlockAddressSDNode *BA = cast<BlockAddressSDNode>(Op);
- if (getTargetMachine().getCodeModel() == CodeModel::Large &&
- !Subtarget->isTargetMachO()) {
- return getAddrLarge(BA, DAG);
- } else if (getTargetMachine().getCodeModel() == CodeModel::Tiny) {
- return getAddrTiny(BA, DAG);
- }
- return getAddr(BA, DAG);
- }
- SDValue AArch64TargetLowering::LowerDarwin_VASTART(SDValue Op,
- SelectionDAG &DAG) const {
- AArch64FunctionInfo *FuncInfo =
- DAG.getMachineFunction().getInfo<AArch64FunctionInfo>();
- SDLoc DL(Op);
- SDValue FR = DAG.getFrameIndex(FuncInfo->getVarArgsStackIndex(),
- getPointerTy(DAG.getDataLayout()));
- FR = DAG.getZExtOrTrunc(FR, DL, getPointerMemTy(DAG.getDataLayout()));
- const Value *SV = cast<SrcValueSDNode>(Op.getOperand(2))->getValue();
- return DAG.getStore(Op.getOperand(0), DL, FR, Op.getOperand(1),
- MachinePointerInfo(SV));
- }
- SDValue AArch64TargetLowering::LowerWin64_VASTART(SDValue Op,
- SelectionDAG &DAG) const {
- AArch64FunctionInfo *FuncInfo =
- DAG.getMachineFunction().getInfo<AArch64FunctionInfo>();
- SDLoc DL(Op);
- SDValue FR = DAG.getFrameIndex(FuncInfo->getVarArgsGPRSize() > 0
- ? FuncInfo->getVarArgsGPRIndex()
- : FuncInfo->getVarArgsStackIndex(),
- getPointerTy(DAG.getDataLayout()));
- const Value *SV = cast<SrcValueSDNode>(Op.getOperand(2))->getValue();
- return DAG.getStore(Op.getOperand(0), DL, FR, Op.getOperand(1),
- MachinePointerInfo(SV));
- }
- SDValue AArch64TargetLowering::LowerAAPCS_VASTART(SDValue Op,
- SelectionDAG &DAG) const {
-
-
- MachineFunction &MF = DAG.getMachineFunction();
- AArch64FunctionInfo *FuncInfo = MF.getInfo<AArch64FunctionInfo>();
- unsigned PtrSize = Subtarget->isTargetILP32() ? 4 : 8;
- auto PtrMemVT = getPointerMemTy(DAG.getDataLayout());
- auto PtrVT = getPointerTy(DAG.getDataLayout());
- SDLoc DL(Op);
- SDValue Chain = Op.getOperand(0);
- SDValue VAList = Op.getOperand(1);
- const Value *SV = cast<SrcValueSDNode>(Op.getOperand(2))->getValue();
- SmallVector<SDValue, 4> MemOps;
-
- unsigned Offset = 0;
- SDValue Stack = DAG.getFrameIndex(FuncInfo->getVarArgsStackIndex(), PtrVT);
- Stack = DAG.getZExtOrTrunc(Stack, DL, PtrMemVT);
- MemOps.push_back(DAG.getStore(Chain, DL, Stack, VAList,
- MachinePointerInfo(SV), Align(PtrSize)));
-
- Offset += PtrSize;
- int GPRSize = FuncInfo->getVarArgsGPRSize();
- if (GPRSize > 0) {
- SDValue GRTop, GRTopAddr;
- GRTopAddr = DAG.getNode(ISD::ADD, DL, PtrVT, VAList,
- DAG.getConstant(Offset, DL, PtrVT));
- GRTop = DAG.getFrameIndex(FuncInfo->getVarArgsGPRIndex(), PtrVT);
- GRTop = DAG.getNode(ISD::ADD, DL, PtrVT, GRTop,
- DAG.getConstant(GPRSize, DL, PtrVT));
- GRTop = DAG.getZExtOrTrunc(GRTop, DL, PtrMemVT);
- MemOps.push_back(DAG.getStore(Chain, DL, GRTop, GRTopAddr,
- MachinePointerInfo(SV, Offset),
- Align(PtrSize)));
- }
-
- Offset += PtrSize;
- int FPRSize = FuncInfo->getVarArgsFPRSize();
- if (FPRSize > 0) {
- SDValue VRTop, VRTopAddr;
- VRTopAddr = DAG.getNode(ISD::ADD, DL, PtrVT, VAList,
- DAG.getConstant(Offset, DL, PtrVT));
- VRTop = DAG.getFrameIndex(FuncInfo->getVarArgsFPRIndex(), PtrVT);
- VRTop = DAG.getNode(ISD::ADD, DL, PtrVT, VRTop,
- DAG.getConstant(FPRSize, DL, PtrVT));
- VRTop = DAG.getZExtOrTrunc(VRTop, DL, PtrMemVT);
- MemOps.push_back(DAG.getStore(Chain, DL, VRTop, VRTopAddr,
- MachinePointerInfo(SV, Offset),
- Align(PtrSize)));
- }
-
- Offset += PtrSize;
- SDValue GROffsAddr = DAG.getNode(ISD::ADD, DL, PtrVT, VAList,
- DAG.getConstant(Offset, DL, PtrVT));
- MemOps.push_back(
- DAG.getStore(Chain, DL, DAG.getConstant(-GPRSize, DL, MVT::i32),
- GROffsAddr, MachinePointerInfo(SV, Offset), Align(4)));
-
- Offset += 4;
- SDValue VROffsAddr = DAG.getNode(ISD::ADD, DL, PtrVT, VAList,
- DAG.getConstant(Offset, DL, PtrVT));
- MemOps.push_back(
- DAG.getStore(Chain, DL, DAG.getConstant(-FPRSize, DL, MVT::i32),
- VROffsAddr, MachinePointerInfo(SV, Offset), Align(4)));
- return DAG.getNode(ISD::TokenFactor, DL, MVT::Other, MemOps);
- }
- SDValue AArch64TargetLowering::LowerVASTART(SDValue Op,
- SelectionDAG &DAG) const {
- MachineFunction &MF = DAG.getMachineFunction();
- if (Subtarget->isCallingConvWin64(MF.getFunction().getCallingConv()))
- return LowerWin64_VASTART(Op, DAG);
- else if (Subtarget->isTargetDarwin())
- return LowerDarwin_VASTART(Op, DAG);
- else
- return LowerAAPCS_VASTART(Op, DAG);
- }
- SDValue AArch64TargetLowering::LowerVACOPY(SDValue Op,
- SelectionDAG &DAG) const {
-
-
- SDLoc DL(Op);
- unsigned PtrSize = Subtarget->isTargetILP32() ? 4 : 8;
- unsigned VaListSize =
- (Subtarget->isTargetDarwin() || Subtarget->isTargetWindows())
- ? PtrSize
- : Subtarget->isTargetILP32() ? 20 : 32;
- const Value *DestSV = cast<SrcValueSDNode>(Op.getOperand(3))->getValue();
- const Value *SrcSV = cast<SrcValueSDNode>(Op.getOperand(4))->getValue();
- return DAG.getMemcpy(Op.getOperand(0), DL, Op.getOperand(1), Op.getOperand(2),
- DAG.getConstant(VaListSize, DL, MVT::i32),
- Align(PtrSize), false, false, false,
- MachinePointerInfo(DestSV), MachinePointerInfo(SrcSV));
- }
- SDValue AArch64TargetLowering::LowerVAARG(SDValue Op, SelectionDAG &DAG) const {
- assert(Subtarget->isTargetDarwin() &&
- "automatic va_arg instruction only works on Darwin");
- const Value *V = cast<SrcValueSDNode>(Op.getOperand(2))->getValue();
- EVT VT = Op.getValueType();
- SDLoc DL(Op);
- SDValue Chain = Op.getOperand(0);
- SDValue Addr = Op.getOperand(1);
- MaybeAlign Align(Op.getConstantOperandVal(3));
- unsigned MinSlotSize = Subtarget->isTargetILP32() ? 4 : 8;
- auto PtrVT = getPointerTy(DAG.getDataLayout());
- auto PtrMemVT = getPointerMemTy(DAG.getDataLayout());
- SDValue VAList =
- DAG.getLoad(PtrMemVT, DL, Chain, Addr, MachinePointerInfo(V));
- Chain = VAList.getValue(1);
- VAList = DAG.getZExtOrTrunc(VAList, DL, PtrVT);
- if (VT.isScalableVector())
- report_fatal_error("Passing SVE types to variadic functions is "
- "currently not supported");
- if (Align && *Align > MinSlotSize) {
- VAList = DAG.getNode(ISD::ADD, DL, PtrVT, VAList,
- DAG.getConstant(Align->value() - 1, DL, PtrVT));
- VAList = DAG.getNode(ISD::AND, DL, PtrVT, VAList,
- DAG.getConstant(-(int64_t)Align->value(), DL, PtrVT));
- }
- Type *ArgTy = VT.getTypeForEVT(*DAG.getContext());
- unsigned ArgSize = DAG.getDataLayout().getTypeAllocSize(ArgTy);
-
-
-
-
- if (VT.isInteger() && !VT.isVector())
- ArgSize = std::max(ArgSize, MinSlotSize);
- bool NeedFPTrunc = false;
- if (VT.isFloatingPoint() && !VT.isVector() && VT != MVT::f64) {
- ArgSize = 8;
- NeedFPTrunc = true;
- }
-
- SDValue VANext = DAG.getNode(ISD::ADD, DL, PtrVT, VAList,
- DAG.getConstant(ArgSize, DL, PtrVT));
- VANext = DAG.getZExtOrTrunc(VANext, DL, PtrMemVT);
-
- SDValue APStore =
- DAG.getStore(Chain, DL, VANext, Addr, MachinePointerInfo(V));
-
- if (NeedFPTrunc) {
-
- SDValue WideFP =
- DAG.getLoad(MVT::f64, DL, APStore, VAList, MachinePointerInfo());
-
- SDValue NarrowFP = DAG.getNode(ISD::FP_ROUND, DL, VT, WideFP.getValue(0),
- DAG.getIntPtrConstant(1, DL));
- SDValue Ops[] = { NarrowFP, WideFP.getValue(1) };
-
- return DAG.getMergeValues(Ops, DL);
- }
- return DAG.getLoad(VT, DL, APStore, VAList, MachinePointerInfo());
- }
- SDValue AArch64TargetLowering::LowerFRAMEADDR(SDValue Op,
- SelectionDAG &DAG) const {
- MachineFrameInfo &MFI = DAG.getMachineFunction().getFrameInfo();
- MFI.setFrameAddressIsTaken(true);
- EVT VT = Op.getValueType();
- SDLoc DL(Op);
- unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue();
- SDValue FrameAddr =
- DAG.getCopyFromReg(DAG.getEntryNode(), DL, AArch64::FP, MVT::i64);
- while (Depth--)
- FrameAddr = DAG.getLoad(VT, DL, DAG.getEntryNode(), FrameAddr,
- MachinePointerInfo());
- if (Subtarget->isTargetILP32())
- FrameAddr = DAG.getNode(ISD::AssertZext, DL, MVT::i64, FrameAddr,
- DAG.getValueType(VT));
- return FrameAddr;
- }
- SDValue AArch64TargetLowering::LowerSPONENTRY(SDValue Op,
- SelectionDAG &DAG) const {
- MachineFrameInfo &MFI = DAG.getMachineFunction().getFrameInfo();
- EVT VT = getPointerTy(DAG.getDataLayout());
- SDLoc DL(Op);
- int FI = MFI.CreateFixedObject(4, 0, false);
- return DAG.getFrameIndex(FI, VT);
- }
- #define GET_REGISTER_MATCHER
- #include "AArch64GenAsmMatcher.inc"
- Register AArch64TargetLowering::
- getRegisterByName(const char* RegName, LLT VT, const MachineFunction &MF) const {
- Register Reg = MatchRegisterName(RegName);
- if (AArch64::X1 <= Reg && Reg <= AArch64::X28) {
- const MCRegisterInfo *MRI = Subtarget->getRegisterInfo();
- unsigned DwarfRegNum = MRI->getDwarfRegNum(Reg, false);
- if (!Subtarget->isXRegisterReserved(DwarfRegNum))
- Reg = 0;
- }
- if (Reg)
- return Reg;
- report_fatal_error(Twine("Invalid register name \""
- + StringRef(RegName) + "\"."));
- }
- SDValue AArch64TargetLowering::LowerADDROFRETURNADDR(SDValue Op,
- SelectionDAG &DAG) const {
- DAG.getMachineFunction().getFrameInfo().setFrameAddressIsTaken(true);
- EVT VT = Op.getValueType();
- SDLoc DL(Op);
- SDValue FrameAddr =
- DAG.getCopyFromReg(DAG.getEntryNode(), DL, AArch64::FP, VT);
- SDValue Offset = DAG.getConstant(8, DL, getPointerTy(DAG.getDataLayout()));
- return DAG.getNode(ISD::ADD, DL, VT, FrameAddr, Offset);
- }
- SDValue AArch64TargetLowering::LowerRETURNADDR(SDValue Op,
- SelectionDAG &DAG) const {
- MachineFunction &MF = DAG.getMachineFunction();
- MachineFrameInfo &MFI = MF.getFrameInfo();
- MFI.setReturnAddressIsTaken(true);
- EVT VT = Op.getValueType();
- SDLoc DL(Op);
- unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue();
- SDValue ReturnAddress;
- if (Depth) {
- SDValue FrameAddr = LowerFRAMEADDR(Op, DAG);
- SDValue Offset = DAG.getConstant(8, DL, getPointerTy(DAG.getDataLayout()));
- ReturnAddress = DAG.getLoad(
- VT, DL, DAG.getEntryNode(),
- DAG.getNode(ISD::ADD, DL, VT, FrameAddr, Offset), MachinePointerInfo());
- } else {
-
-
- unsigned Reg = MF.addLiveIn(AArch64::LR, &AArch64::GPR64RegClass);
- ReturnAddress = DAG.getCopyFromReg(DAG.getEntryNode(), DL, Reg, VT);
- }
-
-
-
-
- SDNode *St;
- if (Subtarget->hasPAuth()) {
- St = DAG.getMachineNode(AArch64::XPACI, DL, VT, ReturnAddress);
- } else {
-
- SDValue Chain =
- DAG.getCopyToReg(DAG.getEntryNode(), DL, AArch64::LR, ReturnAddress);
- St = DAG.getMachineNode(AArch64::XPACLRI, DL, VT, Chain);
- }
- return SDValue(St, 0);
- }
- SDValue AArch64TargetLowering::LowerShiftRightParts(SDValue Op,
- SelectionDAG &DAG) const {
- assert(Op.getNumOperands() == 3 && "Not a double-shift!");
- EVT VT = Op.getValueType();
- unsigned VTBits = VT.getSizeInBits();
- SDLoc dl(Op);
- SDValue ShOpLo = Op.getOperand(0);
- SDValue ShOpHi = Op.getOperand(1);
- SDValue ShAmt = Op.getOperand(2);
- unsigned Opc = (Op.getOpcode() == ISD::SRA_PARTS) ? ISD::SRA : ISD::SRL;
- assert(Op.getOpcode() == ISD::SRA_PARTS || Op.getOpcode() == ISD::SRL_PARTS);
- SDValue RevShAmt = DAG.getNode(ISD::SUB, dl, MVT::i64,
- DAG.getConstant(VTBits, dl, MVT::i64), ShAmt);
- SDValue HiBitsForLo = DAG.getNode(ISD::SHL, dl, VT, ShOpHi, RevShAmt);
-
-
- SDValue Cmp = emitComparison(ShAmt, DAG.getConstant(0, dl, MVT::i64),
- ISD::SETEQ, dl, DAG);
- SDValue CCVal = DAG.getConstant(AArch64CC::EQ, dl, MVT::i32);
- HiBitsForLo =
- DAG.getNode(AArch64ISD::CSEL, dl, VT, DAG.getConstant(0, dl, MVT::i64),
- HiBitsForLo, CCVal, Cmp);
- SDValue ExtraShAmt = DAG.getNode(ISD::SUB, dl, MVT::i64, ShAmt,
- DAG.getConstant(VTBits, dl, MVT::i64));
- SDValue LoBitsForLo = DAG.getNode(ISD::SRL, dl, VT, ShOpLo, ShAmt);
- SDValue LoForNormalShift =
- DAG.getNode(ISD::OR, dl, VT, LoBitsForLo, HiBitsForLo);
- Cmp = emitComparison(ExtraShAmt, DAG.getConstant(0, dl, MVT::i64), ISD::SETGE,
- dl, DAG);
- CCVal = DAG.getConstant(AArch64CC::GE, dl, MVT::i32);
- SDValue LoForBigShift = DAG.getNode(Opc, dl, VT, ShOpHi, ExtraShAmt);
- SDValue Lo = DAG.getNode(AArch64ISD::CSEL, dl, VT, LoForBigShift,
- LoForNormalShift, CCVal, Cmp);
-
-
- SDValue HiForNormalShift = DAG.getNode(Opc, dl, VT, ShOpHi, ShAmt);
- SDValue HiForBigShift =
- Opc == ISD::SRA
- ? DAG.getNode(Opc, dl, VT, ShOpHi,
- DAG.getConstant(VTBits - 1, dl, MVT::i64))
- : DAG.getConstant(0, dl, VT);
- SDValue Hi = DAG.getNode(AArch64ISD::CSEL, dl, VT, HiForBigShift,
- HiForNormalShift, CCVal, Cmp);
- SDValue Ops[2] = { Lo, Hi };
- return DAG.getMergeValues(Ops, dl);
- }
- SDValue AArch64TargetLowering::LowerShiftLeftParts(SDValue Op,
- SelectionDAG &DAG) const {
- assert(Op.getNumOperands() == 3 && "Not a double-shift!");
- EVT VT = Op.getValueType();
- unsigned VTBits = VT.getSizeInBits();
- SDLoc dl(Op);
- SDValue ShOpLo = Op.getOperand(0);
- SDValue ShOpHi = Op.getOperand(1);
- SDValue ShAmt = Op.getOperand(2);
- assert(Op.getOpcode() == ISD::SHL_PARTS);
- SDValue RevShAmt = DAG.getNode(ISD::SUB, dl, MVT::i64,
- DAG.getConstant(VTBits, dl, MVT::i64), ShAmt);
- SDValue LoBitsForHi = DAG.getNode(ISD::SRL, dl, VT, ShOpLo, RevShAmt);
-
-
- SDValue Cmp = emitComparison(ShAmt, DAG.getConstant(0, dl, MVT::i64),
- ISD::SETEQ, dl, DAG);
- SDValue CCVal = DAG.getConstant(AArch64CC::EQ, dl, MVT::i32);
- LoBitsForHi =
- DAG.getNode(AArch64ISD::CSEL, dl, VT, DAG.getConstant(0, dl, MVT::i64),
- LoBitsForHi, CCVal, Cmp);
- SDValue ExtraShAmt = DAG.getNode(ISD::SUB, dl, MVT::i64, ShAmt,
- DAG.getConstant(VTBits, dl, MVT::i64));
- SDValue HiBitsForHi = DAG.getNode(ISD::SHL, dl, VT, ShOpHi, ShAmt);
- SDValue HiForNormalShift =
- DAG.getNode(ISD::OR, dl, VT, LoBitsForHi, HiBitsForHi);
- SDValue HiForBigShift = DAG.getNode(ISD::SHL, dl, VT, ShOpLo, ExtraShAmt);
- Cmp = emitComparison(ExtraShAmt, DAG.getConstant(0, dl, MVT::i64), ISD::SETGE,
- dl, DAG);
- CCVal = DAG.getConstant(AArch64CC::GE, dl, MVT::i32);
- SDValue Hi = DAG.getNode(AArch64ISD::CSEL, dl, VT, HiForBigShift,
- HiForNormalShift, CCVal, Cmp);
-
-
- SDValue LoForBigShift = DAG.getConstant(0, dl, VT);
- SDValue LoForNormalShift = DAG.getNode(ISD::SHL, dl, VT, ShOpLo, ShAmt);
- SDValue Lo = DAG.getNode(AArch64ISD::CSEL, dl, VT, LoForBigShift,
- LoForNormalShift, CCVal, Cmp);
- SDValue Ops[2] = { Lo, Hi };
- return DAG.getMergeValues(Ops, dl);
- }
- bool AArch64TargetLowering::isOffsetFoldingLegal(
- const GlobalAddressSDNode *GA) const {
-
-
- return false;
- }
- bool AArch64TargetLowering::isFPImmLegal(const APFloat &Imm, EVT VT,
- bool OptForSize) const {
- bool IsLegal = false;
-
-
-
- const APInt ImmInt = Imm.bitcastToAPInt();
- if (VT == MVT::f64)
- IsLegal = AArch64_AM::getFP64Imm(ImmInt) != -1 || Imm.isPosZero();
- else if (VT == MVT::f32)
- IsLegal = AArch64_AM::getFP32Imm(ImmInt) != -1 || Imm.isPosZero();
- else if (VT == MVT::f16 && Subtarget->hasFullFP16())
- IsLegal = AArch64_AM::getFP16Imm(ImmInt) != -1 || Imm.isPosZero();
-
-
-
-
-
- if (!IsLegal && (VT == MVT::f64 || VT == MVT::f32)) {
-
-
-
-
-
- SmallVector<AArch64_IMM::ImmInsnModel, 4> Insn;
- AArch64_IMM::expandMOVImm(ImmInt.getZExtValue(), VT.getSizeInBits(),
- Insn);
- unsigned Limit = (OptForSize ? 1 : (Subtarget->hasFuseLiterals() ? 5 : 2));
- IsLegal = Insn.size() <= Limit;
- }
- LLVM_DEBUG(dbgs() << (IsLegal ? "Legal " : "Illegal ") << VT.getEVTString()
- << " imm value: "; Imm.dump(););
- return IsLegal;
- }
- static SDValue getEstimate(const AArch64Subtarget *ST, unsigned Opcode,
- SDValue Operand, SelectionDAG &DAG,
- int &ExtraSteps) {
- EVT VT = Operand.getValueType();
- if (ST->hasNEON() &&
- (VT == MVT::f64 || VT == MVT::v1f64 || VT == MVT::v2f64 ||
- VT == MVT::f32 || VT == MVT::v1f32 ||
- VT == MVT::v2f32 || VT == MVT::v4f32)) {
- if (ExtraSteps == TargetLoweringBase::ReciprocalEstimate::Unspecified)
-
-
-
-
-
- ExtraSteps = VT.getScalarType() == MVT::f64 ? 3 : 2;
- return DAG.getNode(Opcode, SDLoc(Operand), VT, Operand);
- }
- return SDValue();
- }
- SDValue
- AArch64TargetLowering::getSqrtInputTest(SDValue Op, SelectionDAG &DAG,
- const DenormalMode &Mode) const {
- SDLoc DL(Op);
- EVT VT = Op.getValueType();
- EVT CCVT = getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(), VT);
- SDValue FPZero = DAG.getConstantFP(0.0, DL, VT);
- return DAG.getSetCC(DL, CCVT, Op, FPZero, ISD::SETEQ);
- }
- SDValue
- AArch64TargetLowering::getSqrtResultForDenormInput(SDValue Op,
- SelectionDAG &DAG) const {
- return Op;
- }
- SDValue AArch64TargetLowering::getSqrtEstimate(SDValue Operand,
- SelectionDAG &DAG, int Enabled,
- int &ExtraSteps,
- bool &UseOneConst,
- bool Reciprocal) const {
- if (Enabled == ReciprocalEstimate::Enabled ||
- (Enabled == ReciprocalEstimate::Unspecified && Subtarget->useRSqrt()))
- if (SDValue Estimate = getEstimate(Subtarget, AArch64ISD::FRSQRTE, Operand,
- DAG, ExtraSteps)) {
- SDLoc DL(Operand);
- EVT VT = Operand.getValueType();
- SDNodeFlags Flags;
- Flags.setAllowReassociation(true);
-
-
- for (int i = ExtraSteps; i > 0; --i) {
- SDValue Step = DAG.getNode(ISD::FMUL, DL, VT, Estimate, Estimate,
- Flags);
- Step = DAG.getNode(AArch64ISD::FRSQRTS, DL, VT, Operand, Step, Flags);
- Estimate = DAG.getNode(ISD::FMUL, DL, VT, Estimate, Step, Flags);
- }
- if (!Reciprocal)
- Estimate = DAG.getNode(ISD::FMUL, DL, VT, Operand, Estimate, Flags);
- ExtraSteps = 0;
- return Estimate;
- }
- return SDValue();
- }
- SDValue AArch64TargetLowering::getRecipEstimate(SDValue Operand,
- SelectionDAG &DAG, int Enabled,
- int &ExtraSteps) const {
- if (Enabled == ReciprocalEstimate::Enabled)
- if (SDValue Estimate = getEstimate(Subtarget, AArch64ISD::FRECPE, Operand,
- DAG, ExtraSteps)) {
- SDLoc DL(Operand);
- EVT VT = Operand.getValueType();
- SDNodeFlags Flags;
- Flags.setAllowReassociation(true);
-
-
- for (int i = ExtraSteps; i > 0; --i) {
- SDValue Step = DAG.getNode(AArch64ISD::FRECPS, DL, VT, Operand,
- Estimate, Flags);
- Estimate = DAG.getNode(ISD::FMUL, DL, VT, Estimate, Step, Flags);
- }
- ExtraSteps = 0;
- return Estimate;
- }
- return SDValue();
- }
- const char *AArch64TargetLowering::LowerXConstraint(EVT ConstraintVT) const {
-
-
-
-
-
-
-
- if (!Subtarget->hasFPARMv8())
- return "r";
- if (ConstraintVT.isFloatingPoint())
- return "w";
- if (ConstraintVT.isVector() &&
- (ConstraintVT.getSizeInBits() == 64 ||
- ConstraintVT.getSizeInBits() == 128))
- return "w";
- return "r";
- }
- enum PredicateConstraint {
- Upl,
- Upa,
- Invalid
- };
- static PredicateConstraint parsePredicateConstraint(StringRef Constraint) {
- PredicateConstraint P = PredicateConstraint::Invalid;
- if (Constraint == "Upa")
- P = PredicateConstraint::Upa;
- if (Constraint == "Upl")
- P = PredicateConstraint::Upl;
- return P;
- }
- AArch64TargetLowering::ConstraintType
- AArch64TargetLowering::getConstraintType(StringRef Constraint) const {
- if (Constraint.size() == 1) {
- switch (Constraint[0]) {
- default:
- break;
- case 'x':
- case 'w':
- case 'y':
- return C_RegisterClass;
-
-
- case 'Q':
- return C_Memory;
- case 'I':
- case 'J':
- case 'K':
- case 'L':
- case 'M':
- case 'N':
- case 'Y':
- case 'Z':
- return C_Immediate;
- case 'z':
- case 'S':
- return C_Other;
- }
- } else if (parsePredicateConstraint(Constraint) !=
- PredicateConstraint::Invalid)
- return C_RegisterClass;
- return TargetLowering::getConstraintType(Constraint);
- }
- TargetLowering::ConstraintWeight
- AArch64TargetLowering::getSingleConstraintMatchWeight(
- AsmOperandInfo &info, const char *constraint) const {
- ConstraintWeight weight = CW_Invalid;
- Value *CallOperandVal = info.CallOperandVal;
-
-
- if (!CallOperandVal)
- return CW_Default;
- Type *type = CallOperandVal->getType();
-
- switch (*constraint) {
- default:
- weight = TargetLowering::getSingleConstraintMatchWeight(info, constraint);
- break;
- case 'x':
- case 'w':
- case 'y':
- if (type->isFloatingPointTy() || type->isVectorTy())
- weight = CW_Register;
- break;
- case 'z':
- weight = CW_Constant;
- break;
- case 'U':
- if (parsePredicateConstraint(constraint) != PredicateConstraint::Invalid)
- weight = CW_Register;
- break;
- }
- return weight;
- }
- std::pair<unsigned, const TargetRegisterClass *>
- AArch64TargetLowering::getRegForInlineAsmConstraint(
- const TargetRegisterInfo *TRI, StringRef Constraint, MVT VT) const {
- if (Constraint.size() == 1) {
- switch (Constraint[0]) {
- case 'r':
- if (VT.isScalableVector())
- return std::make_pair(0U, nullptr);
- if (VT.getFixedSizeInBits() == 64)
- return std::make_pair(0U, &AArch64::GPR64commonRegClass);
- return std::make_pair(0U, &AArch64::GPR32commonRegClass);
- case 'w': {
- if (!Subtarget->hasFPARMv8())
- break;
- if (VT.isScalableVector()) {
- if (VT.getVectorElementType() != MVT::i1)
- return std::make_pair(0U, &AArch64::ZPRRegClass);
- return std::make_pair(0U, nullptr);
- }
- uint64_t VTSize = VT.getFixedSizeInBits();
- if (VTSize == 16)
- return std::make_pair(0U, &AArch64::FPR16RegClass);
- if (VTSize == 32)
- return std::make_pair(0U, &AArch64::FPR32RegClass);
- if (VTSize == 64)
- return std::make_pair(0U, &AArch64::FPR64RegClass);
- if (VTSize == 128)
- return std::make_pair(0U, &AArch64::FPR128RegClass);
- break;
- }
-
-
- case 'x':
- if (!Subtarget->hasFPARMv8())
- break;
- if (VT.isScalableVector())
- return std::make_pair(0U, &AArch64::ZPR_4bRegClass);
- if (VT.getSizeInBits() == 128)
- return std::make_pair(0U, &AArch64::FPR128_loRegClass);
- break;
- case 'y':
- if (!Subtarget->hasFPARMv8())
- break;
- if (VT.isScalableVector())
- return std::make_pair(0U, &AArch64::ZPR_3bRegClass);
- break;
- }
- } else {
- PredicateConstraint PC = parsePredicateConstraint(Constraint);
- if (PC != PredicateConstraint::Invalid) {
- if (!VT.isScalableVector() || VT.getVectorElementType() != MVT::i1)
- return std::make_pair(0U, nullptr);
- bool restricted = (PC == PredicateConstraint::Upl);
- return restricted ? std::make_pair(0U, &AArch64::PPR_3bRegClass)
- : std::make_pair(0U, &AArch64::PPRRegClass);
- }
- }
- if (StringRef("{cc}").equals_lower(Constraint))
- return std::make_pair(unsigned(AArch64::NZCV), &AArch64::CCRRegClass);
-
-
- std::pair<unsigned, const TargetRegisterClass *> Res;
- Res = TargetLowering::getRegForInlineAsmConstraint(TRI, Constraint, VT);
-
- if (!Res.second) {
- unsigned Size = Constraint.size();
- if ((Size == 4 || Size == 5) && Constraint[0] == '{' &&
- tolower(Constraint[1]) == 'v' && Constraint[Size - 1] == '}') {
- int RegNo;
- bool Failed = Constraint.slice(2, Size - 1).getAsInteger(10, RegNo);
- if (!Failed && RegNo >= 0 && RegNo <= 31) {
-
-
-
- if (VT != MVT::Other && VT.getSizeInBits() == 64) {
- Res.first = AArch64::FPR64RegClass.getRegister(RegNo);
- Res.second = &AArch64::FPR64RegClass;
- } else {
- Res.first = AArch64::FPR128RegClass.getRegister(RegNo);
- Res.second = &AArch64::FPR128RegClass;
- }
- }
- }
- }
- if (Res.second && !Subtarget->hasFPARMv8() &&
- !AArch64::GPR32allRegClass.hasSubClassEq(Res.second) &&
- !AArch64::GPR64allRegClass.hasSubClassEq(Res.second))
- return std::make_pair(0U, nullptr);
- return Res;
- }
- void AArch64TargetLowering::LowerAsmOperandForConstraint(
- SDValue Op, std::string &Constraint, std::vector<SDValue> &Ops,
- SelectionDAG &DAG) const {
- SDValue Result;
-
- if (Constraint.length() != 1)
- return;
- char ConstraintLetter = Constraint[0];
- switch (ConstraintLetter) {
- default:
- break;
-
-
- case 'z': {
-
- if (!isNullConstant(Op))
- return;
- if (Op.getValueType() == MVT::i64)
- Result = DAG.getRegister(AArch64::XZR, MVT::i64);
- else
- Result = DAG.getRegister(AArch64::WZR, MVT::i32);
- break;
- }
- case 'S': {
-
- if (const GlobalAddressSDNode *GA = dyn_cast<GlobalAddressSDNode>(Op)) {
- Result = DAG.getTargetGlobalAddress(GA->getGlobal(), SDLoc(Op),
- GA->getValueType(0));
- } else if (const BlockAddressSDNode *BA =
- dyn_cast<BlockAddressSDNode>(Op)) {
- Result =
- DAG.getTargetBlockAddress(BA->getBlockAddress(), BA->getValueType(0));
- } else if (const ExternalSymbolSDNode *ES =
- dyn_cast<ExternalSymbolSDNode>(Op)) {
- Result =
- DAG.getTargetExternalSymbol(ES->getSymbol(), ES->getValueType(0));
- } else
- return;
- break;
- }
- case 'I':
- case 'J':
- case 'K':
- case 'L':
- case 'M':
- case 'N':
- ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op);
- if (!C)
- return;
-
- uint64_t CVal = C->getZExtValue();
- switch (ConstraintLetter) {
-
-
-
-
-
-
- case 'I':
- if (isUInt<12>(CVal) || isShiftedUInt<12, 12>(CVal))
- break;
- return;
- case 'J': {
- uint64_t NVal = -C->getSExtValue();
- if (isUInt<12>(NVal) || isShiftedUInt<12, 12>(NVal)) {
- CVal = C->getSExtValue();
- break;
- }
- return;
- }
-
-
-
-
-
-
-
- case 'K':
- if (AArch64_AM::isLogicalImmediate(CVal, 32))
- break;
- return;
- case 'L':
- if (AArch64_AM::isLogicalImmediate(CVal, 64))
- break;
- return;
-
-
-
-
-
-
- case 'M': {
- if (!isUInt<32>(CVal))
- return;
- if (AArch64_AM::isLogicalImmediate(CVal, 32))
- break;
- if ((CVal & 0xFFFF) == CVal)
- break;
- if ((CVal & 0xFFFF0000ULL) == CVal)
- break;
- uint64_t NCVal = ~(uint32_t)CVal;
- if ((NCVal & 0xFFFFULL) == NCVal)
- break;
- if ((NCVal & 0xFFFF0000ULL) == NCVal)
- break;
- return;
- }
- case 'N': {
- if (AArch64_AM::isLogicalImmediate(CVal, 64))
- break;
- if ((CVal & 0xFFFFULL) == CVal)
- break;
- if ((CVal & 0xFFFF0000ULL) == CVal)
- break;
- if ((CVal & 0xFFFF00000000ULL) == CVal)
- break;
- if ((CVal & 0xFFFF000000000000ULL) == CVal)
- break;
- uint64_t NCVal = ~CVal;
- if ((NCVal & 0xFFFFULL) == NCVal)
- break;
- if ((NCVal & 0xFFFF0000ULL) == NCVal)
- break;
- if ((NCVal & 0xFFFF00000000ULL) == NCVal)
- break;
- if ((NCVal & 0xFFFF000000000000ULL) == NCVal)
- break;
- return;
- }
- default:
- return;
- }
-
- Result = DAG.getTargetConstant(CVal, SDLoc(Op), MVT::i64);
- break;
- }
- if (Result.getNode()) {
- Ops.push_back(Result);
- return;
- }
- return TargetLowering::LowerAsmOperandForConstraint(Op, Constraint, Ops, DAG);
- }
- static SDValue WidenVector(SDValue V64Reg, SelectionDAG &DAG) {
- EVT VT = V64Reg.getValueType();
- unsigned NarrowSize = VT.getVectorNumElements();
- MVT EltTy = VT.getVectorElementType().getSimpleVT();
- MVT WideTy = MVT::getVectorVT(EltTy, 2 * NarrowSize);
- SDLoc DL(V64Reg);
- return DAG.getNode(ISD::INSERT_SUBVECTOR, DL, WideTy, DAG.getUNDEF(WideTy),
- V64Reg, DAG.getConstant(0, DL, MVT::i32));
- }
- static unsigned getExtFactor(SDValue &V) {
- EVT EltType = V.getValueType().getVectorElementType();
- return EltType.getSizeInBits() / 8;
- }
- static SDValue NarrowVector(SDValue V128Reg, SelectionDAG &DAG) {
- EVT VT = V128Reg.getValueType();
- unsigned WideSize = VT.getVectorNumElements();
- MVT EltTy = VT.getVectorElementType().getSimpleVT();
- MVT NarrowTy = MVT::getVectorVT(EltTy, WideSize / 2);
- SDLoc DL(V128Reg);
- return DAG.getTargetExtractSubreg(AArch64::dsub, DL, NarrowTy, V128Reg);
- }
- SDValue AArch64TargetLowering::ReconstructShuffle(SDValue Op,
- SelectionDAG &DAG) const {
- assert(Op.getOpcode() == ISD::BUILD_VECTOR && "Unknown opcode!");
- LLVM_DEBUG(dbgs() << "AArch64TargetLowering::ReconstructShuffle\n");
- SDLoc dl(Op);
- EVT VT = Op.getValueType();
- assert(!VT.isScalableVector() &&
- "Scalable vectors cannot be used with ISD::BUILD_VECTOR");
- unsigned NumElts = VT.getVectorNumElements();
- struct ShuffleSourceInfo {
- SDValue Vec;
- unsigned MinElt;
- unsigned MaxElt;
-
-
-
- SDValue ShuffleVec;
-
-
- int WindowBase;
- int WindowScale;
- ShuffleSourceInfo(SDValue Vec)
- : Vec(Vec), MinElt(std::numeric_limits<unsigned>::max()), MaxElt(0),
- ShuffleVec(Vec), WindowBase(0), WindowScale(1) {}
- bool operator ==(SDValue OtherVec) { return Vec == OtherVec; }
- };
-
-
- SmallVector<ShuffleSourceInfo, 2> Sources;
- for (unsigned i = 0; i < NumElts; ++i) {
- SDValue V = Op.getOperand(i);
- if (V.isUndef())
- continue;
- else if (V.getOpcode() != ISD::EXTRACT_VECTOR_ELT ||
- !isa<ConstantSDNode>(V.getOperand(1))) {
- LLVM_DEBUG(
- dbgs() << "Reshuffle failed: "
- "a shuffle can only come from building a vector from "
- "various elements of other vectors, provided their "
- "indices are constant\n");
- return SDValue();
- }
-
- SDValue SourceVec = V.getOperand(0);
- auto Source = find(Sources, SourceVec);
- if (Source == Sources.end())
- Source = Sources.insert(Sources.end(), ShuffleSourceInfo(SourceVec));
-
- unsigned EltNo = cast<ConstantSDNode>(V.getOperand(1))->getZExtValue();
- Source->MinElt = std::min(Source->MinElt, EltNo);
- Source->MaxElt = std::max(Source->MaxElt, EltNo);
- }
- if (Sources.size() > 2) {
- LLVM_DEBUG(
- dbgs() << "Reshuffle failed: currently only do something sane when at "
- "most two source vectors are involved\n");
- return SDValue();
- }
-
-
- EVT SmallestEltTy = VT.getVectorElementType();
- for (auto &Source : Sources) {
- EVT SrcEltTy = Source.Vec.getValueType().getVectorElementType();
- if (SrcEltTy.bitsLT(SmallestEltTy)) {
- SmallestEltTy = SrcEltTy;
- }
- }
- unsigned ResMultiplier =
- VT.getScalarSizeInBits() / SmallestEltTy.getFixedSizeInBits();
- uint64_t VTSize = VT.getFixedSizeInBits();
- NumElts = VTSize / SmallestEltTy.getFixedSizeInBits();
- EVT ShuffleVT = EVT::getVectorVT(*DAG.getContext(), SmallestEltTy, NumElts);
-
-
-
- for (auto &Src : Sources) {
- EVT SrcVT = Src.ShuffleVec.getValueType();
- uint64_t SrcVTSize = SrcVT.getFixedSizeInBits();
- if (SrcVTSize == VTSize)
- continue;
-
-
- EVT EltVT = SrcVT.getVectorElementType();
- unsigned NumSrcElts = VTSize / EltVT.getFixedSizeInBits();
- EVT DestVT = EVT::getVectorVT(*DAG.getContext(), EltVT, NumSrcElts);
- if (SrcVTSize < VTSize) {
- assert(2 * SrcVTSize == VTSize);
-
-
- Src.ShuffleVec =
- DAG.getNode(ISD::CONCAT_VECTORS, dl, DestVT, Src.ShuffleVec,
- DAG.getUNDEF(Src.ShuffleVec.getValueType()));
- continue;
- }
- if (SrcVTSize != 2 * VTSize) {
- LLVM_DEBUG(
- dbgs() << "Reshuffle failed: result vector too small to extract\n");
- return SDValue();
- }
- if (Src.MaxElt - Src.MinElt >= NumSrcElts) {
- LLVM_DEBUG(
- dbgs() << "Reshuffle failed: span too large for a VEXT to cope\n");
- return SDValue();
- }
- if (Src.MinElt >= NumSrcElts) {
-
- Src.ShuffleVec =
- DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, DestVT, Src.ShuffleVec,
- DAG.getConstant(NumSrcElts, dl, MVT::i64));
- Src.WindowBase = -NumSrcElts;
- } else if (Src.MaxElt < NumSrcElts) {
-
- Src.ShuffleVec =
- DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, DestVT, Src.ShuffleVec,
- DAG.getConstant(0, dl, MVT::i64));
- } else {
-
- SDValue VEXTSrc1 =
- DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, DestVT, Src.ShuffleVec,
- DAG.getConstant(0, dl, MVT::i64));
- SDValue VEXTSrc2 =
- DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, DestVT, Src.ShuffleVec,
- DAG.getConstant(NumSrcElts, dl, MVT::i64));
- unsigned Imm = Src.MinElt * getExtFactor(VEXTSrc1);
- if (!SrcVT.is64BitVector()) {
- LLVM_DEBUG(
- dbgs() << "Reshuffle failed: don't know how to lower AArch64ISD::EXT "
- "for SVE vectors.");
- return SDValue();
- }
- Src.ShuffleVec = DAG.getNode(AArch64ISD::EXT, dl, DestVT, VEXTSrc1,
- VEXTSrc2,
- DAG.getConstant(Imm, dl, MVT::i32));
- Src.WindowBase = -Src.MinElt;
- }
- }
-
-
-
- for (auto &Src : Sources) {
- EVT SrcEltTy = Src.ShuffleVec.getValueType().getVectorElementType();
- if (SrcEltTy == SmallestEltTy)
- continue;
- assert(ShuffleVT.getVectorElementType() == SmallestEltTy);
- Src.ShuffleVec = DAG.getNode(ISD::BITCAST, dl, ShuffleVT, Src.ShuffleVec);
- Src.WindowScale =
- SrcEltTy.getFixedSizeInBits() / SmallestEltTy.getFixedSizeInBits();
- Src.WindowBase *= Src.WindowScale;
- }
-
- LLVM_DEBUG(for (auto Src
- : Sources)
- assert(Src.ShuffleVec.getValueType() == ShuffleVT););
-
- SmallVector<int, 8> Mask(ShuffleVT.getVectorNumElements(), -1);
- int BitsPerShuffleLane = ShuffleVT.getScalarSizeInBits();
- for (unsigned i = 0; i < VT.getVectorNumElements(); ++i) {
- SDValue Entry = Op.getOperand(i);
- if (Entry.isUndef())
- continue;
- auto Src = find(Sources, Entry.getOperand(0));
- int EltNo = cast<ConstantSDNode>(Entry.getOperand(1))->getSExtValue();
-
-
-
- EVT OrigEltTy = Entry.getOperand(0).getValueType().getVectorElementType();
- int BitsDefined = std::min(OrigEltTy.getScalarSizeInBits(),
- VT.getScalarSizeInBits());
- int LanesDefined = BitsDefined / BitsPerShuffleLane;
-
-
- int *LaneMask = &Mask[i * ResMultiplier];
- int ExtractBase = EltNo * Src->WindowScale + Src->WindowBase;
- ExtractBase += NumElts * (Src - Sources.begin());
- for (int j = 0; j < LanesDefined; ++j)
- LaneMask[j] = ExtractBase + j;
- }
-
- if (!isShuffleMaskLegal(Mask, ShuffleVT)) {
- LLVM_DEBUG(dbgs() << "Reshuffle failed: illegal shuffle mask\n");
- return SDValue();
- }
- SDValue ShuffleOps[] = { DAG.getUNDEF(ShuffleVT), DAG.getUNDEF(ShuffleVT) };
- for (unsigned i = 0; i < Sources.size(); ++i)
- ShuffleOps[i] = Sources[i].ShuffleVec;
- SDValue Shuffle = DAG.getVectorShuffle(ShuffleVT, dl, ShuffleOps[0],
- ShuffleOps[1], Mask);
- SDValue V = DAG.getNode(ISD::BITCAST, dl, VT, Shuffle);
- LLVM_DEBUG(dbgs() << "Reshuffle, creating node: "; Shuffle.dump();
- dbgs() << "Reshuffle, creating node: "; V.dump(););
- return V;
- }
- static bool isSingletonEXTMask(ArrayRef<int> M, EVT VT, unsigned &Imm) {
- unsigned NumElts = VT.getVectorNumElements();
-
- if (M[0] < 0)
- return false;
- Imm = M[0];
-
-
-
- unsigned ExpectedElt = Imm;
- for (unsigned i = 1; i < NumElts; ++i) {
-
-
- ++ExpectedElt;
- if (ExpectedElt == NumElts)
- ExpectedElt = 0;
- if (M[i] < 0)
- continue;
- if (ExpectedElt != static_cast<unsigned>(M[i]))
- return false;
- }
- return true;
- }
- static bool isWideDUPMask(ArrayRef<int> M, EVT VT, unsigned BlockSize,
- unsigned &DupLaneOp) {
- assert((BlockSize == 16 || BlockSize == 32 || BlockSize == 64) &&
- "Only possible block sizes for wide DUP are: 16, 32, 64");
- if (BlockSize <= VT.getScalarSizeInBits())
- return false;
- if (BlockSize % VT.getScalarSizeInBits() != 0)
- return false;
- if (VT.getSizeInBits() % BlockSize != 0)
- return false;
- size_t SingleVecNumElements = VT.getVectorNumElements();
- size_t NumEltsPerBlock = BlockSize / VT.getScalarSizeInBits();
- size_t NumBlocks = VT.getSizeInBits() / BlockSize;
-
-
-
-
-
- SmallVector<int, 8> BlockElts(NumEltsPerBlock, -1);
- for (size_t BlockIndex = 0; BlockIndex < NumBlocks; BlockIndex++)
- for (size_t I = 0; I < NumEltsPerBlock; I++) {
- int Elt = M[BlockIndex * NumEltsPerBlock + I];
- if (Elt < 0)
- continue;
-
- if ((unsigned)Elt >= SingleVecNumElements)
- return false;
- if (BlockElts[I] < 0)
- BlockElts[I] = Elt;
- else if (BlockElts[I] != Elt)
- return false;
- }
-
-
-
-
- auto FirstRealEltIter = find_if(BlockElts, [](int Elt) { return Elt >= 0; });
- assert(FirstRealEltIter != BlockElts.end() &&
- "Shuffle with all-undefs must have been caught by previous cases, "
- "e.g. isSplat()");
- if (FirstRealEltIter == BlockElts.end()) {
- DupLaneOp = 0;
- return true;
- }
-
- size_t FirstRealIndex = FirstRealEltIter - BlockElts.begin();
- if ((unsigned)*FirstRealEltIter < FirstRealIndex)
- return false;
-
- size_t Elt0 = *FirstRealEltIter - FirstRealIndex;
-
- if (Elt0 % NumEltsPerBlock != 0)
- return false;
-
-
- for (size_t I = 0; I < NumEltsPerBlock; I++)
- if (BlockElts[I] >= 0 && (unsigned)BlockElts[I] != Elt0 + I)
- return false;
- DupLaneOp = Elt0 / NumEltsPerBlock;
- return true;
- }
- static bool isEXTMask(ArrayRef<int> M, EVT VT, bool &ReverseEXT,
- unsigned &Imm) {
-
- const int *FirstRealElt = find_if(M, [](int Elt) { return Elt >= 0; });
-
- unsigned NumElts = VT.getVectorNumElements();
- unsigned MaskBits = APInt(32, NumElts * 2).logBase2();
- APInt ExpectedElt = APInt(MaskBits, *FirstRealElt + 1);
-
-
- const int *FirstWrongElt = std::find_if(FirstRealElt + 1, M.end(),
- [&](int Elt) {return Elt != ExpectedElt++ && Elt != -1;});
- if (FirstWrongElt != M.end())
- return false;
-
-
-
-
-
-
- Imm = ExpectedElt.getZExtValue();
-
-
-
-
-
-
- if (Imm < NumElts)
- ReverseEXT = true;
- else
- Imm -= NumElts;
- return true;
- }
- static bool isREVMask(ArrayRef<int> M, EVT VT, unsigned BlockSize) {
- assert((BlockSize == 16 || BlockSize == 32 || BlockSize == 64) &&
- "Only possible block sizes for REV are: 16, 32, 64");
- unsigned EltSz = VT.getScalarSizeInBits();
- if (EltSz == 64)
- return false;
- unsigned NumElts = VT.getVectorNumElements();
- unsigned BlockElts = M[0] + 1;
-
- if (M[0] < 0)
- BlockElts = BlockSize / EltSz;
- if (BlockSize <= EltSz || BlockSize != BlockElts * EltSz)
- return false;
- for (unsigned i = 0; i < NumElts; ++i) {
- if (M[i] < 0)
- continue;
- if ((unsigned)M[i] != (i - i % BlockElts) + (BlockElts - 1 - i % BlockElts))
- return false;
- }
- return true;
- }
- static bool isZIPMask(ArrayRef<int> M, EVT VT, unsigned &WhichResult) {
- unsigned NumElts = VT.getVectorNumElements();
- if (NumElts % 2 != 0)
- return false;
- WhichResult = (M[0] == 0 ? 0 : 1);
- unsigned Idx = WhichResult * NumElts / 2;
- for (unsigned i = 0; i != NumElts; i += 2) {
- if ((M[i] >= 0 && (unsigned)M[i] != Idx) ||
- (M[i + 1] >= 0 && (unsigned)M[i + 1] != Idx + NumElts))
- return false;
- Idx += 1;
- }
- return true;
- }
- static bool isUZPMask(ArrayRef<int> M, EVT VT, unsigned &WhichResult) {
- unsigned NumElts = VT.getVectorNumElements();
- WhichResult = (M[0] == 0 ? 0 : 1);
- for (unsigned i = 0; i != NumElts; ++i) {
- if (M[i] < 0)
- continue;
- if ((unsigned)M[i] != 2 * i + WhichResult)
- return false;
- }
- return true;
- }
- static bool isTRNMask(ArrayRef<int> M, EVT VT, unsigned &WhichResult) {
- unsigned NumElts = VT.getVectorNumElements();
- if (NumElts % 2 != 0)
- return false;
- WhichResult = (M[0] == 0 ? 0 : 1);
- for (unsigned i = 0; i < NumElts; i += 2) {
- if ((M[i] >= 0 && (unsigned)M[i] != i + WhichResult) ||
- (M[i + 1] >= 0 && (unsigned)M[i + 1] != i + NumElts + WhichResult))
- return false;
- }
- return true;
- }
- static bool isZIP_v_undef_Mask(ArrayRef<int> M, EVT VT, unsigned &WhichResult) {
- unsigned NumElts = VT.getVectorNumElements();
- if (NumElts % 2 != 0)
- return false;
- WhichResult = (M[0] == 0 ? 0 : 1);
- unsigned Idx = WhichResult * NumElts / 2;
- for (unsigned i = 0; i != NumElts; i += 2) {
- if ((M[i] >= 0 && (unsigned)M[i] != Idx) ||
- (M[i + 1] >= 0 && (unsigned)M[i + 1] != Idx))
- return false;
- Idx += 1;
- }
- return true;
- }
- static bool isUZP_v_undef_Mask(ArrayRef<int> M, EVT VT, unsigned &WhichResult) {
- unsigned Half = VT.getVectorNumElements() / 2;
- WhichResult = (M[0] == 0 ? 0 : 1);
- for (unsigned j = 0; j != 2; ++j) {
- unsigned Idx = WhichResult;
- for (unsigned i = 0; i != Half; ++i) {
- int MIdx = M[i + j * Half];
- if (MIdx >= 0 && (unsigned)MIdx != Idx)
- return false;
- Idx += 2;
- }
- }
- return true;
- }
- static bool isTRN_v_undef_Mask(ArrayRef<int> M, EVT VT, unsigned &WhichResult) {
- unsigned NumElts = VT.getVectorNumElements();
- if (NumElts % 2 != 0)
- return false;
- WhichResult = (M[0] == 0 ? 0 : 1);
- for (unsigned i = 0; i < NumElts; i += 2) {
- if ((M[i] >= 0 && (unsigned)M[i] != i + WhichResult) ||
- (M[i + 1] >= 0 && (unsigned)M[i + 1] != i + WhichResult))
- return false;
- }
- return true;
- }
- static bool isINSMask(ArrayRef<int> M, int NumInputElements,
- bool &DstIsLeft, int &Anomaly) {
- if (M.size() != static_cast<size_t>(NumInputElements))
- return false;
- int NumLHSMatch = 0, NumRHSMatch = 0;
- int LastLHSMismatch = -1, LastRHSMismatch = -1;
- for (int i = 0; i < NumInputElements; ++i) {
- if (M[i] == -1) {
- ++NumLHSMatch;
- ++NumRHSMatch;
- continue;
- }
- if (M[i] == i)
- ++NumLHSMatch;
- else
- LastLHSMismatch = i;
- if (M[i] == i + NumInputElements)
- ++NumRHSMatch;
- else
- LastRHSMismatch = i;
- }
- if (NumLHSMatch == NumInputElements - 1) {
- DstIsLeft = true;
- Anomaly = LastLHSMismatch;
- return true;
- } else if (NumRHSMatch == NumInputElements - 1) {
- DstIsLeft = false;
- Anomaly = LastRHSMismatch;
- return true;
- }
- return false;
- }
- static bool isConcatMask(ArrayRef<int> Mask, EVT VT, bool SplitLHS) {
- if (VT.getSizeInBits() != 128)
- return false;
- unsigned NumElts = VT.getVectorNumElements();
- for (int I = 0, E = NumElts / 2; I != E; I++) {
- if (Mask[I] != I)
- return false;
- }
- int Offset = NumElts / 2;
- for (int I = NumElts / 2, E = NumElts; I != E; I++) {
- if (Mask[I] != I + SplitLHS * Offset)
- return false;
- }
- return true;
- }
- static SDValue tryFormConcatFromShuffle(SDValue Op, SelectionDAG &DAG) {
- SDLoc DL(Op);
- EVT VT = Op.getValueType();
- SDValue V0 = Op.getOperand(0);
- SDValue V1 = Op.getOperand(1);
- ArrayRef<int> Mask = cast<ShuffleVectorSDNode>(Op)->getMask();
- if (VT.getVectorElementType() != V0.getValueType().getVectorElementType() ||
- VT.getVectorElementType() != V1.getValueType().getVectorElementType())
- return SDValue();
- bool SplitV0 = V0.getValueSizeInBits() == 128;
- if (!isConcatMask(Mask, VT, SplitV0))
- return SDValue();
- EVT CastVT = VT.getHalfNumVectorElementsVT(*DAG.getContext());
- if (SplitV0) {
- V0 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, CastVT, V0,
- DAG.getConstant(0, DL, MVT::i64));
- }
- if (V1.getValueSizeInBits() == 128) {
- V1 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, CastVT, V1,
- DAG.getConstant(0, DL, MVT::i64));
- }
- return DAG.getNode(ISD::CONCAT_VECTORS, DL, VT, V0, V1);
- }
- static SDValue GeneratePerfectShuffle(unsigned PFEntry, SDValue LHS,
- SDValue RHS, SelectionDAG &DAG,
- const SDLoc &dl) {
- unsigned OpNum = (PFEntry >> 26) & 0x0F;
- unsigned LHSID = (PFEntry >> 13) & ((1 << 13) - 1);
- unsigned RHSID = (PFEntry >> 0) & ((1 << 13) - 1);
- enum {
- OP_COPY = 0,
- OP_VREV,
- OP_VDUP0,
- OP_VDUP1,
- OP_VDUP2,
- OP_VDUP3,
- OP_VEXT1,
- OP_VEXT2,
- OP_VEXT3,
- OP_VUZPL,
- OP_VUZPR,
- OP_VZIPL,
- OP_VZIPR,
- OP_VTRNL,
- OP_VTRNR
- };
- if (OpNum == OP_COPY) {
- if (LHSID == (1 * 9 + 2) * 9 + 3)
- return LHS;
- assert(LHSID == ((4 * 9 + 5) * 9 + 6) * 9 + 7 && "Illegal OP_COPY!");
- return RHS;
- }
- SDValue OpLHS, OpRHS;
- OpLHS = GeneratePerfectShuffle(PerfectShuffleTable[LHSID], LHS, RHS, DAG, dl);
- OpRHS = GeneratePerfectShuffle(PerfectShuffleTable[RHSID], LHS, RHS, DAG, dl);
- EVT VT = OpLHS.getValueType();
- switch (OpNum) {
- default:
- llvm_unreachable("Unknown shuffle opcode!");
- case OP_VREV:
-
- if (VT.getVectorElementType() == MVT::i32 ||
- VT.getVectorElementType() == MVT::f32)
- return DAG.getNode(AArch64ISD::REV64, dl, VT, OpLHS);
-
- if (VT.getVectorElementType() == MVT::i16 ||
- VT.getVectorElementType() == MVT::f16 ||
- VT.getVectorElementType() == MVT::bf16)
- return DAG.getNode(AArch64ISD::REV32, dl, VT, OpLHS);
-
- assert(VT.getVectorElementType() == MVT::i8);
- return DAG.getNode(AArch64ISD::REV16, dl, VT, OpLHS);
- case OP_VDUP0:
- case OP_VDUP1:
- case OP_VDUP2:
- case OP_VDUP3: {
- EVT EltTy = VT.getVectorElementType();
- unsigned Opcode;
- if (EltTy == MVT::i8)
- Opcode = AArch64ISD::DUPLANE8;
- else if (EltTy == MVT::i16 || EltTy == MVT::f16 || EltTy == MVT::bf16)
- Opcode = AArch64ISD::DUPLANE16;
- else if (EltTy == MVT::i32 || EltTy == MVT::f32)
- Opcode = AArch64ISD::DUPLANE32;
- else if (EltTy == MVT::i64 || EltTy == MVT::f64)
- Opcode = AArch64ISD::DUPLANE64;
- else
- llvm_unreachable("Invalid vector element type?");
- if (VT.getSizeInBits() == 64)
- OpLHS = WidenVector(OpLHS, DAG);
- SDValue Lane = DAG.getConstant(OpNum - OP_VDUP0, dl, MVT::i64);
- return DAG.getNode(Opcode, dl, VT, OpLHS, Lane);
- }
- case OP_VEXT1:
- case OP_VEXT2:
- case OP_VEXT3: {
- unsigned Imm = (OpNum - OP_VEXT1 + 1) * getExtFactor(OpLHS);
- return DAG.getNode(AArch64ISD::EXT, dl, VT, OpLHS, OpRHS,
- DAG.getConstant(Imm, dl, MVT::i32));
- }
- case OP_VUZPL:
- return DAG.getNode(AArch64ISD::UZP1, dl, DAG.getVTList(VT, VT), OpLHS,
- OpRHS);
- case OP_VUZPR:
- return DAG.getNode(AArch64ISD::UZP2, dl, DAG.getVTList(VT, VT), OpLHS,
- OpRHS);
- case OP_VZIPL:
- return DAG.getNode(AArch64ISD::ZIP1, dl, DAG.getVTList(VT, VT), OpLHS,
- OpRHS);
- case OP_VZIPR:
- return DAG.getNode(AArch64ISD::ZIP2, dl, DAG.getVTList(VT, VT), OpLHS,
- OpRHS);
- case OP_VTRNL:
- return DAG.getNode(AArch64ISD::TRN1, dl, DAG.getVTList(VT, VT), OpLHS,
- OpRHS);
- case OP_VTRNR:
- return DAG.getNode(AArch64ISD::TRN2, dl, DAG.getVTList(VT, VT), OpLHS,
- OpRHS);
- }
- }
- static SDValue GenerateTBL(SDValue Op, ArrayRef<int> ShuffleMask,
- SelectionDAG &DAG) {
-
- SDValue V1 = Op.getOperand(0);
- SDValue V2 = Op.getOperand(1);
- SDLoc DL(Op);
- EVT EltVT = Op.getValueType().getVectorElementType();
- unsigned BytesPerElt = EltVT.getSizeInBits() / 8;
- SmallVector<SDValue, 8> TBLMask;
- for (int Val : ShuffleMask) {
- for (unsigned Byte = 0; Byte < BytesPerElt; ++Byte) {
- unsigned Offset = Byte + Val * BytesPerElt;
- TBLMask.push_back(DAG.getConstant(Offset, DL, MVT::i32));
- }
- }
- MVT IndexVT = MVT::v8i8;
- unsigned IndexLen = 8;
- if (Op.getValueSizeInBits() == 128) {
- IndexVT = MVT::v16i8;
- IndexLen = 16;
- }
- SDValue V1Cst = DAG.getNode(ISD::BITCAST, DL, IndexVT, V1);
- SDValue V2Cst = DAG.getNode(ISD::BITCAST, DL, IndexVT, V2);
- SDValue Shuffle;
- if (V2.getNode()->isUndef()) {
- if (IndexLen == 8)
- V1Cst = DAG.getNode(ISD::CONCAT_VECTORS, DL, MVT::v16i8, V1Cst, V1Cst);
- Shuffle = DAG.getNode(
- ISD::INTRINSIC_WO_CHAIN, DL, IndexVT,
- DAG.getConstant(Intrinsic::aarch64_neon_tbl1, DL, MVT::i32), V1Cst,
- DAG.getBuildVector(IndexVT, DL,
- makeArrayRef(TBLMask.data(), IndexLen)));
- } else {
- if (IndexLen == 8) {
- V1Cst = DAG.getNode(ISD::CONCAT_VECTORS, DL, MVT::v16i8, V1Cst, V2Cst);
- Shuffle = DAG.getNode(
- ISD::INTRINSIC_WO_CHAIN, DL, IndexVT,
- DAG.getConstant(Intrinsic::aarch64_neon_tbl1, DL, MVT::i32), V1Cst,
- DAG.getBuildVector(IndexVT, DL,
- makeArrayRef(TBLMask.data(), IndexLen)));
- } else {
-
-
-
-
-
-
- Shuffle = DAG.getNode(
- ISD::INTRINSIC_WO_CHAIN, DL, IndexVT,
- DAG.getConstant(Intrinsic::aarch64_neon_tbl2, DL, MVT::i32), V1Cst,
- V2Cst, DAG.getBuildVector(IndexVT, DL,
- makeArrayRef(TBLMask.data(), IndexLen)));
- }
- }
- return DAG.getNode(ISD::BITCAST, DL, Op.getValueType(), Shuffle);
- }
- static unsigned getDUPLANEOp(EVT EltType) {
- if (EltType == MVT::i8)
- return AArch64ISD::DUPLANE8;
- if (EltType == MVT::i16 || EltType == MVT::f16 || EltType == MVT::bf16)
- return AArch64ISD::DUPLANE16;
- if (EltType == MVT::i32 || EltType == MVT::f32)
- return AArch64ISD::DUPLANE32;
- if (EltType == MVT::i64 || EltType == MVT::f64)
- return AArch64ISD::DUPLANE64;
- llvm_unreachable("Invalid vector element type?");
- }
- static SDValue constructDup(SDValue V, int Lane, SDLoc dl, EVT VT,
- unsigned Opcode, SelectionDAG &DAG) {
-
- auto getScaledOffsetDup = [](SDValue BitCast, int &LaneC, MVT &CastVT) {
-
- if (BitCast.getOpcode() != ISD::BITCAST ||
- BitCast.getOperand(0).getOpcode() != ISD::EXTRACT_SUBVECTOR)
- return false;
-
-
- SDValue Extract = BitCast.getOperand(0);
- unsigned ExtIdx = Extract.getConstantOperandVal(1);
- unsigned SrcEltBitWidth = Extract.getScalarValueSizeInBits();
- unsigned ExtIdxInBits = ExtIdx * SrcEltBitWidth;
- unsigned CastedEltBitWidth = BitCast.getScalarValueSizeInBits();
- if (ExtIdxInBits % CastedEltBitWidth != 0)
- return false;
-
- LaneC += ExtIdxInBits / CastedEltBitWidth;
-
-
-
-
-
- unsigned SrcVecNumElts =
- Extract.getOperand(0).getValueSizeInBits() / CastedEltBitWidth;
- CastVT = MVT::getVectorVT(BitCast.getSimpleValueType().getScalarType(),
- SrcVecNumElts);
- return true;
- };
- MVT CastVT;
- if (getScaledOffsetDup(V, Lane, CastVT)) {
- V = DAG.getBitcast(CastVT, V.getOperand(0).getOperand(0));
- } else if (V.getOpcode() == ISD::EXTRACT_SUBVECTOR) {
-
-
- Lane += V.getConstantOperandVal(1);
- V = V.getOperand(0);
- } else if (V.getOpcode() == ISD::CONCAT_VECTORS) {
-
-
- unsigned Idx = Lane >= (int)VT.getVectorNumElements() / 2;
- Lane -= Idx * VT.getVectorNumElements() / 2;
- V = WidenVector(V.getOperand(Idx), DAG);
- } else if (VT.getSizeInBits() == 64) {
-
- V = WidenVector(V, DAG);
- }
- return DAG.getNode(Opcode, dl, VT, V, DAG.getConstant(Lane, dl, MVT::i64));
- }
- SDValue AArch64TargetLowering::LowerVECTOR_SHUFFLE(SDValue Op,
- SelectionDAG &DAG) const {
- SDLoc dl(Op);
- EVT VT = Op.getValueType();
- ShuffleVectorSDNode *SVN = cast<ShuffleVectorSDNode>(Op.getNode());
-
-
-
-
- ArrayRef<int> ShuffleMask = SVN->getMask();
- SDValue V1 = Op.getOperand(0);
- SDValue V2 = Op.getOperand(1);
- if (SVN->isSplat()) {
- int Lane = SVN->getSplatIndex();
-
- if (Lane == -1)
- Lane = 0;
- if (Lane == 0 && V1.getOpcode() == ISD::SCALAR_TO_VECTOR)
- return DAG.getNode(AArch64ISD::DUP, dl, V1.getValueType(),
- V1.getOperand(0));
-
-
- if (V1.getOpcode() == ISD::BUILD_VECTOR &&
- !isa<ConstantSDNode>(V1.getOperand(Lane)))
- return DAG.getNode(AArch64ISD::DUP, dl, VT, V1.getOperand(Lane));
-
- unsigned Opcode = getDUPLANEOp(V1.getValueType().getVectorElementType());
- return constructDup(V1, Lane, dl, VT, Opcode, DAG);
- }
-
- for (unsigned LaneSize : {64U, 32U, 16U}) {
- unsigned Lane = 0;
- if (isWideDUPMask(ShuffleMask, VT, LaneSize, Lane)) {
- unsigned Opcode = LaneSize == 64 ? AArch64ISD::DUPLANE64
- : LaneSize == 32 ? AArch64ISD::DUPLANE32
- : AArch64ISD::DUPLANE16;
-
- MVT NewEltTy = MVT::getIntegerVT(LaneSize);
- unsigned NewEltCount = VT.getSizeInBits() / LaneSize;
- MVT NewVecTy = MVT::getVectorVT(NewEltTy, NewEltCount);
- V1 = DAG.getBitcast(NewVecTy, V1);
-
- V1 = constructDup(V1, Lane, dl, NewVecTy, Opcode, DAG);
-
- return DAG.getBitcast(VT, V1);
- }
- }
- if (isREVMask(ShuffleMask, VT, 64))
- return DAG.getNode(AArch64ISD::REV64, dl, V1.getValueType(), V1, V2);
- if (isREVMask(ShuffleMask, VT, 32))
- return DAG.getNode(AArch64ISD::REV32, dl, V1.getValueType(), V1, V2);
- if (isREVMask(ShuffleMask, VT, 16))
- return DAG.getNode(AArch64ISD::REV16, dl, V1.getValueType(), V1, V2);
- bool ReverseEXT = false;
- unsigned Imm;
- if (isEXTMask(ShuffleMask, VT, ReverseEXT, Imm)) {
- if (ReverseEXT)
- std::swap(V1, V2);
- Imm *= getExtFactor(V1);
- return DAG.getNode(AArch64ISD::EXT, dl, V1.getValueType(), V1, V2,
- DAG.getConstant(Imm, dl, MVT::i32));
- } else if (V2->isUndef() && isSingletonEXTMask(ShuffleMask, VT, Imm)) {
- Imm *= getExtFactor(V1);
- return DAG.getNode(AArch64ISD::EXT, dl, V1.getValueType(), V1, V1,
- DAG.getConstant(Imm, dl, MVT::i32));
- }
- unsigned WhichResult;
- if (isZIPMask(ShuffleMask, VT, WhichResult)) {
- unsigned Opc = (WhichResult == 0) ? AArch64ISD::ZIP1 : AArch64ISD::ZIP2;
- return DAG.getNode(Opc, dl, V1.getValueType(), V1, V2);
- }
- if (isUZPMask(ShuffleMask, VT, WhichResult)) {
- unsigned Opc = (WhichResult == 0) ? AArch64ISD::UZP1 : AArch64ISD::UZP2;
- return DAG.getNode(Opc, dl, V1.getValueType(), V1, V2);
- }
- if (isTRNMask(ShuffleMask, VT, WhichResult)) {
- unsigned Opc = (WhichResult == 0) ? AArch64ISD::TRN1 : AArch64ISD::TRN2;
- return DAG.getNode(Opc, dl, V1.getValueType(), V1, V2);
- }
- if (isZIP_v_undef_Mask(ShuffleMask, VT, WhichResult)) {
- unsigned Opc = (WhichResult == 0) ? AArch64ISD::ZIP1 : AArch64ISD::ZIP2;
- return DAG.getNode(Opc, dl, V1.getValueType(), V1, V1);
- }
- if (isUZP_v_undef_Mask(ShuffleMask, VT, WhichResult)) {
- unsigned Opc = (WhichResult == 0) ? AArch64ISD::UZP1 : AArch64ISD::UZP2;
- return DAG.getNode(Opc, dl, V1.getValueType(), V1, V1);
- }
- if (isTRN_v_undef_Mask(ShuffleMask, VT, WhichResult)) {
- unsigned Opc = (WhichResult == 0) ? AArch64ISD::TRN1 : AArch64ISD::TRN2;
- return DAG.getNode(Opc, dl, V1.getValueType(), V1, V1);
- }
- if (SDValue Concat = tryFormConcatFromShuffle(Op, DAG))
- return Concat;
- bool DstIsLeft;
- int Anomaly;
- int NumInputElements = V1.getValueType().getVectorNumElements();
- if (isINSMask(ShuffleMask, NumInputElements, DstIsLeft, Anomaly)) {
- SDValue DstVec = DstIsLeft ? V1 : V2;
- SDValue DstLaneV = DAG.getConstant(Anomaly, dl, MVT::i64);
- SDValue SrcVec = V1;
- int SrcLane = ShuffleMask[Anomaly];
- if (SrcLane >= NumInputElements) {
- SrcVec = V2;
- SrcLane -= VT.getVectorNumElements();
- }
- SDValue SrcLaneV = DAG.getConstant(SrcLane, dl, MVT::i64);
- EVT ScalarVT = VT.getVectorElementType();
- if (ScalarVT.getFixedSizeInBits() < 32 && ScalarVT.isInteger())
- ScalarVT = MVT::i32;
- return DAG.getNode(
- ISD::INSERT_VECTOR_ELT, dl, VT, DstVec,
- DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, ScalarVT, SrcVec, SrcLaneV),
- DstLaneV);
- }
-
-
- unsigned NumElts = VT.getVectorNumElements();
- if (NumElts == 4) {
- unsigned PFIndexes[4];
- for (unsigned i = 0; i != 4; ++i) {
- if (ShuffleMask[i] < 0)
- PFIndexes[i] = 8;
- else
- PFIndexes[i] = ShuffleMask[i];
- }
-
- unsigned PFTableIndex = PFIndexes[0] * 9 * 9 * 9 + PFIndexes[1] * 9 * 9 +
- PFIndexes[2] * 9 + PFIndexes[3];
- unsigned PFEntry = PerfectShuffleTable[PFTableIndex];
- unsigned Cost = (PFEntry >> 30);
- if (Cost <= 4)
- return GeneratePerfectShuffle(PFEntry, V1, V2, DAG, dl);
- }
- return GenerateTBL(Op, ShuffleMask, DAG);
- }
- SDValue AArch64TargetLowering::LowerSPLAT_VECTOR(SDValue Op,
- SelectionDAG &DAG) const {
- SDLoc dl(Op);
- EVT VT = Op.getValueType();
- EVT ElemVT = VT.getScalarType();
- SDValue SplatVal = Op.getOperand(0);
- if (useSVEForFixedLengthVectorVT(VT))
- return LowerToScalableOp(Op, DAG);
-
-
- switch (ElemVT.getSimpleVT().SimpleTy) {
- case MVT::i1: {
-
-
- if (auto *ConstVal = dyn_cast<ConstantSDNode>(SplatVal)) {
- if (ConstVal->isOne())
- return getPTrue(DAG, dl, VT, AArch64SVEPredPattern::all);
-
- }
-
-
- SplatVal = DAG.getAnyExtOrTrunc(SplatVal, dl, MVT::i64);
- SplatVal = DAG.getNode(ISD::SIGN_EXTEND_INREG, dl, MVT::i64, SplatVal,
- DAG.getValueType(MVT::i1));
- SDValue ID = DAG.getTargetConstant(Intrinsic::aarch64_sve_whilelo, dl,
- MVT::i64);
- return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, VT, ID,
- DAG.getConstant(0, dl, MVT::i64), SplatVal);
- }
- case MVT::i8:
- case MVT::i16:
- case MVT::i32:
- SplatVal = DAG.getAnyExtOrTrunc(SplatVal, dl, MVT::i32);
- break;
- case MVT::i64:
- SplatVal = DAG.getAnyExtOrTrunc(SplatVal, dl, MVT::i64);
- break;
- case MVT::f16:
- case MVT::bf16:
- case MVT::f32:
- case MVT::f64:
-
- break;
- default:
- report_fatal_error("Unsupported SPLAT_VECTOR input operand type");
- }
- return DAG.getNode(AArch64ISD::DUP, dl, VT, SplatVal);
- }
- SDValue AArch64TargetLowering::LowerDUPQLane(SDValue Op,
- SelectionDAG &DAG) const {
- SDLoc DL(Op);
- EVT VT = Op.getValueType();
- if (!isTypeLegal(VT) || !VT.isScalableVector())
- return SDValue();
-
- if (VT.getSizeInBits().getKnownMinSize() != AArch64::SVEBitsPerBlock)
- return SDValue();
-
- SDValue V = DAG.getNode(ISD::BITCAST, DL, MVT::nxv2i64, Op.getOperand(1));
- SDValue Idx128 = Op.getOperand(2);
-
- auto *CIdx = dyn_cast<ConstantSDNode>(Idx128);
- if (CIdx && (CIdx->getZExtValue() <= 3)) {
- SDValue CI = DAG.getTargetConstant(CIdx->getZExtValue(), DL, MVT::i64);
- SDNode *DUPQ =
- DAG.getMachineNode(AArch64::DUP_ZZI_Q, DL, MVT::nxv2i64, V, CI);
- return DAG.getNode(ISD::BITCAST, DL, VT, SDValue(DUPQ, 0));
- }
-
-
-
-
- SDValue One = DAG.getConstant(1, DL, MVT::i64);
- SDValue SplatOne = DAG.getNode(ISD::SPLAT_VECTOR, DL, MVT::nxv2i64, One);
-
- SDValue Zero = DAG.getConstant(0, DL, MVT::i64);
- SDValue SV = DAG.getNode(AArch64ISD::INDEX_VECTOR,
- DL, MVT::nxv2i64, Zero, One);
- SV = DAG.getNode(ISD::AND, DL, MVT::nxv2i64, SV, SplatOne);
-
- SDValue Idx64 = DAG.getNode(ISD::ADD, DL, MVT::i64, Idx128, Idx128);
- SDValue SplatIdx64 = DAG.getNode(ISD::SPLAT_VECTOR, DL, MVT::nxv2i64, Idx64);
- SDValue ShuffleMask = DAG.getNode(ISD::ADD, DL, MVT::nxv2i64, SV, SplatIdx64);
-
- SDValue TBL = DAG.getNode(AArch64ISD::TBL, DL, MVT::nxv2i64, V, ShuffleMask);
- return DAG.getNode(ISD::BITCAST, DL, VT, TBL);
- }
- static bool resolveBuildVector(BuildVectorSDNode *BVN, APInt &CnstBits,
- APInt &UndefBits) {
- EVT VT = BVN->getValueType(0);
- APInt SplatBits, SplatUndef;
- unsigned SplatBitSize;
- bool HasAnyUndefs;
- if (BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, HasAnyUndefs)) {
- unsigned NumSplats = VT.getSizeInBits() / SplatBitSize;
- for (unsigned i = 0; i < NumSplats; ++i) {
- CnstBits <<= SplatBitSize;
- UndefBits <<= SplatBitSize;
- CnstBits |= SplatBits.zextOrTrunc(VT.getSizeInBits());
- UndefBits |= (SplatBits ^ SplatUndef).zextOrTrunc(VT.getSizeInBits());
- }
- return true;
- }
- return false;
- }
- static SDValue tryAdvSIMDModImm64(unsigned NewOp, SDValue Op, SelectionDAG &DAG,
- const APInt &Bits) {
- if (Bits.getHiBits(64) == Bits.getLoBits(64)) {
- uint64_t Value = Bits.zextOrTrunc(64).getZExtValue();
- EVT VT = Op.getValueType();
- MVT MovTy = (VT.getSizeInBits() == 128) ? MVT::v2i64 : MVT::f64;
- if (AArch64_AM::isAdvSIMDModImmType10(Value)) {
- Value = AArch64_AM::encodeAdvSIMDModImmType10(Value);
- SDLoc dl(Op);
- SDValue Mov = DAG.getNode(NewOp, dl, MovTy,
- DAG.getConstant(Value, dl, MVT::i32));
- return DAG.getNode(AArch64ISD::NVCAST, dl, VT, Mov);
- }
- }
- return SDValue();
- }
- static SDValue tryAdvSIMDModImm32(unsigned NewOp, SDValue Op, SelectionDAG &DAG,
- const APInt &Bits,
- const SDValue *LHS = nullptr) {
- if (Bits.getHiBits(64) == Bits.getLoBits(64)) {
- uint64_t Value = Bits.zextOrTrunc(64).getZExtValue();
- EVT VT = Op.getValueType();
- MVT MovTy = (VT.getSizeInBits() == 128) ? MVT::v4i32 : MVT::v2i32;
- bool isAdvSIMDModImm = false;
- uint64_t Shift;
- if ((isAdvSIMDModImm = AArch64_AM::isAdvSIMDModImmType1(Value))) {
- Value = AArch64_AM::encodeAdvSIMDModImmType1(Value);
- Shift = 0;
- }
- else if ((isAdvSIMDModImm = AArch64_AM::isAdvSIMDModImmType2(Value))) {
- Value = AArch64_AM::encodeAdvSIMDModImmType2(Value);
- Shift = 8;
- }
- else if ((isAdvSIMDModImm = AArch64_AM::isAdvSIMDModImmType3(Value))) {
- Value = AArch64_AM::encodeAdvSIMDModImmType3(Value);
- Shift = 16;
- }
- else if ((isAdvSIMDModImm = AArch64_AM::isAdvSIMDModImmType4(Value))) {
- Value = AArch64_AM::encodeAdvSIMDModImmType4(Value);
- Shift = 24;
- }
- if (isAdvSIMDModImm) {
- SDLoc dl(Op);
- SDValue Mov;
- if (LHS)
- Mov = DAG.getNode(NewOp, dl, MovTy, *LHS,
- DAG.getConstant(Value, dl, MVT::i32),
- DAG.getConstant(Shift, dl, MVT::i32));
- else
- Mov = DAG.getNode(NewOp, dl, MovTy,
- DAG.getConstant(Value, dl, MVT::i32),
- DAG.getConstant(Shift, dl, MVT::i32));
- return DAG.getNode(AArch64ISD::NVCAST, dl, VT, Mov);
- }
- }
- return SDValue();
- }
- static SDValue tryAdvSIMDModImm16(unsigned NewOp, SDValue Op, SelectionDAG &DAG,
- const APInt &Bits,
- const SDValue *LHS = nullptr) {
- if (Bits.getHiBits(64) == Bits.getLoBits(64)) {
- uint64_t Value = Bits.zextOrTrunc(64).getZExtValue();
- EVT VT = Op.getValueType();
- MVT MovTy = (VT.getSizeInBits() == 128) ? MVT::v8i16 : MVT::v4i16;
- bool isAdvSIMDModImm = false;
- uint64_t Shift;
- if ((isAdvSIMDModImm = AArch64_AM::isAdvSIMDModImmType5(Value))) {
- Value = AArch64_AM::encodeAdvSIMDModImmType5(Value);
- Shift = 0;
- }
- else if ((isAdvSIMDModImm = AArch64_AM::isAdvSIMDModImmType6(Value))) {
- Value = AArch64_AM::encodeAdvSIMDModImmType6(Value);
- Shift = 8;
- }
- if (isAdvSIMDModImm) {
- SDLoc dl(Op);
- SDValue Mov;
- if (LHS)
- Mov = DAG.getNode(NewOp, dl, MovTy, *LHS,
- DAG.getConstant(Value, dl, MVT::i32),
- DAG.getConstant(Shift, dl, MVT::i32));
- else
- Mov = DAG.getNode(NewOp, dl, MovTy,
- DAG.getConstant(Value, dl, MVT::i32),
- DAG.getConstant(Shift, dl, MVT::i32));
- return DAG.getNode(AArch64ISD::NVCAST, dl, VT, Mov);
- }
- }
- return SDValue();
- }
- static SDValue tryAdvSIMDModImm321s(unsigned NewOp, SDValue Op,
- SelectionDAG &DAG, const APInt &Bits) {
- if (Bits.getHiBits(64) == Bits.getLoBits(64)) {
- uint64_t Value = Bits.zextOrTrunc(64).getZExtValue();
- EVT VT = Op.getValueType();
- MVT MovTy = (VT.getSizeInBits() == 128) ? MVT::v4i32 : MVT::v2i32;
- bool isAdvSIMDModImm = false;
- uint64_t Shift;
- if ((isAdvSIMDModImm = AArch64_AM::isAdvSIMDModImmType7(Value))) {
- Value = AArch64_AM::encodeAdvSIMDModImmType7(Value);
- Shift = 264;
- }
- else if ((isAdvSIMDModImm = AArch64_AM::isAdvSIMDModImmType8(Value))) {
- Value = AArch64_AM::encodeAdvSIMDModImmType8(Value);
- Shift = 272;
- }
- if (isAdvSIMDModImm) {
- SDLoc dl(Op);
- SDValue Mov = DAG.getNode(NewOp, dl, MovTy,
- DAG.getConstant(Value, dl, MVT::i32),
- DAG.getConstant(Shift, dl, MVT::i32));
- return DAG.getNode(AArch64ISD::NVCAST, dl, VT, Mov);
- }
- }
- return SDValue();
- }
- static SDValue tryAdvSIMDModImm8(unsigned NewOp, SDValue Op, SelectionDAG &DAG,
- const APInt &Bits) {
- if (Bits.getHiBits(64) == Bits.getLoBits(64)) {
- uint64_t Value = Bits.zextOrTrunc(64).getZExtValue();
- EVT VT = Op.getValueType();
- MVT MovTy = (VT.getSizeInBits() == 128) ? MVT::v16i8 : MVT::v8i8;
- if (AArch64_AM::isAdvSIMDModImmType9(Value)) {
- Value = AArch64_AM::encodeAdvSIMDModImmType9(Value);
- SDLoc dl(Op);
- SDValue Mov = DAG.getNode(NewOp, dl, MovTy,
- DAG.getConstant(Value, dl, MVT::i32));
- return DAG.getNode(AArch64ISD::NVCAST, dl, VT, Mov);
- }
- }
- return SDValue();
- }
- static SDValue tryAdvSIMDModImmFP(unsigned NewOp, SDValue Op, SelectionDAG &DAG,
- const APInt &Bits) {
- if (Bits.getHiBits(64) == Bits.getLoBits(64)) {
- uint64_t Value = Bits.zextOrTrunc(64).getZExtValue();
- EVT VT = Op.getValueType();
- bool isWide = (VT.getSizeInBits() == 128);
- MVT MovTy;
- bool isAdvSIMDModImm = false;
- if ((isAdvSIMDModImm = AArch64_AM::isAdvSIMDModImmType11(Value))) {
- Value = AArch64_AM::encodeAdvSIMDModImmType11(Value);
- MovTy = isWide ? MVT::v4f32 : MVT::v2f32;
- }
- else if (isWide &&
- (isAdvSIMDModImm = AArch64_AM::isAdvSIMDModImmType12(Value))) {
- Value = AArch64_AM::encodeAdvSIMDModImmType12(Value);
- MovTy = MVT::v2f64;
- }
- if (isAdvSIMDModImm) {
- SDLoc dl(Op);
- SDValue Mov = DAG.getNode(NewOp, dl, MovTy,
- DAG.getConstant(Value, dl, MVT::i32));
- return DAG.getNode(AArch64ISD::NVCAST, dl, VT, Mov);
- }
- }
- return SDValue();
- }
- static bool isAllConstantBuildVector(const SDValue &PotentialBVec,
- uint64_t &ConstVal) {
- BuildVectorSDNode *Bvec = dyn_cast<BuildVectorSDNode>(PotentialBVec);
- if (!Bvec)
- return false;
- ConstantSDNode *FirstElt = dyn_cast<ConstantSDNode>(Bvec->getOperand(0));
- if (!FirstElt)
- return false;
- EVT VT = Bvec->getValueType(0);
- unsigned NumElts = VT.getVectorNumElements();
- for (unsigned i = 1; i < NumElts; ++i)
- if (dyn_cast<ConstantSDNode>(Bvec->getOperand(i)) != FirstElt)
- return false;
- ConstVal = FirstElt->getZExtValue();
- return true;
- }
- static unsigned getIntrinsicID(const SDNode *N) {
- unsigned Opcode = N->getOpcode();
- switch (Opcode) {
- default:
- return Intrinsic::not_intrinsic;
- case ISD::INTRINSIC_WO_CHAIN: {
- unsigned IID = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
- if (IID < Intrinsic::num_intrinsics)
- return IID;
- return Intrinsic::not_intrinsic;
- }
- }
- }
- static SDValue tryLowerToSLI(SDNode *N, SelectionDAG &DAG) {
- EVT VT = N->getValueType(0);
- if (!VT.isVector())
- return SDValue();
- SDLoc DL(N);
- SDValue And;
- SDValue Shift;
- SDValue FirstOp = N->getOperand(0);
- unsigned FirstOpc = FirstOp.getOpcode();
- SDValue SecondOp = N->getOperand(1);
- unsigned SecondOpc = SecondOp.getOpcode();
-
-
-
-
- if ((FirstOpc == ISD::AND || FirstOpc == AArch64ISD::BICi) &&
- (SecondOpc == AArch64ISD::VSHL || SecondOpc == AArch64ISD::VLSHR)) {
- And = FirstOp;
- Shift = SecondOp;
- } else if ((SecondOpc == ISD::AND || SecondOpc == AArch64ISD::BICi) &&
- (FirstOpc == AArch64ISD::VSHL || FirstOpc == AArch64ISD::VLSHR)) {
- And = SecondOp;
- Shift = FirstOp;
- } else
- return SDValue();
- bool IsAnd = And.getOpcode() == ISD::AND;
- bool IsShiftRight = Shift.getOpcode() == AArch64ISD::VLSHR;
-
- ConstantSDNode *C2node = dyn_cast<ConstantSDNode>(Shift.getOperand(1));
- if (!C2node)
- return SDValue();
- uint64_t C1;
- if (IsAnd) {
-
- if (!isAllConstantBuildVector(And.getOperand(1), C1))
- return SDValue();
- } else {
-
- ConstantSDNode *C1nodeImm = dyn_cast<ConstantSDNode>(And.getOperand(1));
- ConstantSDNode *C1nodeShift = dyn_cast<ConstantSDNode>(And.getOperand(2));
- assert(C1nodeImm && C1nodeShift);
- C1 = ~(C1nodeImm->getZExtValue() << C1nodeShift->getZExtValue());
- }
-
-
-
- uint64_t C2 = C2node->getZExtValue();
- unsigned ElemSizeInBits = VT.getScalarSizeInBits();
- if (C2 > ElemSizeInBits)
- return SDValue();
- APInt C1AsAPInt(ElemSizeInBits, C1);
- APInt RequiredC1 = IsShiftRight ? APInt::getHighBitsSet(ElemSizeInBits, C2)
- : APInt::getLowBitsSet(ElemSizeInBits, C2);
- if (C1AsAPInt != RequiredC1)
- return SDValue();
- SDValue X = And.getOperand(0);
- SDValue Y = Shift.getOperand(0);
- unsigned Inst = IsShiftRight ? AArch64ISD::VSRI : AArch64ISD::VSLI;
- SDValue ResultSLI = DAG.getNode(Inst, DL, VT, X, Y, Shift.getOperand(1));
- LLVM_DEBUG(dbgs() << "aarch64-lower: transformed: \n");
- LLVM_DEBUG(N->dump(&DAG));
- LLVM_DEBUG(dbgs() << "into: \n");
- LLVM_DEBUG(ResultSLI->dump(&DAG));
- ++NumShiftInserts;
- return ResultSLI;
- }
- SDValue AArch64TargetLowering::LowerVectorOR(SDValue Op,
- SelectionDAG &DAG) const {
- if (useSVEForFixedLengthVectorVT(Op.getValueType()))
- return LowerToScalableOp(Op, DAG);
-
- if (SDValue Res = tryLowerToSLI(Op.getNode(), DAG))
- return Res;
- EVT VT = Op.getValueType();
- SDValue LHS = Op.getOperand(0);
- BuildVectorSDNode *BVN =
- dyn_cast<BuildVectorSDNode>(Op.getOperand(1).getNode());
- if (!BVN) {
-
- LHS = Op.getOperand(1);
- BVN = dyn_cast<BuildVectorSDNode>(Op.getOperand(0).getNode());
- }
- if (!BVN)
- return Op;
- APInt DefBits(VT.getSizeInBits(), 0);
- APInt UndefBits(VT.getSizeInBits(), 0);
- if (resolveBuildVector(BVN, DefBits, UndefBits)) {
- SDValue NewOp;
- if ((NewOp = tryAdvSIMDModImm32(AArch64ISD::ORRi, Op, DAG,
- DefBits, &LHS)) ||
- (NewOp = tryAdvSIMDModImm16(AArch64ISD::ORRi, Op, DAG,
- DefBits, &LHS)))
- return NewOp;
- if ((NewOp = tryAdvSIMDModImm32(AArch64ISD::ORRi, Op, DAG,
- UndefBits, &LHS)) ||
- (NewOp = tryAdvSIMDModImm16(AArch64ISD::ORRi, Op, DAG,
- UndefBits, &LHS)))
- return NewOp;
- }
-
- return Op;
- }
- static SDValue NormalizeBuildVector(SDValue Op,
- SelectionDAG &DAG) {
- assert(Op.getOpcode() == ISD::BUILD_VECTOR && "Unknown opcode!");
- SDLoc dl(Op);
- EVT VT = Op.getValueType();
- EVT EltTy= VT.getVectorElementType();
- if (EltTy.isFloatingPoint() || EltTy.getSizeInBits() > 16)
- return Op;
- SmallVector<SDValue, 16> Ops;
- for (SDValue Lane : Op->ops()) {
-
-
-
-
- if (auto *CstLane = dyn_cast<ConstantSDNode>(Lane)) {
- APInt LowBits(EltTy.getSizeInBits(),
- CstLane->getZExtValue());
- Lane = DAG.getConstant(LowBits.getZExtValue(), dl, MVT::i32);
- } else if (Lane.getNode()->isUndef()) {
- Lane = DAG.getUNDEF(MVT::i32);
- } else {
- assert(Lane.getValueType() == MVT::i32 &&
- "Unexpected BUILD_VECTOR operand type");
- }
- Ops.push_back(Lane);
- }
- return DAG.getBuildVector(VT, dl, Ops);
- }
- static SDValue ConstantBuildVector(SDValue Op, SelectionDAG &DAG) {
- EVT VT = Op.getValueType();
- APInt DefBits(VT.getSizeInBits(), 0);
- APInt UndefBits(VT.getSizeInBits(), 0);
- BuildVectorSDNode *BVN = cast<BuildVectorSDNode>(Op.getNode());
- if (resolveBuildVector(BVN, DefBits, UndefBits)) {
- SDValue NewOp;
- if ((NewOp = tryAdvSIMDModImm64(AArch64ISD::MOVIedit, Op, DAG, DefBits)) ||
- (NewOp = tryAdvSIMDModImm32(AArch64ISD::MOVIshift, Op, DAG, DefBits)) ||
- (NewOp = tryAdvSIMDModImm321s(AArch64ISD::MOVImsl, Op, DAG, DefBits)) ||
- (NewOp = tryAdvSIMDModImm16(AArch64ISD::MOVIshift, Op, DAG, DefBits)) ||
- (NewOp = tryAdvSIMDModImm8(AArch64ISD::MOVI, Op, DAG, DefBits)) ||
- (NewOp = tryAdvSIMDModImmFP(AArch64ISD::FMOV, Op, DAG, DefBits)))
- return NewOp;
- DefBits = ~DefBits;
- if ((NewOp = tryAdvSIMDModImm32(AArch64ISD::MVNIshift, Op, DAG, DefBits)) ||
- (NewOp = tryAdvSIMDModImm321s(AArch64ISD::MVNImsl, Op, DAG, DefBits)) ||
- (NewOp = tryAdvSIMDModImm16(AArch64ISD::MVNIshift, Op, DAG, DefBits)))
- return NewOp;
- DefBits = UndefBits;
- if ((NewOp = tryAdvSIMDModImm64(AArch64ISD::MOVIedit, Op, DAG, DefBits)) ||
- (NewOp = tryAdvSIMDModImm32(AArch64ISD::MOVIshift, Op, DAG, DefBits)) ||
- (NewOp = tryAdvSIMDModImm321s(AArch64ISD::MOVImsl, Op, DAG, DefBits)) ||
- (NewOp = tryAdvSIMDModImm16(AArch64ISD::MOVIshift, Op, DAG, DefBits)) ||
- (NewOp = tryAdvSIMDModImm8(AArch64ISD::MOVI, Op, DAG, DefBits)) ||
- (NewOp = tryAdvSIMDModImmFP(AArch64ISD::FMOV, Op, DAG, DefBits)))
- return NewOp;
- DefBits = ~UndefBits;
- if ((NewOp = tryAdvSIMDModImm32(AArch64ISD::MVNIshift, Op, DAG, DefBits)) ||
- (NewOp = tryAdvSIMDModImm321s(AArch64ISD::MVNImsl, Op, DAG, DefBits)) ||
- (NewOp = tryAdvSIMDModImm16(AArch64ISD::MVNIshift, Op, DAG, DefBits)))
- return NewOp;
- }
- return SDValue();
- }
- SDValue AArch64TargetLowering::LowerBUILD_VECTOR(SDValue Op,
- SelectionDAG &DAG) const {
- EVT VT = Op.getValueType();
-
- Op = NormalizeBuildVector(Op, DAG);
- if (VT.isInteger()) {
-
-
-
-
- BuildVectorSDNode *BVN = cast<BuildVectorSDNode>(Op.getNode());
- if (BVN->isConstant())
- if (ConstantSDNode *Const = BVN->getConstantSplatNode()) {
- unsigned BitSize = VT.getVectorElementType().getSizeInBits();
- APInt Val(BitSize,
- Const->getAPIntValue().zextOrTrunc(BitSize).getZExtValue());
- if (Val.isNullValue() || Val.isAllOnesValue())
- return Op;
- }
- }
- if (SDValue V = ConstantBuildVector(Op, DAG))
- return V;
-
-
-
-
-
-
-
-
-
-
-
-
- SDLoc dl(Op);
- unsigned NumElts = VT.getVectorNumElements();
- bool isOnlyLowElement = true;
- bool usesOnlyOneValue = true;
- bool usesOnlyOneConstantValue = true;
- bool isConstant = true;
- bool AllLanesExtractElt = true;
- unsigned NumConstantLanes = 0;
- unsigned NumDifferentLanes = 0;
- unsigned NumUndefLanes = 0;
- SDValue Value;
- SDValue ConstantValue;
- for (unsigned i = 0; i < NumElts; ++i) {
- SDValue V = Op.getOperand(i);
- if (V.getOpcode() != ISD::EXTRACT_VECTOR_ELT)
- AllLanesExtractElt = false;
- if (V.isUndef()) {
- ++NumUndefLanes;
- continue;
- }
- if (i > 0)
- isOnlyLowElement = false;
- if (!isa<ConstantFPSDNode>(V) && !isa<ConstantSDNode>(V))
- isConstant = false;
- if (isa<ConstantSDNode>(V) || isa<ConstantFPSDNode>(V)) {
- ++NumConstantLanes;
- if (!ConstantValue.getNode())
- ConstantValue = V;
- else if (ConstantValue != V)
- usesOnlyOneConstantValue = false;
- }
- if (!Value.getNode())
- Value = V;
- else if (V != Value) {
- usesOnlyOneValue = false;
- ++NumDifferentLanes;
- }
- }
- if (!Value.getNode()) {
- LLVM_DEBUG(
- dbgs() << "LowerBUILD_VECTOR: value undefined, creating undef node\n");
- return DAG.getUNDEF(VT);
- }
-
-
-
- if (isOnlyLowElement && !(NumElts == 1 && isa<ConstantSDNode>(Value))) {
- LLVM_DEBUG(dbgs() << "LowerBUILD_VECTOR: only low element used, creating 1 "
- "SCALAR_TO_VECTOR node\n");
- return DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, VT, Value);
- }
- if (AllLanesExtractElt) {
- SDNode *Vector = nullptr;
- bool Even = false;
- bool Odd = false;
-
-
- for (unsigned i = 0; i < NumElts; ++i) {
- SDValue V = Op.getOperand(i);
- const SDNode *N = V.getNode();
- if (!isa<ConstantSDNode>(N->getOperand(1)))
- break;
- SDValue N0 = N->getOperand(0);
-
- if (!Vector) {
- Vector = N0.getNode();
-
-
- if (VT.getVectorElementType() !=
- N0.getValueType().getVectorElementType())
- break;
- } else if (Vector != N0.getNode()) {
- Odd = false;
- Even = false;
- break;
- }
-
-
- uint64_t Val = N->getConstantOperandVal(1);
- if (Val == 2 * i) {
- Even = true;
- continue;
- }
- if (Val - 1 == 2 * i) {
- Odd = true;
- continue;
- }
-
- Odd = false;
- Even = false;
- break;
- }
- if (Even || Odd) {
- SDValue LHS =
- DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, VT, SDValue(Vector, 0),
- DAG.getConstant(0, dl, MVT::i64));
- SDValue RHS =
- DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, VT, SDValue(Vector, 0),
- DAG.getConstant(NumElts, dl, MVT::i64));
- if (Even && !Odd)
- return DAG.getNode(AArch64ISD::UZP1, dl, DAG.getVTList(VT, VT), LHS,
- RHS);
- if (Odd && !Even)
- return DAG.getNode(AArch64ISD::UZP2, dl, DAG.getVTList(VT, VT), LHS,
- RHS);
- }
- }
-
-
- if (usesOnlyOneValue) {
- if (!isConstant) {
- if (Value.getOpcode() != ISD::EXTRACT_VECTOR_ELT ||
- Value.getValueType() != VT) {
- LLVM_DEBUG(
- dbgs() << "LowerBUILD_VECTOR: use DUP for non-constant splats\n");
- return DAG.getNode(AArch64ISD::DUP, dl, VT, Value);
- }
-
- SDValue Lane = Value.getOperand(1);
- Value = Value.getOperand(0);
- if (Value.getValueSizeInBits() == 64) {
- LLVM_DEBUG(
- dbgs() << "LowerBUILD_VECTOR: DUPLANE works on 128-bit vectors, "
- "widening it\n");
- Value = WidenVector(Value, DAG);
- }
- unsigned Opcode = getDUPLANEOp(VT.getVectorElementType());
- return DAG.getNode(Opcode, dl, VT, Value, Lane);
- }
- if (VT.getVectorElementType().isFloatingPoint()) {
- SmallVector<SDValue, 8> Ops;
- EVT EltTy = VT.getVectorElementType();
- assert ((EltTy == MVT::f16 || EltTy == MVT::bf16 || EltTy == MVT::f32 ||
- EltTy == MVT::f64) && "Unsupported floating-point vector type");
- LLVM_DEBUG(
- dbgs() << "LowerBUILD_VECTOR: float constant splats, creating int "
- "BITCASTS, and try again\n");
- MVT NewType = MVT::getIntegerVT(EltTy.getSizeInBits());
- for (unsigned i = 0; i < NumElts; ++i)
- Ops.push_back(DAG.getNode(ISD::BITCAST, dl, NewType, Op.getOperand(i)));
- EVT VecVT = EVT::getVectorVT(*DAG.getContext(), NewType, NumElts);
- SDValue Val = DAG.getBuildVector(VecVT, dl, Ops);
- LLVM_DEBUG(dbgs() << "LowerBUILD_VECTOR: trying to lower new vector: ";
- Val.dump(););
- Val = LowerBUILD_VECTOR(Val, DAG);
- if (Val.getNode())
- return DAG.getNode(ISD::BITCAST, dl, VT, Val);
- }
- }
-
-
-
-
- bool PreferDUPAndInsert =
- !isConstant && NumDifferentLanes >= 1 &&
- NumDifferentLanes < ((NumElts - NumUndefLanes) / 2) &&
- NumDifferentLanes >= NumConstantLanes;
-
-
-
-
- if (!PreferDUPAndInsert && NumConstantLanes > 0 && usesOnlyOneConstantValue) {
-
- SDValue Vec = DAG.getSplatBuildVector(VT, dl, ConstantValue),
- Val = ConstantBuildVector(Vec, DAG);
- if (!Val) {
-
- Val = DAG.getNode(AArch64ISD::DUP, dl, VT, ConstantValue);
- DAG.ReplaceAllUsesWith(Vec.getNode(), &Val);
- }
-
- for (unsigned i = 0; i < NumElts; ++i) {
- SDValue V = Op.getOperand(i);
- SDValue LaneIdx = DAG.getConstant(i, dl, MVT::i64);
- if (!isa<ConstantSDNode>(V) && !isa<ConstantFPSDNode>(V))
-
-
- Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, VT, Val, V, LaneIdx);
- }
- return Val;
- }
-
- if (isConstant) {
- LLVM_DEBUG(
- dbgs() << "LowerBUILD_VECTOR: all elements are constant, use default "
- "expansion\n");
- return SDValue();
- }
-
- if (NumElts >= 4) {
- if (SDValue shuffle = ReconstructShuffle(Op, DAG))
- return shuffle;
- }
- if (PreferDUPAndInsert) {
-
- SmallVector<SDValue, 8> Ops;
- for (unsigned I = 0; I < NumElts; ++I)
- Ops.push_back(Value);
- SDValue NewVector = LowerBUILD_VECTOR(DAG.getBuildVector(VT, dl, Ops), DAG);
-
- for (unsigned I = 0; I < NumElts; ++I)
- if (Op.getOperand(I) != Value)
- NewVector =
- DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, VT, NewVector,
- Op.getOperand(I), DAG.getConstant(I, dl, MVT::i64));
- return NewVector;
- }
-
-
-
-
-
-
- if (!isConstant && !usesOnlyOneValue) {
- LLVM_DEBUG(
- dbgs() << "LowerBUILD_VECTOR: alternatives failed, creating sequence "
- "of INSERT_VECTOR_ELT\n");
- SDValue Vec = DAG.getUNDEF(VT);
- SDValue Op0 = Op.getOperand(0);
- unsigned i = 0;
-
-
-
-
-
-
-
-
-
-
- if (!Op0.isUndef()) {
- LLVM_DEBUG(dbgs() << "Creating node for op0, it is not undefined:\n");
- Vec = DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, VT, Op0);
- ++i;
- }
- LLVM_DEBUG(if (i < NumElts) dbgs()
- << "Creating nodes for the other vector elements:\n";);
- for (; i < NumElts; ++i) {
- SDValue V = Op.getOperand(i);
- if (V.isUndef())
- continue;
- SDValue LaneIdx = DAG.getConstant(i, dl, MVT::i64);
- Vec = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, VT, Vec, V, LaneIdx);
- }
- return Vec;
- }
- LLVM_DEBUG(
- dbgs() << "LowerBUILD_VECTOR: use default expansion, failed to find "
- "better alternative\n");
- return SDValue();
- }
- SDValue AArch64TargetLowering::LowerCONCAT_VECTORS(SDValue Op,
- SelectionDAG &DAG) const {
- assert(Op.getValueType().isScalableVector() &&
- isTypeLegal(Op.getValueType()) &&
- "Expected legal scalable vector type!");
- if (isTypeLegal(Op.getOperand(0).getValueType()) && Op.getNumOperands() == 2)
- return Op;
- return SDValue();
- }
- SDValue AArch64TargetLowering::LowerINSERT_VECTOR_ELT(SDValue Op,
- SelectionDAG &DAG) const {
- assert(Op.getOpcode() == ISD::INSERT_VECTOR_ELT && "Unknown opcode!");
-
- EVT VT = Op.getOperand(0).getValueType();
- ConstantSDNode *CI = dyn_cast<ConstantSDNode>(Op.getOperand(2));
- if (!CI || CI->getZExtValue() >= VT.getVectorNumElements())
- return SDValue();
-
- if (VT == MVT::v16i8 || VT == MVT::v8i16 || VT == MVT::v4i32 ||
- VT == MVT::v2i64 || VT == MVT::v4f32 || VT == MVT::v2f64 ||
- VT == MVT::v8f16 || VT == MVT::v8bf16)
- return Op;
- if (VT != MVT::v8i8 && VT != MVT::v4i16 && VT != MVT::v2i32 &&
- VT != MVT::v1i64 && VT != MVT::v2f32 && VT != MVT::v4f16 &&
- VT != MVT::v4bf16)
- return SDValue();
-
-
- SDLoc DL(Op);
- SDValue WideVec = WidenVector(Op.getOperand(0), DAG);
- EVT WideTy = WideVec.getValueType();
- SDValue Node = DAG.getNode(ISD::INSERT_VECTOR_ELT, DL, WideTy, WideVec,
- Op.getOperand(1), Op.getOperand(2));
-
- return NarrowVector(Node, DAG);
- }
- SDValue
- AArch64TargetLowering::LowerEXTRACT_VECTOR_ELT(SDValue Op,
- SelectionDAG &DAG) const {
- assert(Op.getOpcode() == ISD::EXTRACT_VECTOR_ELT && "Unknown opcode!");
-
- EVT VT = Op.getOperand(0).getValueType();
- ConstantSDNode *CI = dyn_cast<ConstantSDNode>(Op.getOperand(1));
- if (!CI || CI->getZExtValue() >= VT.getVectorNumElements())
- return SDValue();
-
- if (VT == MVT::v16i8 || VT == MVT::v8i16 || VT == MVT::v4i32 ||
- VT == MVT::v2i64 || VT == MVT::v4f32 || VT == MVT::v2f64 ||
- VT == MVT::v8f16 || VT == MVT::v8bf16)
- return Op;
- if (VT != MVT::v8i8 && VT != MVT::v4i16 && VT != MVT::v2i32 &&
- VT != MVT::v1i64 && VT != MVT::v2f32 && VT != MVT::v4f16 &&
- VT != MVT::v4bf16)
- return SDValue();
-
-
- SDLoc DL(Op);
- SDValue WideVec = WidenVector(Op.getOperand(0), DAG);
- EVT WideTy = WideVec.getValueType();
- EVT ExtrTy = WideTy.getVectorElementType();
- if (ExtrTy == MVT::i16 || ExtrTy == MVT::i8)
- ExtrTy = MVT::i32;
-
- return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, ExtrTy, WideVec,
- Op.getOperand(1));
- }
- SDValue AArch64TargetLowering::LowerEXTRACT_SUBVECTOR(SDValue Op,
- SelectionDAG &DAG) const {
- assert(Op.getValueType().isFixedLengthVector() &&
- "Only cases that extract a fixed length vector are supported!");
- EVT InVT = Op.getOperand(0).getValueType();
- unsigned Idx = cast<ConstantSDNode>(Op.getOperand(1))->getZExtValue();
- unsigned Size = Op.getValueSizeInBits();
- if (InVT.isScalableVector()) {
-
- if (Idx == 0 && isPackedVectorType(InVT, DAG))
- return Op;
- return SDValue();
- }
-
- if (Idx == 0 && InVT.getSizeInBits() <= 128)
- return Op;
-
-
- if (Size == 64 && Idx * InVT.getScalarSizeInBits() == 64 &&
- InVT.getSizeInBits() == 128)
- return Op;
- return SDValue();
- }
- SDValue AArch64TargetLowering::LowerINSERT_SUBVECTOR(SDValue Op,
- SelectionDAG &DAG) const {
- assert(Op.getValueType().isScalableVector() &&
- "Only expect to lower inserts into scalable vectors!");
- EVT InVT = Op.getOperand(1).getValueType();
- unsigned Idx = cast<ConstantSDNode>(Op.getOperand(2))->getZExtValue();
- if (InVT.isScalableVector()) {
- SDLoc DL(Op);
- EVT VT = Op.getValueType();
- if (!isTypeLegal(VT) || !VT.isInteger())
- return SDValue();
- SDValue Vec0 = Op.getOperand(0);
- SDValue Vec1 = Op.getOperand(1);
-
- if (VT.getVectorElementCount() != (InVT.getVectorElementCount() * 2))
- return SDValue();
-
- EVT WideVT = InVT.widenIntegerVectorElementType(*(DAG.getContext()));
- SDValue ExtVec = DAG.getNode(ISD::ANY_EXTEND, DL, WideVT, Vec1);
- if (Idx == 0) {
- SDValue HiVec0 = DAG.getNode(AArch64ISD::UUNPKHI, DL, WideVT, Vec0);
- return DAG.getNode(AArch64ISD::UZP1, DL, VT, ExtVec, HiVec0);
- } else if (Idx == InVT.getVectorMinNumElements()) {
- SDValue LoVec0 = DAG.getNode(AArch64ISD::UUNPKLO, DL, WideVT, Vec0);
- return DAG.getNode(AArch64ISD::UZP1, DL, VT, LoVec0, ExtVec);
- }
- return SDValue();
- }
-
- if (Idx == 0 && isPackedVectorType(InVT, DAG) && Op.getOperand(0).isUndef())
- return Op;
- return SDValue();
- }
- SDValue AArch64TargetLowering::LowerDIV(SDValue Op, SelectionDAG &DAG) const {
- EVT VT = Op.getValueType();
- if (useSVEForFixedLengthVectorVT(VT, true))
- return LowerFixedLengthVectorIntDivideToSVE(Op, DAG);
- assert(VT.isScalableVector() && "Expected a scalable vector.");
- bool Signed = Op.getOpcode() == ISD::SDIV;
- unsigned PredOpcode = Signed ? AArch64ISD::SDIV_PRED : AArch64ISD::UDIV_PRED;
- if (VT == MVT::nxv4i32 || VT == MVT::nxv2i64)
- return LowerToPredicatedOp(Op, DAG, PredOpcode);
-
-
- EVT WidenedVT;
- if (VT == MVT::nxv16i8)
- WidenedVT = MVT::nxv8i16;
- else if (VT == MVT::nxv8i16)
- WidenedVT = MVT::nxv4i32;
- else
- llvm_unreachable("Unexpected Custom DIV operation");
- SDLoc dl(Op);
- unsigned UnpkLo = Signed ? AArch64ISD::SUNPKLO : AArch64ISD::UUNPKLO;
- unsigned UnpkHi = Signed ? AArch64ISD::SUNPKHI : AArch64ISD::UUNPKHI;
- SDValue Op0Lo = DAG.getNode(UnpkLo, dl, WidenedVT, Op.getOperand(0));
- SDValue Op1Lo = DAG.getNode(UnpkLo, dl, WidenedVT, Op.getOperand(1));
- SDValue Op0Hi = DAG.getNode(UnpkHi, dl, WidenedVT, Op.getOperand(0));
- SDValue Op1Hi = DAG.getNode(UnpkHi, dl, WidenedVT, Op.getOperand(1));
- SDValue ResultLo = DAG.getNode(Op.getOpcode(), dl, WidenedVT, Op0Lo, Op1Lo);
- SDValue ResultHi = DAG.getNode(Op.getOpcode(), dl, WidenedVT, Op0Hi, Op1Hi);
- return DAG.getNode(AArch64ISD::UZP1, dl, VT, ResultLo, ResultHi);
- }
- bool AArch64TargetLowering::isShuffleMaskLegal(ArrayRef<int> M, EVT VT) const {
-
- if (useSVEForFixedLengthVectorVT(VT))
- return false;
- if (VT.getVectorNumElements() == 4 &&
- (VT.is128BitVector() || VT.is64BitVector())) {
- unsigned PFIndexes[4];
- for (unsigned i = 0; i != 4; ++i) {
- if (M[i] < 0)
- PFIndexes[i] = 8;
- else
- PFIndexes[i] = M[i];
- }
-
- unsigned PFTableIndex = PFIndexes[0] * 9 * 9 * 9 + PFIndexes[1] * 9 * 9 +
- PFIndexes[2] * 9 + PFIndexes[3];
- unsigned PFEntry = PerfectShuffleTable[PFTableIndex];
- unsigned Cost = (PFEntry >> 30);
- if (Cost <= 4)
- return true;
- }
- bool DummyBool;
- int DummyInt;
- unsigned DummyUnsigned;
- return (ShuffleVectorSDNode::isSplatMask(&M[0], VT) || isREVMask(M, VT, 64) ||
- isREVMask(M, VT, 32) || isREVMask(M, VT, 16) ||
- isEXTMask(M, VT, DummyBool, DummyUnsigned) ||
-
- isTRNMask(M, VT, DummyUnsigned) || isUZPMask(M, VT, DummyUnsigned) ||
- isZIPMask(M, VT, DummyUnsigned) ||
- isTRN_v_undef_Mask(M, VT, DummyUnsigned) ||
- isUZP_v_undef_Mask(M, VT, DummyUnsigned) ||
- isZIP_v_undef_Mask(M, VT, DummyUnsigned) ||
- isINSMask(M, VT.getVectorNumElements(), DummyBool, DummyInt) ||
- isConcatMask(M, VT, VT.getSizeInBits() == 128));
- }
- static bool getVShiftImm(SDValue Op, unsigned ElementBits, int64_t &Cnt) {
-
- while (Op.getOpcode() == ISD::BITCAST)
- Op = Op.getOperand(0);
- BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(Op.getNode());
- APInt SplatBits, SplatUndef;
- unsigned SplatBitSize;
- bool HasAnyUndefs;
- if (!BVN || !BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize,
- HasAnyUndefs, ElementBits) ||
- SplatBitSize > ElementBits)
- return false;
- Cnt = SplatBits.getSExtValue();
- return true;
- }
- static bool isVShiftLImm(SDValue Op, EVT VT, bool isLong, int64_t &Cnt) {
- assert(VT.isVector() && "vector shift count is not a vector type");
- int64_t ElementBits = VT.getScalarSizeInBits();
- if (!getVShiftImm(Op, ElementBits, Cnt))
- return false;
- return (Cnt >= 0 && (isLong ? Cnt - 1 : Cnt) < ElementBits);
- }
- static bool isVShiftRImm(SDValue Op, EVT VT, bool isNarrow, int64_t &Cnt) {
- assert(VT.isVector() && "vector shift count is not a vector type");
- int64_t ElementBits = VT.getScalarSizeInBits();
- if (!getVShiftImm(Op, ElementBits, Cnt))
- return false;
- return (Cnt >= 1 && Cnt <= (isNarrow ? ElementBits / 2 : ElementBits));
- }
- SDValue AArch64TargetLowering::LowerTRUNCATE(SDValue Op,
- SelectionDAG &DAG) const {
- EVT VT = Op.getValueType();
- if (VT.getScalarType() == MVT::i1) {
-
- SDLoc dl(Op);
- EVT OpVT = Op.getOperand(0).getValueType();
- SDValue Zero = DAG.getConstant(0, dl, OpVT);
- SDValue One = DAG.getConstant(1, dl, OpVT);
- SDValue And = DAG.getNode(ISD::AND, dl, OpVT, Op.getOperand(0), One);
- return DAG.getSetCC(dl, VT, And, Zero, ISD::SETNE);
- }
- if (!VT.isVector() || VT.isScalableVector())
- return SDValue();
- if (useSVEForFixedLengthVectorVT(Op.getOperand(0).getValueType()))
- return LowerFixedLengthVectorTruncateToSVE(Op, DAG);
- return SDValue();
- }
- SDValue AArch64TargetLowering::LowerVectorSRA_SRL_SHL(SDValue Op,
- SelectionDAG &DAG) const {
- EVT VT = Op.getValueType();
- SDLoc DL(Op);
- int64_t Cnt;
- if (!Op.getOperand(1).getValueType().isVector())
- return Op;
- unsigned EltSize = VT.getScalarSizeInBits();
- switch (Op.getOpcode()) {
- default:
- llvm_unreachable("unexpected shift opcode");
- case ISD::SHL:
- if (VT.isScalableVector() || useSVEForFixedLengthVectorVT(VT))
- return LowerToPredicatedOp(Op, DAG, AArch64ISD::SHL_PRED);
- if (isVShiftLImm(Op.getOperand(1), VT, false, Cnt) && Cnt < EltSize)
- return DAG.getNode(AArch64ISD::VSHL, DL, VT, Op.getOperand(0),
- DAG.getConstant(Cnt, DL, MVT::i32));
- return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, DL, VT,
- DAG.getConstant(Intrinsic::aarch64_neon_ushl, DL,
- MVT::i32),
- Op.getOperand(0), Op.getOperand(1));
- case ISD::SRA:
- case ISD::SRL:
- if (VT.isScalableVector() || useSVEForFixedLengthVectorVT(VT)) {
- unsigned Opc = Op.getOpcode() == ISD::SRA ? AArch64ISD::SRA_PRED
- : AArch64ISD::SRL_PRED;
- return LowerToPredicatedOp(Op, DAG, Opc);
- }
-
- if (isVShiftRImm(Op.getOperand(1), VT, false, Cnt) && Cnt < EltSize) {
- unsigned Opc =
- (Op.getOpcode() == ISD::SRA) ? AArch64ISD::VASHR : AArch64ISD::VLSHR;
- return DAG.getNode(Opc, DL, VT, Op.getOperand(0),
- DAG.getConstant(Cnt, DL, MVT::i32));
- }
-
-
-
- unsigned Opc = (Op.getOpcode() == ISD::SRA) ? Intrinsic::aarch64_neon_sshl
- : Intrinsic::aarch64_neon_ushl;
-
- SDValue NegShift = DAG.getNode(AArch64ISD::NEG, DL, VT, Op.getOperand(1));
- SDValue NegShiftLeft =
- DAG.getNode(ISD::INTRINSIC_WO_CHAIN, DL, VT,
- DAG.getConstant(Opc, DL, MVT::i32), Op.getOperand(0),
- NegShift);
- return NegShiftLeft;
- }
- return SDValue();
- }
- static SDValue EmitVectorComparison(SDValue LHS, SDValue RHS,
- AArch64CC::CondCode CC, bool NoNans, EVT VT,
- const SDLoc &dl, SelectionDAG &DAG) {
- EVT SrcVT = LHS.getValueType();
- assert(VT.getSizeInBits() == SrcVT.getSizeInBits() &&
- "function only supposed to emit natural comparisons");
- BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(RHS.getNode());
- APInt CnstBits(VT.getSizeInBits(), 0);
- APInt UndefBits(VT.getSizeInBits(), 0);
- bool IsCnst = BVN && resolveBuildVector(BVN, CnstBits, UndefBits);
- bool IsZero = IsCnst && (CnstBits == 0);
- if (SrcVT.getVectorElementType().isFloatingPoint()) {
- switch (CC) {
- default:
- return SDValue();
- case AArch64CC::NE: {
- SDValue Fcmeq;
- if (IsZero)
- Fcmeq = DAG.getNode(AArch64ISD::FCMEQz, dl, VT, LHS);
- else
- Fcmeq = DAG.getNode(AArch64ISD::FCMEQ, dl, VT, LHS, RHS);
- return DAG.getNOT(dl, Fcmeq, VT);
- }
- case AArch64CC::EQ:
- if (IsZero)
- return DAG.getNode(AArch64ISD::FCMEQz, dl, VT, LHS);
- return DAG.getNode(AArch64ISD::FCMEQ, dl, VT, LHS, RHS);
- case AArch64CC::GE:
- if (IsZero)
- return DAG.getNode(AArch64ISD::FCMGEz, dl, VT, LHS);
- return DAG.getNode(AArch64ISD::FCMGE, dl, VT, LHS, RHS);
- case AArch64CC::GT:
- if (IsZero)
- return DAG.getNode(AArch64ISD::FCMGTz, dl, VT, LHS);
- return DAG.getNode(AArch64ISD::FCMGT, dl, VT, LHS, RHS);
- case AArch64CC::LS:
- if (IsZero)
- return DAG.getNode(AArch64ISD::FCMLEz, dl, VT, LHS);
- return DAG.getNode(AArch64ISD::FCMGE, dl, VT, RHS, LHS);
- case AArch64CC::LT:
- if (!NoNans)
- return SDValue();
-
- LLVM_FALLTHROUGH;
- case AArch64CC::MI:
- if (IsZero)
- return DAG.getNode(AArch64ISD::FCMLTz, dl, VT, LHS);
- return DAG.getNode(AArch64ISD::FCMGT, dl, VT, RHS, LHS);
- }
- }
- switch (CC) {
- default:
- return SDValue();
- case AArch64CC::NE: {
- SDValue Cmeq;
- if (IsZero)
- Cmeq = DAG.getNode(AArch64ISD::CMEQz, dl, VT, LHS);
- else
- Cmeq = DAG.getNode(AArch64ISD::CMEQ, dl, VT, LHS, RHS);
- return DAG.getNOT(dl, Cmeq, VT);
- }
- case AArch64CC::EQ:
- if (IsZero)
- return DAG.getNode(AArch64ISD::CMEQz, dl, VT, LHS);
- return DAG.getNode(AArch64ISD::CMEQ, dl, VT, LHS, RHS);
- case AArch64CC::GE:
- if (IsZero)
- return DAG.getNode(AArch64ISD::CMGEz, dl, VT, LHS);
- return DAG.getNode(AArch64ISD::CMGE, dl, VT, LHS, RHS);
- case AArch64CC::GT:
- if (IsZero)
- return DAG.getNode(AArch64ISD::CMGTz, dl, VT, LHS);
- return DAG.getNode(AArch64ISD::CMGT, dl, VT, LHS, RHS);
- case AArch64CC::LE:
- if (IsZero)
- return DAG.getNode(AArch64ISD::CMLEz, dl, VT, LHS);
- return DAG.getNode(AArch64ISD::CMGE, dl, VT, RHS, LHS);
- case AArch64CC::LS:
- return DAG.getNode(AArch64ISD::CMHS, dl, VT, RHS, LHS);
- case AArch64CC::LO:
- return DAG.getNode(AArch64ISD::CMHI, dl, VT, RHS, LHS);
- case AArch64CC::LT:
- if (IsZero)
- return DAG.getNode(AArch64ISD::CMLTz, dl, VT, LHS);
- return DAG.getNode(AArch64ISD::CMGT, dl, VT, RHS, LHS);
- case AArch64CC::HI:
- return DAG.getNode(AArch64ISD::CMHI, dl, VT, LHS, RHS);
- case AArch64CC::HS:
- return DAG.getNode(AArch64ISD::CMHS, dl, VT, LHS, RHS);
- }
- }
- SDValue AArch64TargetLowering::LowerVSETCC(SDValue Op,
- SelectionDAG &DAG) const {
- if (Op.getValueType().isScalableVector()) {
- if (Op.getOperand(0).getValueType().isFloatingPoint())
- return Op;
- return LowerToPredicatedOp(Op, DAG, AArch64ISD::SETCC_MERGE_ZERO);
- }
- if (useSVEForFixedLengthVectorVT(Op.getOperand(0).getValueType()))
- return LowerFixedLengthVectorSetccToSVE(Op, DAG);
- ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(2))->get();
- SDValue LHS = Op.getOperand(0);
- SDValue RHS = Op.getOperand(1);
- EVT CmpVT = LHS.getValueType().changeVectorElementTypeToInteger();
- SDLoc dl(Op);
- if (LHS.getValueType().getVectorElementType().isInteger()) {
- assert(LHS.getValueType() == RHS.getValueType());
- AArch64CC::CondCode AArch64CC = changeIntCCToAArch64CC(CC);
- SDValue Cmp =
- EmitVectorComparison(LHS, RHS, AArch64CC, false, CmpVT, dl, DAG);
- return DAG.getSExtOrTrunc(Cmp, dl, Op.getValueType());
- }
- const bool FullFP16 =
- static_cast<const AArch64Subtarget &>(DAG.getSubtarget()).hasFullFP16();
-
-
- if (!FullFP16 && LHS.getValueType().getVectorElementType() == MVT::f16) {
- if (LHS.getValueType().getVectorNumElements() == 4) {
- LHS = DAG.getNode(ISD::FP_EXTEND, dl, MVT::v4f32, LHS);
- RHS = DAG.getNode(ISD::FP_EXTEND, dl, MVT::v4f32, RHS);
- SDValue NewSetcc = DAG.getSetCC(dl, MVT::v4i16, LHS, RHS, CC);
- DAG.ReplaceAllUsesWith(Op, NewSetcc);
- CmpVT = MVT::v4i32;
- } else
- return SDValue();
- }
- assert((!FullFP16 && LHS.getValueType().getVectorElementType() != MVT::f16) ||
- LHS.getValueType().getVectorElementType() != MVT::f128);
-
-
- AArch64CC::CondCode CC1, CC2;
- bool ShouldInvert;
- changeVectorFPCCToAArch64CC(CC, CC1, CC2, ShouldInvert);
- bool NoNaNs = getTargetMachine().Options.NoNaNsFPMath;
- SDValue Cmp =
- EmitVectorComparison(LHS, RHS, CC1, NoNaNs, CmpVT, dl, DAG);
- if (!Cmp.getNode())
- return SDValue();
- if (CC2 != AArch64CC::AL) {
- SDValue Cmp2 =
- EmitVectorComparison(LHS, RHS, CC2, NoNaNs, CmpVT, dl, DAG);
- if (!Cmp2.getNode())
- return SDValue();
- Cmp = DAG.getNode(ISD::OR, dl, CmpVT, Cmp, Cmp2);
- }
- Cmp = DAG.getSExtOrTrunc(Cmp, dl, Op.getValueType());
- if (ShouldInvert)
- Cmp = DAG.getNOT(dl, Cmp, Cmp.getValueType());
- return Cmp;
- }
- static SDValue getReductionSDNode(unsigned Op, SDLoc DL, SDValue ScalarOp,
- SelectionDAG &DAG) {
- SDValue VecOp = ScalarOp.getOperand(0);
- auto Rdx = DAG.getNode(Op, DL, VecOp.getSimpleValueType(), VecOp);
- return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, ScalarOp.getValueType(), Rdx,
- DAG.getConstant(0, DL, MVT::i64));
- }
- SDValue AArch64TargetLowering::LowerVECREDUCE(SDValue Op,
- SelectionDAG &DAG) const {
- SDValue Src = Op.getOperand(0);
-
- EVT SrcVT = Src.getValueType();
- bool OverrideNEON = Op.getOpcode() == ISD::VECREDUCE_AND ||
- Op.getOpcode() == ISD::VECREDUCE_OR ||
- Op.getOpcode() == ISD::VECREDUCE_XOR ||
- Op.getOpcode() == ISD::VECREDUCE_FADD ||
- (Op.getOpcode() != ISD::VECREDUCE_ADD &&
- SrcVT.getVectorElementType() == MVT::i64);
- if (SrcVT.isScalableVector() ||
- useSVEForFixedLengthVectorVT(SrcVT, OverrideNEON)) {
- if (SrcVT.getVectorElementType() == MVT::i1)
- return LowerPredReductionToSVE(Op, DAG);
- switch (Op.getOpcode()) {
- case ISD::VECREDUCE_ADD:
- return LowerReductionToSVE(AArch64ISD::UADDV_PRED, Op, DAG);
- case ISD::VECREDUCE_AND:
- return LowerReductionToSVE(AArch64ISD::ANDV_PRED, Op, DAG);
- case ISD::VECREDUCE_OR:
- return LowerReductionToSVE(AArch64ISD::ORV_PRED, Op, DAG);
- case ISD::VECREDUCE_SMAX:
- return LowerReductionToSVE(AArch64ISD::SMAXV_PRED, Op, DAG);
- case ISD::VECREDUCE_SMIN:
- return LowerReductionToSVE(AArch64ISD::SMINV_PRED, Op, DAG);
- case ISD::VECREDUCE_UMAX:
- return LowerReductionToSVE(AArch64ISD::UMAXV_PRED, Op, DAG);
- case ISD::VECREDUCE_UMIN:
- return LowerReductionToSVE(AArch64ISD::UMINV_PRED, Op, DAG);
- case ISD::VECREDUCE_XOR:
- return LowerReductionToSVE(AArch64ISD::EORV_PRED, Op, DAG);
- case ISD::VECREDUCE_FADD:
- return LowerReductionToSVE(AArch64ISD::FADDV_PRED, Op, DAG);
- case ISD::VECREDUCE_FMAX:
- return LowerReductionToSVE(AArch64ISD::FMAXNMV_PRED, Op, DAG);
- case ISD::VECREDUCE_FMIN:
- return LowerReductionToSVE(AArch64ISD::FMINNMV_PRED, Op, DAG);
- default:
- llvm_unreachable("Unhandled fixed length reduction");
- }
- }
-
- SDLoc dl(Op);
- switch (Op.getOpcode()) {
- case ISD::VECREDUCE_ADD:
- return getReductionSDNode(AArch64ISD::UADDV, dl, Op, DAG);
- case ISD::VECREDUCE_SMAX:
- return getReductionSDNode(AArch64ISD::SMAXV, dl, Op, DAG);
- case ISD::VECREDUCE_SMIN:
- return getReductionSDNode(AArch64ISD::SMINV, dl, Op, DAG);
- case ISD::VECREDUCE_UMAX:
- return getReductionSDNode(AArch64ISD::UMAXV, dl, Op, DAG);
- case ISD::VECREDUCE_UMIN:
- return getReductionSDNode(AArch64ISD::UMINV, dl, Op, DAG);
- case ISD::VECREDUCE_FMAX: {
- return DAG.getNode(
- ISD::INTRINSIC_WO_CHAIN, dl, Op.getValueType(),
- DAG.getConstant(Intrinsic::aarch64_neon_fmaxnmv, dl, MVT::i32),
- Src);
- }
- case ISD::VECREDUCE_FMIN: {
- return DAG.getNode(
- ISD::INTRINSIC_WO_CHAIN, dl, Op.getValueType(),
- DAG.getConstant(Intrinsic::aarch64_neon_fminnmv, dl, MVT::i32),
- Src);
- }
- default:
- llvm_unreachable("Unhandled reduction");
- }
- }
- SDValue AArch64TargetLowering::LowerATOMIC_LOAD_SUB(SDValue Op,
- SelectionDAG &DAG) const {
- auto &Subtarget = static_cast<const AArch64Subtarget &>(DAG.getSubtarget());
- if (!Subtarget.hasLSE() && !Subtarget.outlineAtomics())
- return SDValue();
-
- SDLoc dl(Op);
- MVT VT = Op.getSimpleValueType();
- SDValue RHS = Op.getOperand(2);
- AtomicSDNode *AN = cast<AtomicSDNode>(Op.getNode());
- RHS = DAG.getNode(ISD::SUB, dl, VT, DAG.getConstant(0, dl, VT), RHS);
- return DAG.getAtomic(ISD::ATOMIC_LOAD_ADD, dl, AN->getMemoryVT(),
- Op.getOperand(0), Op.getOperand(1), RHS,
- AN->getMemOperand());
- }
- SDValue AArch64TargetLowering::LowerATOMIC_LOAD_AND(SDValue Op,
- SelectionDAG &DAG) const {
- auto &Subtarget = static_cast<const AArch64Subtarget &>(DAG.getSubtarget());
- if (!Subtarget.hasLSE() && !Subtarget.outlineAtomics())
- return SDValue();
-
- SDLoc dl(Op);
- MVT VT = Op.getSimpleValueType();
- SDValue RHS = Op.getOperand(2);
- AtomicSDNode *AN = cast<AtomicSDNode>(Op.getNode());
- RHS = DAG.getNode(ISD::XOR, dl, VT, DAG.getConstant(-1ULL, dl, VT), RHS);
- return DAG.getAtomic(ISD::ATOMIC_LOAD_CLR, dl, AN->getMemoryVT(),
- Op.getOperand(0), Op.getOperand(1), RHS,
- AN->getMemOperand());
- }
- SDValue AArch64TargetLowering::LowerWindowsDYNAMIC_STACKALLOC(
- SDValue Op, SDValue Chain, SDValue &Size, SelectionDAG &DAG) const {
- SDLoc dl(Op);
- EVT PtrVT = getPointerTy(DAG.getDataLayout());
- SDValue Callee = DAG.getTargetExternalSymbol("__chkstk", PtrVT, 0);
- const AArch64RegisterInfo *TRI = Subtarget->getRegisterInfo();
- const uint32_t *Mask = TRI->getWindowsStackProbePreservedMask();
- if (Subtarget->hasCustomCallingConv())
- TRI->UpdateCustomCallPreservedMask(DAG.getMachineFunction(), &Mask);
- Size = DAG.getNode(ISD::SRL, dl, MVT::i64, Size,
- DAG.getConstant(4, dl, MVT::i64));
- Chain = DAG.getCopyToReg(Chain, dl, AArch64::X15, Size, SDValue());
- Chain =
- DAG.getNode(AArch64ISD::CALL, dl, DAG.getVTList(MVT::Other, MVT::Glue),
- Chain, Callee, DAG.getRegister(AArch64::X15, MVT::i64),
- DAG.getRegisterMask(Mask), Chain.getValue(1));
-
-
-
-
- Size = DAG.getNode(ISD::SHL, dl, MVT::i64, Size,
- DAG.getConstant(4, dl, MVT::i64));
- return Chain;
- }
- SDValue
- AArch64TargetLowering::LowerDYNAMIC_STACKALLOC(SDValue Op,
- SelectionDAG &DAG) const {
- assert(Subtarget->isTargetWindows() &&
- "Only Windows alloca probing supported");
- SDLoc dl(Op);
-
- SDNode *Node = Op.getNode();
- SDValue Chain = Op.getOperand(0);
- SDValue Size = Op.getOperand(1);
- MaybeAlign Align =
- cast<ConstantSDNode>(Op.getOperand(2))->getMaybeAlignValue();
- EVT VT = Node->getValueType(0);
- if (DAG.getMachineFunction().getFunction().hasFnAttribute(
- "no-stack-arg-probe")) {
- SDValue SP = DAG.getCopyFromReg(Chain, dl, AArch64::SP, MVT::i64);
- Chain = SP.getValue(1);
- SP = DAG.getNode(ISD::SUB, dl, MVT::i64, SP, Size);
- if (Align)
- SP = DAG.getNode(ISD::AND, dl, VT, SP.getValue(0),
- DAG.getConstant(-(uint64_t)Align->value(), dl, VT));
- Chain = DAG.getCopyToReg(Chain, dl, AArch64::SP, SP);
- SDValue Ops[2] = {SP, Chain};
- return DAG.getMergeValues(Ops, dl);
- }
- Chain = DAG.getCALLSEQ_START(Chain, 0, 0, dl);
- Chain = LowerWindowsDYNAMIC_STACKALLOC(Op, Chain, Size, DAG);
- SDValue SP = DAG.getCopyFromReg(Chain, dl, AArch64::SP, MVT::i64);
- Chain = SP.getValue(1);
- SP = DAG.getNode(ISD::SUB, dl, MVT::i64, SP, Size);
- if (Align)
- SP = DAG.getNode(ISD::AND, dl, VT, SP.getValue(0),
- DAG.getConstant(-(uint64_t)Align->value(), dl, VT));
- Chain = DAG.getCopyToReg(Chain, dl, AArch64::SP, SP);
- Chain = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(0, dl, true),
- DAG.getIntPtrConstant(0, dl, true), SDValue(), dl);
- SDValue Ops[2] = {SP, Chain};
- return DAG.getMergeValues(Ops, dl);
- }
- SDValue AArch64TargetLowering::LowerVSCALE(SDValue Op,
- SelectionDAG &DAG) const {
- EVT VT = Op.getValueType();
- assert(VT != MVT::i64 && "Expected illegal VSCALE node");
- SDLoc DL(Op);
- APInt MulImm = cast<ConstantSDNode>(Op.getOperand(0))->getAPIntValue();
- return DAG.getZExtOrTrunc(DAG.getVScale(DL, MVT::i64, MulImm.sextOrSelf(64)),
- DL, VT);
- }
- template <unsigned NumVecs>
- static bool
- setInfoSVEStN(const AArch64TargetLowering &TLI, const DataLayout &DL,
- AArch64TargetLowering::IntrinsicInfo &Info, const CallInst &CI) {
- Info.opc = ISD::INTRINSIC_VOID;
-
- const EVT VT = TLI.getMemValueType(DL, CI.getArgOperand(0)->getType());
- ElementCount EC = VT.getVectorElementCount();
- #ifndef NDEBUG
-
- for (unsigned I = 0; I < NumVecs; ++I)
- assert(VT == TLI.getMemValueType(DL, CI.getArgOperand(I)->getType()) &&
- "Invalid type.");
- #endif
-
- Info.memVT = EVT::getVectorVT(CI.getType()->getContext(), VT.getScalarType(),
- EC * NumVecs);
- Info.ptrVal = CI.getArgOperand(CI.getNumArgOperands() - 1);
- Info.offset = 0;
- Info.align.reset();
- Info.flags = MachineMemOperand::MOStore;
- return true;
- }
- bool AArch64TargetLowering::getTgtMemIntrinsic(IntrinsicInfo &Info,
- const CallInst &I,
- MachineFunction &MF,
- unsigned Intrinsic) const {
- auto &DL = I.getModule()->getDataLayout();
- switch (Intrinsic) {
- case Intrinsic::aarch64_sve_st2:
- return setInfoSVEStN<2>(*this, DL, Info, I);
- case Intrinsic::aarch64_sve_st3:
- return setInfoSVEStN<3>(*this, DL, Info, I);
- case Intrinsic::aarch64_sve_st4:
- return setInfoSVEStN<4>(*this, DL, Info, I);
- case Intrinsic::aarch64_neon_ld2:
- case Intrinsic::aarch64_neon_ld3:
- case Intrinsic::aarch64_neon_ld4:
- case Intrinsic::aarch64_neon_ld1x2:
- case Intrinsic::aarch64_neon_ld1x3:
- case Intrinsic::aarch64_neon_ld1x4:
- case Intrinsic::aarch64_neon_ld2lane:
- case Intrinsic::aarch64_neon_ld3lane:
- case Intrinsic::aarch64_neon_ld4lane:
- case Intrinsic::aarch64_neon_ld2r:
- case Intrinsic::aarch64_neon_ld3r:
- case Intrinsic::aarch64_neon_ld4r: {
- Info.opc = ISD::INTRINSIC_W_CHAIN;
-
- uint64_t NumElts = DL.getTypeSizeInBits(I.getType()) / 64;
- Info.memVT = EVT::getVectorVT(I.getType()->getContext(), MVT::i64, NumElts);
- Info.ptrVal = I.getArgOperand(I.getNumArgOperands() - 1);
- Info.offset = 0;
- Info.align.reset();
-
- Info.flags = MachineMemOperand::MOLoad;
- return true;
- }
- case Intrinsic::aarch64_neon_st2:
- case Intrinsic::aarch64_neon_st3:
- case Intrinsic::aarch64_neon_st4:
- case Intrinsic::aarch64_neon_st1x2:
- case Intrinsic::aarch64_neon_st1x3:
- case Intrinsic::aarch64_neon_st1x4:
- case Intrinsic::aarch64_neon_st2lane:
- case Intrinsic::aarch64_neon_st3lane:
- case Intrinsic::aarch64_neon_st4lane: {
- Info.opc = ISD::INTRINSIC_VOID;
-
- unsigned NumElts = 0;
- for (unsigned ArgI = 0, ArgE = I.getNumArgOperands(); ArgI < ArgE; ++ArgI) {
- Type *ArgTy = I.getArgOperand(ArgI)->getType();
- if (!ArgTy->isVectorTy())
- break;
- NumElts += DL.getTypeSizeInBits(ArgTy) / 64;
- }
- Info.memVT = EVT::getVectorVT(I.getType()->getContext(), MVT::i64, NumElts);
- Info.ptrVal = I.getArgOperand(I.getNumArgOperands() - 1);
- Info.offset = 0;
- Info.align.reset();
-
- Info.flags = MachineMemOperand::MOStore;
- return true;
- }
- case Intrinsic::aarch64_ldaxr:
- case Intrinsic::aarch64_ldxr: {
- PointerType *PtrTy = cast<PointerType>(I.getArgOperand(0)->getType());
- Info.opc = ISD::INTRINSIC_W_CHAIN;
- Info.memVT = MVT::getVT(PtrTy->getElementType());
- Info.ptrVal = I.getArgOperand(0);
- Info.offset = 0;
- Info.align = DL.getABITypeAlign(PtrTy->getElementType());
- Info.flags = MachineMemOperand::MOLoad | MachineMemOperand::MOVolatile;
- return true;
- }
- case Intrinsic::aarch64_stlxr:
- case Intrinsic::aarch64_stxr: {
- PointerType *PtrTy = cast<PointerType>(I.getArgOperand(1)->getType());
- Info.opc = ISD::INTRINSIC_W_CHAIN;
- Info.memVT = MVT::getVT(PtrTy->getElementType());
- Info.ptrVal = I.getArgOperand(1);
- Info.offset = 0;
- Info.align = DL.getABITypeAlign(PtrTy->getElementType());
- Info.flags = MachineMemOperand::MOStore | MachineMemOperand::MOVolatile;
- return true;
- }
- case Intrinsic::aarch64_ldaxp:
- case Intrinsic::aarch64_ldxp:
- Info.opc = ISD::INTRINSIC_W_CHAIN;
- Info.memVT = MVT::i128;
- Info.ptrVal = I.getArgOperand(0);
- Info.offset = 0;
- Info.align = Align(16);
- Info.flags = MachineMemOperand::MOLoad | MachineMemOperand::MOVolatile;
- return true;
- case Intrinsic::aarch64_stlxp:
- case Intrinsic::aarch64_stxp:
- Info.opc = ISD::INTRINSIC_W_CHAIN;
- Info.memVT = MVT::i128;
- Info.ptrVal = I.getArgOperand(2);
- Info.offset = 0;
- Info.align = Align(16);
- Info.flags = MachineMemOperand::MOStore | MachineMemOperand::MOVolatile;
- return true;
- case Intrinsic::aarch64_sve_ldnt1: {
- PointerType *PtrTy = cast<PointerType>(I.getArgOperand(1)->getType());
- Info.opc = ISD::INTRINSIC_W_CHAIN;
- Info.memVT = MVT::getVT(I.getType());
- Info.ptrVal = I.getArgOperand(1);
- Info.offset = 0;
- Info.align = DL.getABITypeAlign(PtrTy->getElementType());
- Info.flags = MachineMemOperand::MOLoad;
- if (Intrinsic == Intrinsic::aarch64_sve_ldnt1)
- Info.flags |= MachineMemOperand::MONonTemporal;
- return true;
- }
- case Intrinsic::aarch64_sve_stnt1: {
- PointerType *PtrTy = cast<PointerType>(I.getArgOperand(2)->getType());
- Info.opc = ISD::INTRINSIC_W_CHAIN;
- Info.memVT = MVT::getVT(I.getOperand(0)->getType());
- Info.ptrVal = I.getArgOperand(2);
- Info.offset = 0;
- Info.align = DL.getABITypeAlign(PtrTy->getElementType());
- Info.flags = MachineMemOperand::MOStore;
- if (Intrinsic == Intrinsic::aarch64_sve_stnt1)
- Info.flags |= MachineMemOperand::MONonTemporal;
- return true;
- }
- default:
- break;
- }
- return false;
- }
- bool AArch64TargetLowering::shouldReduceLoadWidth(SDNode *Load,
- ISD::LoadExtType ExtTy,
- EVT NewVT) const {
-
- if (!TargetLoweringBase::shouldReduceLoadWidth(Load, ExtTy, NewVT))
- return false;
-
-
- if (ExtTy != ISD::NON_EXTLOAD)
- return true;
-
-
- MemSDNode *Mem = dyn_cast<MemSDNode>(Load);
- assert(Mem);
- const SDValue &Base = Mem->getBasePtr();
- if (Base.getOpcode() == ISD::ADD &&
- Base.getOperand(1).getOpcode() == ISD::SHL &&
- Base.getOperand(1).hasOneUse() &&
- Base.getOperand(1).getOperand(1).getOpcode() == ISD::Constant) {
-
-
- uint64_t ShiftAmount = Base.getOperand(1).getConstantOperandVal(1);
- uint64_t LoadBytes = Mem->getMemoryVT().getSizeInBits()/8;
- if (ShiftAmount == Log2_32(LoadBytes))
- return false;
- }
-
- return true;
- }
- bool AArch64TargetLowering::isTruncateFree(Type *Ty1, Type *Ty2) const {
- if (!Ty1->isIntegerTy() || !Ty2->isIntegerTy())
- return false;
- uint64_t NumBits1 = Ty1->getPrimitiveSizeInBits().getFixedSize();
- uint64_t NumBits2 = Ty2->getPrimitiveSizeInBits().getFixedSize();
- return NumBits1 > NumBits2;
- }
- bool AArch64TargetLowering::isTruncateFree(EVT VT1, EVT VT2) const {
- if (VT1.isVector() || VT2.isVector() || !VT1.isInteger() || !VT2.isInteger())
- return false;
- uint64_t NumBits1 = VT1.getFixedSizeInBits();
- uint64_t NumBits2 = VT2.getFixedSizeInBits();
- return NumBits1 > NumBits2;
- }
- bool AArch64TargetLowering::isProfitableToHoist(Instruction *I) const {
- if (I->getOpcode() != Instruction::FMul)
- return true;
- if (!I->hasOneUse())
- return true;
- Instruction *User = I->user_back();
- if (User &&
- !(User->getOpcode() == Instruction::FSub ||
- User->getOpcode() == Instruction::FAdd))
- return true;
- const TargetOptions &Options = getTargetMachine().Options;
- const Function *F = I->getFunction();
- const DataLayout &DL = F->getParent()->getDataLayout();
- Type *Ty = User->getOperand(0)->getType();
- return !(isFMAFasterThanFMulAndFAdd(*F, Ty) &&
- isOperationLegalOrCustom(ISD::FMA, getValueType(DL, Ty)) &&
- (Options.AllowFPOpFusion == FPOpFusion::Fast ||
- Options.UnsafeFPMath));
- }
- bool AArch64TargetLowering::isZExtFree(Type *Ty1, Type *Ty2) const {
- if (!Ty1->isIntegerTy() || !Ty2->isIntegerTy())
- return false;
- unsigned NumBits1 = Ty1->getPrimitiveSizeInBits();
- unsigned NumBits2 = Ty2->getPrimitiveSizeInBits();
- return NumBits1 == 32 && NumBits2 == 64;
- }
- bool AArch64TargetLowering::isZExtFree(EVT VT1, EVT VT2) const {
- if (VT1.isVector() || VT2.isVector() || !VT1.isInteger() || !VT2.isInteger())
- return false;
- unsigned NumBits1 = VT1.getSizeInBits();
- unsigned NumBits2 = VT2.getSizeInBits();
- return NumBits1 == 32 && NumBits2 == 64;
- }
- bool AArch64TargetLowering::isZExtFree(SDValue Val, EVT VT2) const {
- EVT VT1 = Val.getValueType();
- if (isZExtFree(VT1, VT2)) {
- return true;
- }
- if (Val.getOpcode() != ISD::LOAD)
- return false;
-
- return (VT1.isSimple() && !VT1.isVector() && VT1.isInteger() &&
- VT2.isSimple() && !VT2.isVector() && VT2.isInteger() &&
- VT1.getSizeInBits() <= 32);
- }
- bool AArch64TargetLowering::isExtFreeImpl(const Instruction *Ext) const {
- if (isa<FPExtInst>(Ext))
- return false;
-
- if (Ext->getType()->isVectorTy())
- return false;
- for (const Use &U : Ext->uses()) {
-
-
-
- const Instruction *Instr = cast<Instruction>(U.getUser());
-
- switch (Instr->getOpcode()) {
- case Instruction::Shl:
- if (!isa<ConstantInt>(Instr->getOperand(1)))
- return false;
- break;
- case Instruction::GetElementPtr: {
- gep_type_iterator GTI = gep_type_begin(Instr);
- auto &DL = Ext->getModule()->getDataLayout();
- std::advance(GTI, U.getOperandNo()-1);
- Type *IdxTy = GTI.getIndexedType();
-
-
-
-
- uint64_t ShiftAmt =
- countTrailingZeros(DL.getTypeStoreSizeInBits(IdxTy).getFixedSize()) - 3;
-
-
- if (ShiftAmt == 0 || ShiftAmt > 4)
- return false;
- break;
- }
- case Instruction::Trunc:
-
-
- if (Instr->getType() == Ext->getOperand(0)->getType())
- continue;
- LLVM_FALLTHROUGH;
- default:
- return false;
- }
-
-
- }
- return true;
- }
- static bool areExtractShuffleVectors(Value *Op1, Value *Op2) {
- auto areTypesHalfed = [](Value *FullV, Value *HalfV) {
- auto *FullTy = FullV->getType();
- auto *HalfTy = HalfV->getType();
- return FullTy->getPrimitiveSizeInBits().getFixedSize() ==
- 2 * HalfTy->getPrimitiveSizeInBits().getFixedSize();
- };
- auto extractHalf = [](Value *FullV, Value *HalfV) {
- auto *FullVT = cast<FixedVectorType>(FullV->getType());
- auto *HalfVT = cast<FixedVectorType>(HalfV->getType());
- return FullVT->getNumElements() == 2 * HalfVT->getNumElements();
- };
- ArrayRef<int> M1, M2;
- Value *S1Op1, *S2Op1;
- if (!match(Op1, m_Shuffle(m_Value(S1Op1), m_Undef(), m_Mask(M1))) ||
- !match(Op2, m_Shuffle(m_Value(S2Op1), m_Undef(), m_Mask(M2))))
- return false;
-
-
- if (!areTypesHalfed(S1Op1, Op1) || !areTypesHalfed(S2Op1, Op2) ||
- !extractHalf(S1Op1, Op1) || !extractHalf(S2Op1, Op2))
- return false;
-
-
- int M1Start = -1;
- int M2Start = -1;
- int NumElements = cast<FixedVectorType>(Op1->getType())->getNumElements() * 2;
- if (!ShuffleVectorInst::isExtractSubvectorMask(M1, NumElements, M1Start) ||
- !ShuffleVectorInst::isExtractSubvectorMask(M2, NumElements, M2Start) ||
- M1Start != M2Start || (M1Start != 0 && M2Start != (NumElements / 2)))
- return false;
- return true;
- }
- static bool areExtractExts(Value *Ext1, Value *Ext2) {
- auto areExtDoubled = [](Instruction *Ext) {
- return Ext->getType()->getScalarSizeInBits() ==
- 2 * Ext->getOperand(0)->getType()->getScalarSizeInBits();
- };
- if (!match(Ext1, m_ZExtOrSExt(m_Value())) ||
- !match(Ext2, m_ZExtOrSExt(m_Value())) ||
- !areExtDoubled(cast<Instruction>(Ext1)) ||
- !areExtDoubled(cast<Instruction>(Ext2)))
- return false;
- return true;
- }
- static bool isOperandOfVmullHighP64(Value *Op) {
- Value *VectorOperand = nullptr;
- ConstantInt *ElementIndex = nullptr;
- return match(Op, m_ExtractElt(m_Value(VectorOperand),
- m_ConstantInt(ElementIndex))) &&
- ElementIndex->getValue() == 1 &&
- isa<FixedVectorType>(VectorOperand->getType()) &&
- cast<FixedVectorType>(VectorOperand->getType())->getNumElements() == 2;
- }
- static bool areOperandsOfVmullHighP64(Value *Op1, Value *Op2) {
- return isOperandOfVmullHighP64(Op1) && isOperandOfVmullHighP64(Op2);
- }
- bool AArch64TargetLowering::shouldSinkOperands(
- Instruction *I, SmallVectorImpl<Use *> &Ops) const {
- if (!I->getType()->isVectorTy())
- return false;
- if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(I)) {
- switch (II->getIntrinsicID()) {
- case Intrinsic::aarch64_neon_umull:
- if (!areExtractShuffleVectors(II->getOperand(0), II->getOperand(1)))
- return false;
- Ops.push_back(&II->getOperandUse(0));
- Ops.push_back(&II->getOperandUse(1));
- return true;
- case Intrinsic::aarch64_neon_pmull64:
- if (!areOperandsOfVmullHighP64(II->getArgOperand(0),
- II->getArgOperand(1)))
- return false;
- Ops.push_back(&II->getArgOperandUse(0));
- Ops.push_back(&II->getArgOperandUse(1));
- return true;
- default:
- return false;
- }
- }
- switch (I->getOpcode()) {
- case Instruction::Sub:
- case Instruction::Add: {
- if (!areExtractExts(I->getOperand(0), I->getOperand(1)))
- return false;
-
-
- auto Ext1 = cast<Instruction>(I->getOperand(0));
- auto Ext2 = cast<Instruction>(I->getOperand(1));
- if (areExtractShuffleVectors(Ext1, Ext2)) {
- Ops.push_back(&Ext1->getOperandUse(0));
- Ops.push_back(&Ext2->getOperandUse(0));
- }
- Ops.push_back(&I->getOperandUse(0));
- Ops.push_back(&I->getOperandUse(1));
- return true;
- }
- case Instruction::Mul: {
- bool IsProfitable = false;
- for (auto &Op : I->operands()) {
-
- if (any_of(Ops, [&](Use *U) { return U->get() == Op; }))
- continue;
- ShuffleVectorInst *Shuffle = dyn_cast<ShuffleVectorInst>(Op);
- if (!Shuffle || !Shuffle->isZeroEltSplat())
- continue;
- Value *ShuffleOperand = Shuffle->getOperand(0);
- InsertElementInst *Insert = dyn_cast<InsertElementInst>(ShuffleOperand);
- if (!Insert)
- continue;
- Instruction *OperandInstr = dyn_cast<Instruction>(Insert->getOperand(1));
- if (!OperandInstr)
- continue;
- ConstantInt *ElementConstant =
- dyn_cast<ConstantInt>(Insert->getOperand(2));
-
- if (!ElementConstant || ElementConstant->getZExtValue() != 0)
- continue;
- unsigned Opcode = OperandInstr->getOpcode();
- if (Opcode != Instruction::SExt && Opcode != Instruction::ZExt)
- continue;
- Ops.push_back(&Shuffle->getOperandUse(0));
- Ops.push_back(&Op);
- IsProfitable = true;
- }
- return IsProfitable;
- }
- default:
- return false;
- }
- return false;
- }
- bool AArch64TargetLowering::hasPairedLoad(EVT LoadedType,
- Align &RequiredAligment) const {
- if (!LoadedType.isSimple() ||
- (!LoadedType.isInteger() && !LoadedType.isFloatingPoint()))
- return false;
-
- RequiredAligment = Align(1);
- unsigned NumBits = LoadedType.getSizeInBits();
- return NumBits == 32 || NumBits == 64;
- }
- unsigned
- AArch64TargetLowering::getNumInterleavedAccesses(VectorType *VecTy,
- const DataLayout &DL) const {
- return (DL.getTypeSizeInBits(VecTy) + 127) / 128;
- }
- MachineMemOperand::Flags
- AArch64TargetLowering::getTargetMMOFlags(const Instruction &I) const {
- if (Subtarget->getProcFamily() == AArch64Subtarget::Falkor &&
- I.getMetadata(FALKOR_STRIDED_ACCESS_MD) != nullptr)
- return MOStridedAccess;
- return MachineMemOperand::MONone;
- }
- bool AArch64TargetLowering::isLegalInterleavedAccessType(
- VectorType *VecTy, const DataLayout &DL) const {
- unsigned VecSize = DL.getTypeSizeInBits(VecTy);
- unsigned ElSize = DL.getTypeSizeInBits(VecTy->getElementType());
-
- if (cast<FixedVectorType>(VecTy)->getNumElements() < 2)
- return false;
-
- if (ElSize != 8 && ElSize != 16 && ElSize != 32 && ElSize != 64)
- return false;
-
-
- return VecSize == 64 || VecSize % 128 == 0;
- }
- bool AArch64TargetLowering::lowerInterleavedLoad(
- LoadInst *LI, ArrayRef<ShuffleVectorInst *> Shuffles,
- ArrayRef<unsigned> Indices, unsigned Factor) const {
- assert(Factor >= 2 && Factor <= getMaxSupportedInterleaveFactor() &&
- "Invalid interleave factor");
- assert(!Shuffles.empty() && "Empty shufflevector input");
- assert(Shuffles.size() == Indices.size() &&
- "Unmatched number of shufflevectors and indices");
- const DataLayout &DL = LI->getModule()->getDataLayout();
- VectorType *VTy = Shuffles[0]->getType();
-
-
-
- if (!Subtarget->hasNEON() || !isLegalInterleavedAccessType(VTy, DL))
- return false;
- unsigned NumLoads = getNumInterleavedAccesses(VTy, DL);
- auto *FVTy = cast<FixedVectorType>(VTy);
-
-
- Type *EltTy = FVTy->getElementType();
- if (EltTy->isPointerTy())
- FVTy =
- FixedVectorType::get(DL.getIntPtrType(EltTy), FVTy->getNumElements());
- IRBuilder<> Builder(LI);
-
- Value *BaseAddr = LI->getPointerOperand();
- if (NumLoads > 1) {
-
-
- FVTy = FixedVectorType::get(FVTy->getElementType(),
- FVTy->getNumElements() / NumLoads);
-
-
-
- BaseAddr = Builder.CreateBitCast(
- BaseAddr,
- FVTy->getElementType()->getPointerTo(LI->getPointerAddressSpace()));
- }
- Type *PtrTy = FVTy->getPointerTo(LI->getPointerAddressSpace());
- Type *Tys[2] = {FVTy, PtrTy};
- static const Intrinsic::ID LoadInts[3] = {Intrinsic::aarch64_neon_ld2,
- Intrinsic::aarch64_neon_ld3,
- Intrinsic::aarch64_neon_ld4};
- Function *LdNFunc =
- Intrinsic::getDeclaration(LI->getModule(), LoadInts[Factor - 2], Tys);
-
-
-
- DenseMap<ShuffleVectorInst *, SmallVector<Value *, 4>> SubVecs;
- for (unsigned LoadCount = 0; LoadCount < NumLoads; ++LoadCount) {
-
-
- if (LoadCount > 0)
- BaseAddr = Builder.CreateConstGEP1_32(FVTy->getElementType(), BaseAddr,
- FVTy->getNumElements() * Factor);
- CallInst *LdN = Builder.CreateCall(
- LdNFunc, Builder.CreateBitCast(BaseAddr, PtrTy), "ldN");
-
- for (unsigned i = 0; i < Shuffles.size(); i++) {
- ShuffleVectorInst *SVI = Shuffles[i];
- unsigned Index = Indices[i];
- Value *SubVec = Builder.CreateExtractValue(LdN, Index);
-
- if (EltTy->isPointerTy())
- SubVec = Builder.CreateIntToPtr(
- SubVec, FixedVectorType::get(SVI->getType()->getElementType(),
- FVTy->getNumElements()));
- SubVecs[SVI].push_back(SubVec);
- }
- }
-
-
-
-
- for (ShuffleVectorInst *SVI : Shuffles) {
- auto &SubVec = SubVecs[SVI];
- auto *WideVec =
- SubVec.size() > 1 ? concatenateVectors(Builder, SubVec) : SubVec[0];
- SVI->replaceAllUsesWith(WideVec);
- }
- return true;
- }
- bool AArch64TargetLowering::lowerInterleavedStore(StoreInst *SI,
- ShuffleVectorInst *SVI,
- unsigned Factor) const {
- assert(Factor >= 2 && Factor <= getMaxSupportedInterleaveFactor() &&
- "Invalid interleave factor");
- auto *VecTy = cast<FixedVectorType>(SVI->getType());
- assert(VecTy->getNumElements() % Factor == 0 && "Invalid interleaved store");
- unsigned LaneLen = VecTy->getNumElements() / Factor;
- Type *EltTy = VecTy->getElementType();
- auto *SubVecTy = FixedVectorType::get(EltTy, LaneLen);
- const DataLayout &DL = SI->getModule()->getDataLayout();
-
-
-
- if (!Subtarget->hasNEON() || !isLegalInterleavedAccessType(SubVecTy, DL))
- return false;
- unsigned NumStores = getNumInterleavedAccesses(SubVecTy, DL);
- Value *Op0 = SVI->getOperand(0);
- Value *Op1 = SVI->getOperand(1);
- IRBuilder<> Builder(SI);
-
-
- if (EltTy->isPointerTy()) {
- Type *IntTy = DL.getIntPtrType(EltTy);
- unsigned NumOpElts =
- cast<FixedVectorType>(Op0->getType())->getNumElements();
-
- auto *IntVecTy = FixedVectorType::get(IntTy, NumOpElts);
- Op0 = Builder.CreatePtrToInt(Op0, IntVecTy);
- Op1 = Builder.CreatePtrToInt(Op1, IntVecTy);
- SubVecTy = FixedVectorType::get(IntTy, LaneLen);
- }
-
- Value *BaseAddr = SI->getPointerOperand();
- if (NumStores > 1) {
-
-
- LaneLen /= NumStores;
- SubVecTy = FixedVectorType::get(SubVecTy->getElementType(), LaneLen);
-
-
-
- BaseAddr = Builder.CreateBitCast(
- BaseAddr,
- SubVecTy->getElementType()->getPointerTo(SI->getPointerAddressSpace()));
- }
- auto Mask = SVI->getShuffleMask();
- Type *PtrTy = SubVecTy->getPointerTo(SI->getPointerAddressSpace());
- Type *Tys[2] = {SubVecTy, PtrTy};
- static const Intrinsic::ID StoreInts[3] = {Intrinsic::aarch64_neon_st2,
- Intrinsic::aarch64_neon_st3,
- Intrinsic::aarch64_neon_st4};
- Function *StNFunc =
- Intrinsic::getDeclaration(SI->getModule(), StoreInts[Factor - 2], Tys);
- for (unsigned StoreCount = 0; StoreCount < NumStores; ++StoreCount) {
- SmallVector<Value *, 5> Ops;
-
- for (unsigned i = 0; i < Factor; i++) {
- unsigned IdxI = StoreCount * LaneLen * Factor + i;
- if (Mask[IdxI] >= 0) {
- Ops.push_back(Builder.CreateShuffleVector(
- Op0, Op1, createSequentialMask(Mask[IdxI], LaneLen, 0)));
- } else {
- unsigned StartMask = 0;
- for (unsigned j = 1; j < LaneLen; j++) {
- unsigned IdxJ = StoreCount * LaneLen * Factor + j;
- if (Mask[IdxJ * Factor + IdxI] >= 0) {
- StartMask = Mask[IdxJ * Factor + IdxI] - IdxJ;
- break;
- }
- }
-
-
-
-
-
- Ops.push_back(Builder.CreateShuffleVector(
- Op0, Op1, createSequentialMask(StartMask, LaneLen, 0)));
- }
- }
-
-
- if (StoreCount > 0)
- BaseAddr = Builder.CreateConstGEP1_32(SubVecTy->getElementType(),
- BaseAddr, LaneLen * Factor);
- Ops.push_back(Builder.CreateBitCast(BaseAddr, PtrTy));
- Builder.CreateCall(StNFunc, Ops);
- }
- return true;
- }
- SDValue AArch64TargetLowering::LowerSVEStructLoad(unsigned Intrinsic,
- ArrayRef<SDValue> LoadOps,
- EVT VT, SelectionDAG &DAG,
- const SDLoc &DL) const {
- assert(VT.isScalableVector() && "Can only lower scalable vectors");
- unsigned N, Opcode;
- static std::map<unsigned, std::pair<unsigned, unsigned>> IntrinsicMap = {
- {Intrinsic::aarch64_sve_ld2, {2, AArch64ISD::SVE_LD2_MERGE_ZERO}},
- {Intrinsic::aarch64_sve_ld3, {3, AArch64ISD::SVE_LD3_MERGE_ZERO}},
- {Intrinsic::aarch64_sve_ld4, {4, AArch64ISD::SVE_LD4_MERGE_ZERO}}};
- std::tie(N, Opcode) = IntrinsicMap[Intrinsic];
- assert(VT.getVectorElementCount().getKnownMinValue() % N == 0 &&
- "invalid tuple vector type!");
- EVT SplitVT =
- EVT::getVectorVT(*DAG.getContext(), VT.getVectorElementType(),
- VT.getVectorElementCount().divideCoefficientBy(N));
- assert(isTypeLegal(SplitVT));
- SmallVector<EVT, 5> VTs(N, SplitVT);
- VTs.push_back(MVT::Other);
- SDVTList NodeTys = DAG.getVTList(VTs);
- SDValue PseudoLoad = DAG.getNode(Opcode, DL, NodeTys, LoadOps);
- SmallVector<SDValue, 4> PseudoLoadOps;
- for (unsigned I = 0; I < N; ++I)
- PseudoLoadOps.push_back(SDValue(PseudoLoad.getNode(), I));
- return DAG.getNode(ISD::CONCAT_VECTORS, DL, VT, PseudoLoadOps);
- }
- EVT AArch64TargetLowering::getOptimalMemOpType(
- const MemOp &Op, const AttributeList &FuncAttributes) const {
- bool CanImplicitFloat =
- !FuncAttributes.hasFnAttribute(Attribute::NoImplicitFloat);
- bool CanUseNEON = Subtarget->hasNEON() && CanImplicitFloat;
- bool CanUseFP = Subtarget->hasFPARMv8() && CanImplicitFloat;
-
-
-
- bool IsSmallMemset = Op.isMemset() && Op.size() < 32;
- auto AlignmentIsAcceptable = [&](EVT VT, Align AlignCheck) {
- if (Op.isAligned(AlignCheck))
- return true;
- bool Fast;
- return allowsMisalignedMemoryAccesses(VT, 0, 1, MachineMemOperand::MONone,
- &Fast) &&
- Fast;
- };
- if (CanUseNEON && Op.isMemset() && !IsSmallMemset &&
- AlignmentIsAcceptable(MVT::v2i64, Align(16)))
- return MVT::v2i64;
- if (CanUseFP && !IsSmallMemset && AlignmentIsAcceptable(MVT::f128, Align(16)))
- return MVT::f128;
- if (Op.size() >= 8 && AlignmentIsAcceptable(MVT::i64, Align(8)))
- return MVT::i64;
- if (Op.size() >= 4 && AlignmentIsAcceptable(MVT::i32, Align(4)))
- return MVT::i32;
- return MVT::Other;
- }
- LLT AArch64TargetLowering::getOptimalMemOpLLT(
- const MemOp &Op, const AttributeList &FuncAttributes) const {
- bool CanImplicitFloat =
- !FuncAttributes.hasFnAttribute(Attribute::NoImplicitFloat);
- bool CanUseNEON = Subtarget->hasNEON() && CanImplicitFloat;
- bool CanUseFP = Subtarget->hasFPARMv8() && CanImplicitFloat;
-
-
-
- bool IsSmallMemset = Op.isMemset() && Op.size() < 32;
- auto AlignmentIsAcceptable = [&](EVT VT, Align AlignCheck) {
- if (Op.isAligned(AlignCheck))
- return true;
- bool Fast;
- return allowsMisalignedMemoryAccesses(VT, 0, 1, MachineMemOperand::MONone,
- &Fast) &&
- Fast;
- };
- if (CanUseNEON && Op.isMemset() && !IsSmallMemset &&
- AlignmentIsAcceptable(MVT::v2i64, Align(16)))
- return LLT::vector(2, 64);
- if (CanUseFP && !IsSmallMemset && AlignmentIsAcceptable(MVT::f128, Align(16)))
- return LLT::scalar(128);
- if (Op.size() >= 8 && AlignmentIsAcceptable(MVT::i64, Align(8)))
- return LLT::scalar(64);
- if (Op.size() >= 4 && AlignmentIsAcceptable(MVT::i32, Align(4)))
- return LLT::scalar(32);
- return LLT();
- }
- bool AArch64TargetLowering::isLegalAddImmediate(int64_t Immed) const {
- if (Immed == std::numeric_limits<int64_t>::min()) {
- LLVM_DEBUG(dbgs() << "Illegal add imm " << Immed
- << ": avoid UB for INT64_MIN\n");
- return false;
- }
-
- Immed = std::abs(Immed);
- bool IsLegal = ((Immed >> 12) == 0 ||
- ((Immed & 0xfff) == 0 && Immed >> 24 == 0));
- LLVM_DEBUG(dbgs() << "Is " << Immed
- << " legal add imm: " << (IsLegal ? "yes" : "no") << "\n");
- return IsLegal;
- }
- bool AArch64TargetLowering::isLegalICmpImmediate(int64_t Immed) const {
- return isLegalAddImmediate(Immed);
- }
- bool AArch64TargetLowering::isLegalAddressingMode(const DataLayout &DL,
- const AddrMode &AM, Type *Ty,
- unsigned AS, Instruction *I) const {
-
-
-
-
-
-
-
- if (AM.BaseGV)
- return false;
-
- if (AM.HasBaseReg && AM.BaseOffs && AM.Scale)
- return false;
-
- if (isa<ScalableVectorType>(Ty))
- return AM.HasBaseReg && !AM.BaseOffs && !AM.Scale;
-
-
- uint64_t NumBytes = 0;
- if (Ty->isSized()) {
- uint64_t NumBits = DL.getTypeSizeInBits(Ty);
- NumBytes = NumBits / 8;
- if (!isPowerOf2_64(NumBits))
- NumBytes = 0;
- }
- if (!AM.Scale) {
- int64_t Offset = AM.BaseOffs;
-
- if (isInt<9>(Offset))
- return true;
-
- unsigned shift = Log2_64(NumBytes);
- if (NumBytes && Offset > 0 && (Offset / NumBytes) <= (1LL << 12) - 1 &&
-
- (Offset >> shift) << shift == Offset)
- return true;
- return false;
- }
-
- return AM.Scale == 1 || (AM.Scale > 0 && (uint64_t)AM.Scale == NumBytes);
- }
- bool AArch64TargetLowering::shouldConsiderGEPOffsetSplit() const {
-
- return true;
- }
- int AArch64TargetLowering::getScalingFactorCost(const DataLayout &DL,
- const AddrMode &AM, Type *Ty,
- unsigned AS) const {
-
-
-
-
-
-
-
- if (isLegalAddressingMode(DL, AM, Ty, AS))
-
-
- return AM.Scale != 0 && AM.Scale != 1;
- return -1;
- }
- bool AArch64TargetLowering::isFMAFasterThanFMulAndFAdd(
- const MachineFunction &MF, EVT VT) const {
- VT = VT.getScalarType();
- if (!VT.isSimple())
- return false;
- switch (VT.getSimpleVT().SimpleTy) {
- case MVT::f32:
- case MVT::f64:
- return true;
- default:
- break;
- }
- return false;
- }
- bool AArch64TargetLowering::isFMAFasterThanFMulAndFAdd(const Function &F,
- Type *Ty) const {
- switch (Ty->getScalarType()->getTypeID()) {
- case Type::FloatTyID:
- case Type::DoubleTyID:
- return true;
- default:
- return false;
- }
- }
- const MCPhysReg *
- AArch64TargetLowering::getScratchRegisters(CallingConv::ID) const {
-
-
-
- static const MCPhysReg ScratchRegs[] = {
- AArch64::X16, AArch64::X17, AArch64::LR, 0
- };
- return ScratchRegs;
- }
- bool
- AArch64TargetLowering::isDesirableToCommuteWithShift(const SDNode *N,
- CombineLevel Level) const {
- N = N->getOperand(0).getNode();
- EVT VT = N->getValueType(0);
-
-
- if (N->getOpcode() == ISD::AND && (VT == MVT::i32 || VT == MVT::i64) &&
- isa<ConstantSDNode>(N->getOperand(1))) {
- uint64_t TruncMask = N->getConstantOperandVal(1);
- if (isMask_64(TruncMask) &&
- N->getOperand(0).getOpcode() == ISD::SRL &&
- isa<ConstantSDNode>(N->getOperand(0)->getOperand(1)))
- return false;
- }
- return true;
- }
- bool AArch64TargetLowering::shouldConvertConstantLoadToIntImm(const APInt &Imm,
- Type *Ty) const {
- assert(Ty->isIntegerTy());
- unsigned BitSize = Ty->getPrimitiveSizeInBits();
- if (BitSize == 0)
- return false;
- int64_t Val = Imm.getSExtValue();
- if (Val == 0 || AArch64_AM::isLogicalImmediate(Val, BitSize))
- return true;
- if ((int64_t)Val < 0)
- Val = ~Val;
- if (BitSize == 32)
- Val &= (1LL << 32) - 1;
- unsigned LZ = countLeadingZeros((uint64_t)Val);
- unsigned Shift = (63 - LZ) / 16;
-
- return Shift < 3;
- }
- bool AArch64TargetLowering::isExtractSubvectorCheap(EVT ResVT, EVT SrcVT,
- unsigned Index) const {
- if (!isOperationLegalOrCustom(ISD::EXTRACT_SUBVECTOR, ResVT))
- return false;
- return (Index == 0 || Index == ResVT.getVectorNumElements());
- }
- static SDValue foldVectorXorShiftIntoCmp(SDNode *N, SelectionDAG &DAG,
- const AArch64Subtarget *Subtarget) {
- EVT VT = N->getValueType(0);
- if (!Subtarget->hasNEON() || !VT.isVector())
- return SDValue();
-
-
- SDValue Shift = N->getOperand(0);
- SDValue Ones = N->getOperand(1);
- if (Shift.getOpcode() != AArch64ISD::VASHR || !Shift.hasOneUse() ||
- !ISD::isBuildVectorAllOnes(Ones.getNode()))
- return SDValue();
-
- auto *ShiftAmt = dyn_cast<ConstantSDNode>(Shift.getOperand(1));
- EVT ShiftEltTy = Shift.getValueType().getVectorElementType();
- if (!ShiftAmt || ShiftAmt->getZExtValue() != ShiftEltTy.getSizeInBits() - 1)
- return SDValue();
- return DAG.getNode(AArch64ISD::CMGEz, SDLoc(N), VT, Shift.getOperand(0));
- }
- static SDValue performVecReduceAddCombine(SDNode *N, SelectionDAG &DAG,
- const AArch64Subtarget *ST) {
- SDValue Op0 = N->getOperand(0);
- if (!ST->hasDotProd() || N->getValueType(0) != MVT::i32)
- return SDValue();
- if (Op0.getValueType().getVectorElementType() != MVT::i32)
- return SDValue();
- unsigned ExtOpcode = Op0.getOpcode();
- if (ExtOpcode != ISD::ZERO_EXTEND && ExtOpcode != ISD::SIGN_EXTEND)
- return SDValue();
- EVT Op0VT = Op0.getOperand(0).getValueType();
- if (Op0VT != MVT::v16i8)
- return SDValue();
- SDLoc DL(Op0);
- SDValue Ones = DAG.getConstant(1, DL, Op0VT);
- SDValue Zeros = DAG.getConstant(0, DL, MVT::v4i32);
- auto DotIntrisic = (ExtOpcode == ISD::ZERO_EXTEND)
- ? Intrinsic::aarch64_neon_udot
- : Intrinsic::aarch64_neon_sdot;
- SDValue Dot = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, DL, Zeros.getValueType(),
- DAG.getConstant(DotIntrisic, DL, MVT::i32), Zeros,
- Ones, Op0.getOperand(0));
- return DAG.getNode(ISD::VECREDUCE_ADD, DL, N->getValueType(0), Dot);
- }
- static SDValue performABSCombine(SDNode *N, SelectionDAG &DAG,
- TargetLowering::DAGCombinerInfo &DCI,
- const AArch64Subtarget *Subtarget) {
- SDValue AbsOp1 = N->getOperand(0);
- SDValue Op0, Op1;
- if (AbsOp1.getOpcode() != ISD::SUB)
- return SDValue();
- Op0 = AbsOp1.getOperand(0);
- Op1 = AbsOp1.getOperand(1);
- unsigned Opc0 = Op0.getOpcode();
-
- if (Opc0 != Op1.getOpcode() ||
- (Opc0 != ISD::ZERO_EXTEND && Opc0 != ISD::SIGN_EXTEND))
- return SDValue();
- EVT VectorT1 = Op0.getOperand(0).getValueType();
- EVT VectorT2 = Op1.getOperand(0).getValueType();
-
- uint64_t Size = VectorT1.getFixedSizeInBits();
- if (VectorT1 != VectorT2 || (Size != 64 && Size != 128))
- return SDValue();
-
- EVT VT1 = VectorT1.getVectorElementType();
- if (VT1 != MVT::i8 && VT1 != MVT::i16 && VT1 != MVT::i32)
- return SDValue();
- Op0 = Op0.getOperand(0);
- Op1 = Op1.getOperand(0);
- unsigned ABDOpcode =
- (Opc0 == ISD::SIGN_EXTEND) ? AArch64ISD::SABD : AArch64ISD::UABD;
- SDValue ABD =
- DAG.getNode(ABDOpcode, SDLoc(N), Op0->getValueType(0), Op0, Op1);
- return DAG.getNode(ISD::ZERO_EXTEND, SDLoc(N), N->getValueType(0), ABD);
- }
- static SDValue performXorCombine(SDNode *N, SelectionDAG &DAG,
- TargetLowering::DAGCombinerInfo &DCI,
- const AArch64Subtarget *Subtarget) {
- if (DCI.isBeforeLegalizeOps())
- return SDValue();
- return foldVectorXorShiftIntoCmp(N, DAG, Subtarget);
- }
- SDValue
- AArch64TargetLowering::BuildSDIVPow2(SDNode *N, const APInt &Divisor,
- SelectionDAG &DAG,
- SmallVectorImpl<SDNode *> &Created) const {
- AttributeList Attr = DAG.getMachineFunction().getFunction().getAttributes();
- if (isIntDivCheap(N->getValueType(0), Attr))
- return SDValue(N,0);
-
- EVT VT = N->getValueType(0);
- if ((VT != MVT::i32 && VT != MVT::i64) ||
- !(Divisor.isPowerOf2() || (-Divisor).isPowerOf2()))
- return SDValue();
- SDLoc DL(N);
- SDValue N0 = N->getOperand(0);
- unsigned Lg2 = Divisor.countTrailingZeros();
- SDValue Zero = DAG.getConstant(0, DL, VT);
- SDValue Pow2MinusOne = DAG.getConstant((1ULL << Lg2) - 1, DL, VT);
-
- SDValue CCVal;
- SDValue Cmp = getAArch64Cmp(N0, Zero, ISD::SETLT, CCVal, DAG, DL);
- SDValue Add = DAG.getNode(ISD::ADD, DL, VT, N0, Pow2MinusOne);
- SDValue CSel = DAG.getNode(AArch64ISD::CSEL, DL, VT, Add, N0, CCVal, Cmp);
- Created.push_back(Cmp.getNode());
- Created.push_back(Add.getNode());
- Created.push_back(CSel.getNode());
-
- SDValue SRA =
- DAG.getNode(ISD::SRA, DL, VT, CSel, DAG.getConstant(Lg2, DL, MVT::i64));
-
-
- if (Divisor.isNonNegative())
- return SRA;
- Created.push_back(SRA.getNode());
- return DAG.getNode(ISD::SUB, DL, VT, DAG.getConstant(0, DL, VT), SRA);
- }
- static bool IsSVECntIntrinsic(SDValue S) {
- switch(getIntrinsicID(S.getNode())) {
- default:
- break;
- case Intrinsic::aarch64_sve_cntb:
- case Intrinsic::aarch64_sve_cnth:
- case Intrinsic::aarch64_sve_cntw:
- case Intrinsic::aarch64_sve_cntd:
- return true;
- }
- return false;
- }
- static EVT calculatePreExtendType(SDValue Extend, SelectionDAG &DAG) {
- switch (Extend.getOpcode()) {
- case ISD::SIGN_EXTEND:
- case ISD::ZERO_EXTEND:
- return Extend.getOperand(0).getValueType();
- case ISD::AssertSext:
- case ISD::AssertZext:
- case ISD::SIGN_EXTEND_INREG: {
- VTSDNode *TypeNode = dyn_cast<VTSDNode>(Extend.getOperand(1));
- if (!TypeNode)
- return MVT::Other;
- return TypeNode->getVT();
- }
- case ISD::AND: {
- ConstantSDNode *Constant =
- dyn_cast<ConstantSDNode>(Extend.getOperand(1).getNode());
- if (!Constant)
- return MVT::Other;
- uint32_t Mask = Constant->getZExtValue();
- if (Mask == UCHAR_MAX)
- return MVT::i8;
- else if (Mask == USHRT_MAX)
- return MVT::i16;
- else if (Mask == UINT_MAX)
- return MVT::i32;
- return MVT::Other;
- }
- default:
- return MVT::Other;
- }
- llvm_unreachable("Code path unhandled in calculatePreExtendType!");
- }
- static SDValue performCommonVectorExtendCombine(SDValue VectorShuffle,
- SelectionDAG &DAG) {
- ShuffleVectorSDNode *ShuffleNode =
- dyn_cast<ShuffleVectorSDNode>(VectorShuffle.getNode());
- if (!ShuffleNode)
- return SDValue();
-
- if (!ShuffleNode->isSplat() || ShuffleNode->getSplatIndex() != 0)
- return SDValue();
- SDValue InsertVectorElt = VectorShuffle.getOperand(0);
- if (InsertVectorElt.getOpcode() != ISD::INSERT_VECTOR_ELT)
- return SDValue();
- SDValue InsertLane = InsertVectorElt.getOperand(2);
- ConstantSDNode *Constant = dyn_cast<ConstantSDNode>(InsertLane.getNode());
-
- if (!Constant || Constant->getZExtValue() != 0)
- return SDValue();
- SDValue Extend = InsertVectorElt.getOperand(1);
- unsigned ExtendOpcode = Extend.getOpcode();
- bool IsSExt = ExtendOpcode == ISD::SIGN_EXTEND ||
- ExtendOpcode == ISD::SIGN_EXTEND_INREG ||
- ExtendOpcode == ISD::AssertSext;
- if (!IsSExt && ExtendOpcode != ISD::ZERO_EXTEND &&
- ExtendOpcode != ISD::AssertZext && ExtendOpcode != ISD::AND)
- return SDValue();
- EVT TargetType = VectorShuffle.getValueType();
- EVT PreExtendType = calculatePreExtendType(Extend, DAG);
- if ((TargetType != MVT::v8i16 && TargetType != MVT::v4i32 &&
- TargetType != MVT::v2i64) ||
- (PreExtendType == MVT::Other))
- return SDValue();
-
- if (PreExtendType != MVT::i8 && PreExtendType != MVT::i16 &&
- PreExtendType != MVT::i32)
- return SDValue();
- EVT PreExtendVT = TargetType.changeVectorElementType(PreExtendType);
- if (PreExtendVT.getVectorElementCount() != TargetType.getVectorElementCount())
- return SDValue();
- if (TargetType.getScalarSizeInBits() != PreExtendVT.getScalarSizeInBits() * 2)
- return SDValue();
- SDLoc DL(VectorShuffle);
- SDValue InsertVectorNode = DAG.getNode(
- InsertVectorElt.getOpcode(), DL, PreExtendVT, DAG.getUNDEF(PreExtendVT),
- DAG.getAnyExtOrTrunc(Extend.getOperand(0), DL, PreExtendType),
- DAG.getConstant(0, DL, MVT::i64));
- std::vector<int> ShuffleMask(TargetType.getVectorElementCount().getValue());
- SDValue VectorShuffleNode =
- DAG.getVectorShuffle(PreExtendVT, DL, InsertVectorNode,
- DAG.getUNDEF(PreExtendVT), ShuffleMask);
- SDValue ExtendNode = DAG.getNode(IsSExt ? ISD::SIGN_EXTEND : ISD::ZERO_EXTEND,
- DL, TargetType, VectorShuffleNode);
- return ExtendNode;
- }
- static SDValue performMulVectorExtendCombine(SDNode *Mul, SelectionDAG &DAG) {
-
- if (!Mul->getValueType(0).isVector())
- return SDValue();
- SDValue Op0 = performCommonVectorExtendCombine(Mul->getOperand(0), DAG);
- SDValue Op1 = performCommonVectorExtendCombine(Mul->getOperand(1), DAG);
-
- if (!Op0 && !Op1)
- return SDValue();
- SDLoc DL(Mul);
- return DAG.getNode(Mul->getOpcode(), DL, Mul->getValueType(0),
- Op0 ? Op0 : Mul->getOperand(0),
- Op1 ? Op1 : Mul->getOperand(1));
- }
- static SDValue performMulCombine(SDNode *N, SelectionDAG &DAG,
- TargetLowering::DAGCombinerInfo &DCI,
- const AArch64Subtarget *Subtarget) {
- if (SDValue Ext = performMulVectorExtendCombine(N, DAG))
- return Ext;
- if (DCI.isBeforeLegalizeOps())
- return SDValue();
-
- if (!isa<ConstantSDNode>(N->getOperand(1)))
- return SDValue();
- SDValue N0 = N->getOperand(0);
- ConstantSDNode *C = cast<ConstantSDNode>(N->getOperand(1));
- const APInt &ConstValue = C->getAPIntValue();
-
-
- if (IsSVECntIntrinsic(N0) ||
- (N0->getOpcode() == ISD::TRUNCATE &&
- (IsSVECntIntrinsic(N0->getOperand(0)))))
- if (ConstValue.sge(1) && ConstValue.sle(16))
- return SDValue();
-
-
-
-
-
-
-
-
-
-
-
-
- unsigned TrailingZeroes = ConstValue.countTrailingZeros();
- if (TrailingZeroes) {
-
-
- if (N0->hasOneUse() && (isSignExtended(N0.getNode(), DAG) ||
- isZeroExtended(N0.getNode(), DAG)))
- return SDValue();
-
-
- if (N->hasOneUse() && (N->use_begin()->getOpcode() == ISD::ADD ||
- N->use_begin()->getOpcode() == ISD::SUB))
- return SDValue();
- }
-
-
- APInt ShiftedConstValue = ConstValue.ashr(TrailingZeroes);
- unsigned ShiftAmt, AddSubOpc;
-
- bool ShiftValUseIsN0 = true;
-
- bool NegateResult = false;
- if (ConstValue.isNonNegative()) {
-
-
-
- APInt SCVMinus1 = ShiftedConstValue - 1;
- APInt CVPlus1 = ConstValue + 1;
- if (SCVMinus1.isPowerOf2()) {
- ShiftAmt = SCVMinus1.logBase2();
- AddSubOpc = ISD::ADD;
- } else if (CVPlus1.isPowerOf2()) {
- ShiftAmt = CVPlus1.logBase2();
- AddSubOpc = ISD::SUB;
- } else
- return SDValue();
- } else {
-
-
- APInt CVNegPlus1 = -ConstValue + 1;
- APInt CVNegMinus1 = -ConstValue - 1;
- if (CVNegPlus1.isPowerOf2()) {
- ShiftAmt = CVNegPlus1.logBase2();
- AddSubOpc = ISD::SUB;
- ShiftValUseIsN0 = false;
- } else if (CVNegMinus1.isPowerOf2()) {
- ShiftAmt = CVNegMinus1.logBase2();
- AddSubOpc = ISD::ADD;
- NegateResult = true;
- } else
- return SDValue();
- }
- SDLoc DL(N);
- EVT VT = N->getValueType(0);
- SDValue ShiftedVal = DAG.getNode(ISD::SHL, DL, VT, N0,
- DAG.getConstant(ShiftAmt, DL, MVT::i64));
- SDValue AddSubN0 = ShiftValUseIsN0 ? ShiftedVal : N0;
- SDValue AddSubN1 = ShiftValUseIsN0 ? N0 : ShiftedVal;
- SDValue Res = DAG.getNode(AddSubOpc, DL, VT, AddSubN0, AddSubN1);
- assert(!(NegateResult && TrailingZeroes) &&
- "NegateResult and TrailingZeroes cannot both be true for now.");
-
- if (NegateResult)
- return DAG.getNode(ISD::SUB, DL, VT, DAG.getConstant(0, DL, VT), Res);
-
- if (TrailingZeroes)
- return DAG.getNode(ISD::SHL, DL, VT, Res,
- DAG.getConstant(TrailingZeroes, DL, MVT::i64));
- return Res;
- }
- static SDValue performVectorCompareAndMaskUnaryOpCombine(SDNode *N,
- SelectionDAG &DAG) {
-
-
-
-
-
-
-
-
-
-
- EVT VT = N->getValueType(0);
- if (!VT.isVector() || N->getOperand(0)->getOpcode() != ISD::AND ||
- N->getOperand(0)->getOperand(0)->getOpcode() != ISD::SETCC ||
- VT.getSizeInBits() != N->getOperand(0)->getValueType(0).getSizeInBits())
- return SDValue();
-
-
-
-
- if (BuildVectorSDNode *BV =
- dyn_cast<BuildVectorSDNode>(N->getOperand(0)->getOperand(1))) {
-
- if (!BV->isConstant())
- return SDValue();
-
- SDLoc DL(N);
- EVT IntVT = BV->getValueType(0);
-
-
- SDValue SourceConst = DAG.getNode(N->getOpcode(), DL, VT, SDValue(BV, 0));
-
- SDValue MaskConst = DAG.getNode(ISD::BITCAST, DL, IntVT, SourceConst);
- SDValue NewAnd = DAG.getNode(ISD::AND, DL, IntVT,
- N->getOperand(0)->getOperand(0), MaskConst);
- SDValue Res = DAG.getNode(ISD::BITCAST, DL, VT, NewAnd);
- return Res;
- }
- return SDValue();
- }
- static SDValue performIntToFpCombine(SDNode *N, SelectionDAG &DAG,
- const AArch64Subtarget *Subtarget) {
-
-
- if (SDValue Res = performVectorCompareAndMaskUnaryOpCombine(N, DAG))
- return Res;
- EVT VT = N->getValueType(0);
- if (VT != MVT::f32 && VT != MVT::f64)
- return SDValue();
-
- if (VT.getSizeInBits() != N->getOperand(0).getValueSizeInBits())
- return SDValue();
-
-
-
- SDValue N0 = N->getOperand(0);
- if (Subtarget->hasNEON() && ISD::isNormalLoad(N0.getNode()) && N0.hasOneUse() &&
-
- !cast<LoadSDNode>(N0)->isVolatile()) {
- LoadSDNode *LN0 = cast<LoadSDNode>(N0);
- SDValue Load = DAG.getLoad(VT, SDLoc(N), LN0->getChain(), LN0->getBasePtr(),
- LN0->getPointerInfo(), LN0->getAlignment(),
- LN0->getMemOperand()->getFlags());
-
-
- DAG.ReplaceAllUsesOfValueWith(SDValue(LN0, 1), Load.getValue(1));
- unsigned Opcode =
- (N->getOpcode() == ISD::SINT_TO_FP) ? AArch64ISD::SITOF : AArch64ISD::UITOF;
- return DAG.getNode(Opcode, SDLoc(N), VT, Load);
- }
- return SDValue();
- }
- static SDValue performFpToIntCombine(SDNode *N, SelectionDAG &DAG,
- TargetLowering::DAGCombinerInfo &DCI,
- const AArch64Subtarget *Subtarget) {
- if (!Subtarget->hasNEON())
- return SDValue();
- if (!N->getValueType(0).isSimple())
- return SDValue();
- SDValue Op = N->getOperand(0);
- if (!Op.getValueType().isVector() || !Op.getValueType().isSimple() ||
- Op.getOpcode() != ISD::FMUL)
- return SDValue();
- SDValue ConstVec = Op->getOperand(1);
- if (!isa<BuildVectorSDNode>(ConstVec))
- return SDValue();
- MVT FloatTy = Op.getSimpleValueType().getVectorElementType();
- uint32_t FloatBits = FloatTy.getSizeInBits();
- if (FloatBits != 32 && FloatBits != 64)
- return SDValue();
- MVT IntTy = N->getSimpleValueType(0).getVectorElementType();
- uint32_t IntBits = IntTy.getSizeInBits();
- if (IntBits != 16 && IntBits != 32 && IntBits != 64)
- return SDValue();
-
- if (IntBits > FloatBits)
- return SDValue();
- BitVector UndefElements;
- BuildVectorSDNode *BV = cast<BuildVectorSDNode>(ConstVec);
- int32_t Bits = IntBits == 64 ? 64 : 32;
- int32_t C = BV->getConstantFPSplatPow2ToLog2Int(&UndefElements, Bits + 1);
- if (C == -1 || C == 0 || C > Bits)
- return SDValue();
- MVT ResTy;
- unsigned NumLanes = Op.getValueType().getVectorNumElements();
- switch (NumLanes) {
- default:
- return SDValue();
- case 2:
- ResTy = FloatBits == 32 ? MVT::v2i32 : MVT::v2i64;
- break;
- case 4:
- ResTy = FloatBits == 32 ? MVT::v4i32 : MVT::v4i64;
- break;
- }
- if (ResTy == MVT::v4i64 && DCI.isBeforeLegalizeOps())
- return SDValue();
- assert((ResTy != MVT::v4i64 || DCI.isBeforeLegalizeOps()) &&
- "Illegal vector type after legalization");
- SDLoc DL(N);
- bool IsSigned = N->getOpcode() == ISD::FP_TO_SINT;
- unsigned IntrinsicOpcode = IsSigned ? Intrinsic::aarch64_neon_vcvtfp2fxs
- : Intrinsic::aarch64_neon_vcvtfp2fxu;
- SDValue FixConv =
- DAG.getNode(ISD::INTRINSIC_WO_CHAIN, DL, ResTy,
- DAG.getConstant(IntrinsicOpcode, DL, MVT::i32),
- Op->getOperand(0), DAG.getConstant(C, DL, MVT::i32));
-
- if (IntBits < FloatBits)
- FixConv = DAG.getNode(ISD::TRUNCATE, DL, N->getValueType(0), FixConv);
- return FixConv;
- }
- static SDValue performFDivCombine(SDNode *N, SelectionDAG &DAG,
- TargetLowering::DAGCombinerInfo &DCI,
- const AArch64Subtarget *Subtarget) {
- if (!Subtarget->hasNEON())
- return SDValue();
- SDValue Op = N->getOperand(0);
- unsigned Opc = Op->getOpcode();
- if (!Op.getValueType().isVector() || !Op.getValueType().isSimple() ||
- !Op.getOperand(0).getValueType().isSimple() ||
- (Opc != ISD::SINT_TO_FP && Opc != ISD::UINT_TO_FP))
- return SDValue();
- SDValue ConstVec = N->getOperand(1);
- if (!isa<BuildVectorSDNode>(ConstVec))
- return SDValue();
- MVT IntTy = Op.getOperand(0).getSimpleValueType().getVectorElementType();
- int32_t IntBits = IntTy.getSizeInBits();
- if (IntBits != 16 && IntBits != 32 && IntBits != 64)
- return SDValue();
- MVT FloatTy = N->getSimpleValueType(0).getVectorElementType();
- int32_t FloatBits = FloatTy.getSizeInBits();
- if (FloatBits != 32 && FloatBits != 64)
- return SDValue();
-
- if (IntBits > FloatBits)
- return SDValue();
- BitVector UndefElements;
- BuildVectorSDNode *BV = cast<BuildVectorSDNode>(ConstVec);
- int32_t C = BV->getConstantFPSplatPow2ToLog2Int(&UndefElements, FloatBits + 1);
- if (C == -1 || C == 0 || C > FloatBits)
- return SDValue();
- MVT ResTy;
- unsigned NumLanes = Op.getValueType().getVectorNumElements();
- switch (NumLanes) {
- default:
- return SDValue();
- case 2:
- ResTy = FloatBits == 32 ? MVT::v2i32 : MVT::v2i64;
- break;
- case 4:
- ResTy = FloatBits == 32 ? MVT::v4i32 : MVT::v4i64;
- break;
- }
- if (ResTy == MVT::v4i64 && DCI.isBeforeLegalizeOps())
- return SDValue();
- SDLoc DL(N);
- SDValue ConvInput = Op.getOperand(0);
- bool IsSigned = Opc == ISD::SINT_TO_FP;
- if (IntBits < FloatBits)
- ConvInput = DAG.getNode(IsSigned ? ISD::SIGN_EXTEND : ISD::ZERO_EXTEND, DL,
- ResTy, ConvInput);
- unsigned IntrinsicOpcode = IsSigned ? Intrinsic::aarch64_neon_vcvtfxs2fp
- : Intrinsic::aarch64_neon_vcvtfxu2fp;
- return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, DL, Op.getValueType(),
- DAG.getConstant(IntrinsicOpcode, DL, MVT::i32), ConvInput,
- DAG.getConstant(C, DL, MVT::i32));
- }
- static bool findEXTRHalf(SDValue N, SDValue &Src, uint32_t &ShiftAmount,
- bool &FromHi) {
- if (N.getOpcode() == ISD::SHL)
- FromHi = false;
- else if (N.getOpcode() == ISD::SRL)
- FromHi = true;
- else
- return false;
- if (!isa<ConstantSDNode>(N.getOperand(1)))
- return false;
- ShiftAmount = N->getConstantOperandVal(1);
- Src = N->getOperand(0);
- return true;
- }
- static SDValue tryCombineToEXTR(SDNode *N,
- TargetLowering::DAGCombinerInfo &DCI) {
- SelectionDAG &DAG = DCI.DAG;
- SDLoc DL(N);
- EVT VT = N->getValueType(0);
- assert(N->getOpcode() == ISD::OR && "Unexpected root");
- if (VT != MVT::i32 && VT != MVT::i64)
- return SDValue();
- SDValue LHS;
- uint32_t ShiftLHS = 0;
- bool LHSFromHi = false;
- if (!findEXTRHalf(N->getOperand(0), LHS, ShiftLHS, LHSFromHi))
- return SDValue();
- SDValue RHS;
- uint32_t ShiftRHS = 0;
- bool RHSFromHi = false;
- if (!findEXTRHalf(N->getOperand(1), RHS, ShiftRHS, RHSFromHi))
- return SDValue();
-
-
- if (LHSFromHi == RHSFromHi)
- return SDValue();
- if (ShiftLHS + ShiftRHS != VT.getSizeInBits())
- return SDValue();
- if (LHSFromHi) {
- std::swap(LHS, RHS);
- std::swap(ShiftLHS, ShiftRHS);
- }
- return DAG.getNode(AArch64ISD::EXTR, DL, VT, LHS, RHS,
- DAG.getConstant(ShiftRHS, DL, MVT::i64));
- }
- static SDValue tryCombineToBSL(SDNode *N,
- TargetLowering::DAGCombinerInfo &DCI) {
- EVT VT = N->getValueType(0);
- SelectionDAG &DAG = DCI.DAG;
- SDLoc DL(N);
- if (!VT.isVector())
- return SDValue();
- SDValue N0 = N->getOperand(0);
- if (N0.getOpcode() != ISD::AND)
- return SDValue();
- SDValue N1 = N->getOperand(1);
- if (N1.getOpcode() != ISD::AND)
- return SDValue();
-
-
- unsigned Bits = VT.getScalarSizeInBits();
- uint64_t BitMask = Bits == 64 ? -1ULL : ((1ULL << Bits) - 1);
- for (int i = 1; i >= 0; --i)
- for (int j = 1; j >= 0; --j) {
- BuildVectorSDNode *BVN0 = dyn_cast<BuildVectorSDNode>(N0->getOperand(i));
- BuildVectorSDNode *BVN1 = dyn_cast<BuildVectorSDNode>(N1->getOperand(j));
- if (!BVN0 || !BVN1)
- continue;
- bool FoundMatch = true;
- for (unsigned k = 0; k < VT.getVectorNumElements(); ++k) {
- ConstantSDNode *CN0 = dyn_cast<ConstantSDNode>(BVN0->getOperand(k));
- ConstantSDNode *CN1 = dyn_cast<ConstantSDNode>(BVN1->getOperand(k));
- if (!CN0 || !CN1 ||
- CN0->getZExtValue() != (BitMask & ~CN1->getZExtValue())) {
- FoundMatch = false;
- break;
- }
- }
- if (FoundMatch)
- return DAG.getNode(AArch64ISD::BSP, DL, VT, SDValue(BVN0, 0),
- N0->getOperand(1 - i), N1->getOperand(1 - j));
- }
- return SDValue();
- }
- static SDValue performORCombine(SDNode *N, TargetLowering::DAGCombinerInfo &DCI,
- const AArch64Subtarget *Subtarget) {
-
- SelectionDAG &DAG = DCI.DAG;
- EVT VT = N->getValueType(0);
- if (!DAG.getTargetLoweringInfo().isTypeLegal(VT))
- return SDValue();
- if (SDValue Res = tryCombineToEXTR(N, DCI))
- return Res;
- if (SDValue Res = tryCombineToBSL(N, DCI))
- return Res;
- return SDValue();
- }
- static bool isConstantSplatVectorMaskForType(SDNode *N, EVT MemVT) {
- if (!MemVT.getVectorElementType().isSimple())
- return false;
- uint64_t MaskForTy = 0ull;
- switch (MemVT.getVectorElementType().getSimpleVT().SimpleTy) {
- case MVT::i8:
- MaskForTy = 0xffull;
- break;
- case MVT::i16:
- MaskForTy = 0xffffull;
- break;
- case MVT::i32:
- MaskForTy = 0xffffffffull;
- break;
- default:
- return false;
- break;
- }
- if (N->getOpcode() == AArch64ISD::DUP || N->getOpcode() == ISD::SPLAT_VECTOR)
- if (auto *Op0 = dyn_cast<ConstantSDNode>(N->getOperand(0)))
- return Op0->getAPIntValue().getLimitedValue() == MaskForTy;
- return false;
- }
- static SDValue performSVEAndCombine(SDNode *N,
- TargetLowering::DAGCombinerInfo &DCI) {
- if (DCI.isBeforeLegalizeOps())
- return SDValue();
- SelectionDAG &DAG = DCI.DAG;
- SDValue Src = N->getOperand(0);
- unsigned Opc = Src->getOpcode();
-
- if (Opc == AArch64ISD::UUNPKHI || Opc == AArch64ISD::UUNPKLO) {
- SDValue UnpkOp = Src->getOperand(0);
- SDValue Dup = N->getOperand(1);
- if (Dup.getOpcode() != AArch64ISD::DUP)
- return SDValue();
- SDLoc DL(N);
- ConstantSDNode *C = dyn_cast<ConstantSDNode>(Dup->getOperand(0));
- uint64_t ExtVal = C->getZExtValue();
-
-
- EVT EltTy = UnpkOp->getValueType(0).getVectorElementType();
- if ((ExtVal == 0xFF && EltTy == MVT::i8) ||
- (ExtVal == 0xFFFF && EltTy == MVT::i16) ||
- (ExtVal == 0xFFFFFFFF && EltTy == MVT::i32))
- return Src;
-
- APInt Mask = C->getAPIntValue().trunc(EltTy.getSizeInBits());
-
-
- Dup = DAG.getNode(AArch64ISD::DUP, DL,
- UnpkOp->getValueType(0),
- DAG.getConstant(Mask.zextOrTrunc(32), DL, MVT::i32));
- SDValue And = DAG.getNode(ISD::AND, DL,
- UnpkOp->getValueType(0), UnpkOp, Dup);
- return DAG.getNode(Opc, DL, N->getValueType(0), And);
- }
- if (!EnableCombineMGatherIntrinsics)
- return SDValue();
- SDValue Mask = N->getOperand(1);
- if (!Src.hasOneUse())
- return SDValue();
- EVT MemVT;
-
-
- switch (Opc) {
- case AArch64ISD::LD1_MERGE_ZERO:
- case AArch64ISD::LDNF1_MERGE_ZERO:
- case AArch64ISD::LDFF1_MERGE_ZERO:
- MemVT = cast<VTSDNode>(Src->getOperand(3))->getVT();
- break;
- case AArch64ISD::GLD1_MERGE_ZERO:
- case AArch64ISD::GLD1_SCALED_MERGE_ZERO:
- case AArch64ISD::GLD1_SXTW_MERGE_ZERO:
- case AArch64ISD::GLD1_SXTW_SCALED_MERGE_ZERO:
- case AArch64ISD::GLD1_UXTW_MERGE_ZERO:
- case AArch64ISD::GLD1_UXTW_SCALED_MERGE_ZERO:
- case AArch64ISD::GLD1_IMM_MERGE_ZERO:
- case AArch64ISD::GLDFF1_MERGE_ZERO:
- case AArch64ISD::GLDFF1_SCALED_MERGE_ZERO:
- case AArch64ISD::GLDFF1_SXTW_MERGE_ZERO:
- case AArch64ISD::GLDFF1_SXTW_SCALED_MERGE_ZERO:
- case AArch64ISD::GLDFF1_UXTW_MERGE_ZERO:
- case AArch64ISD::GLDFF1_UXTW_SCALED_MERGE_ZERO:
- case AArch64ISD::GLDFF1_IMM_MERGE_ZERO:
- case AArch64ISD::GLDNT1_MERGE_ZERO:
- MemVT = cast<VTSDNode>(Src->getOperand(4))->getVT();
- break;
- default:
- return SDValue();
- }
- if (isConstantSplatVectorMaskForType(Mask.getNode(), MemVT))
- return Src;
- return SDValue();
- }
- static SDValue performANDCombine(SDNode *N,
- TargetLowering::DAGCombinerInfo &DCI) {
- SelectionDAG &DAG = DCI.DAG;
- SDValue LHS = N->getOperand(0);
- EVT VT = N->getValueType(0);
- if (!VT.isVector() || !DAG.getTargetLoweringInfo().isTypeLegal(VT))
- return SDValue();
- if (VT.isScalableVector())
- return performSVEAndCombine(N, DCI);
-
-
- if (!(VT.is64BitVector() || VT.is128BitVector()))
- return SDValue();
- BuildVectorSDNode *BVN =
- dyn_cast<BuildVectorSDNode>(N->getOperand(1).getNode());
- if (!BVN)
- return SDValue();
-
-
-
-
- APInt DefBits(VT.getSizeInBits(), 0);
- APInt UndefBits(VT.getSizeInBits(), 0);
- if (resolveBuildVector(BVN, DefBits, UndefBits)) {
- SDValue NewOp;
- DefBits = ~DefBits;
- if ((NewOp = tryAdvSIMDModImm32(AArch64ISD::BICi, SDValue(N, 0), DAG,
- DefBits, &LHS)) ||
- (NewOp = tryAdvSIMDModImm16(AArch64ISD::BICi, SDValue(N, 0), DAG,
- DefBits, &LHS)))
- return NewOp;
- UndefBits = ~UndefBits;
- if ((NewOp = tryAdvSIMDModImm32(AArch64ISD::BICi, SDValue(N, 0), DAG,
- UndefBits, &LHS)) ||
- (NewOp = tryAdvSIMDModImm16(AArch64ISD::BICi, SDValue(N, 0), DAG,
- UndefBits, &LHS)))
- return NewOp;
- }
- return SDValue();
- }
- static SDValue performSRLCombine(SDNode *N,
- TargetLowering::DAGCombinerInfo &DCI) {
- SelectionDAG &DAG = DCI.DAG;
- EVT VT = N->getValueType(0);
- if (VT != MVT::i32 && VT != MVT::i64)
- return SDValue();
-
-
-
- SDValue N0 = N->getOperand(0);
- if (N0.getOpcode() == ISD::BSWAP) {
- SDLoc DL(N);
- SDValue N1 = N->getOperand(1);
- SDValue N00 = N0.getOperand(0);
- if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N1)) {
- uint64_t ShiftAmt = C->getZExtValue();
- if (VT == MVT::i32 && ShiftAmt == 16 &&
- DAG.MaskedValueIsZero(N00, APInt::getHighBitsSet(32, 16)))
- return DAG.getNode(ISD::ROTR, DL, VT, N0, N1);
- if (VT == MVT::i64 && ShiftAmt == 32 &&
- DAG.MaskedValueIsZero(N00, APInt::getHighBitsSet(64, 32)))
- return DAG.getNode(ISD::ROTR, DL, VT, N0, N1);
- }
- }
- return SDValue();
- }
- static SDValue
- performVectorTruncateCombine(SDNode *N, TargetLowering::DAGCombinerInfo &DCI,
- SelectionDAG &DAG) {
- EVT VT = N->getValueType(0);
-
-
-
-
-
- SDValue Shift = N->getOperand(0);
- if (Shift.getOpcode() != AArch64ISD::VLSHR)
- return SDValue();
-
- uint64_t ShiftAmount = Shift.getConstantOperandVal(1);
- if (ShiftAmount != 1)
- return SDValue();
- SDValue ExtendOpA, ExtendOpB;
- SDValue ShiftOp0 = Shift.getOperand(0);
- unsigned ShiftOp0Opc = ShiftOp0.getOpcode();
- if (ShiftOp0Opc == ISD::SUB) {
- SDValue Xor = ShiftOp0.getOperand(1);
- if (Xor.getOpcode() != ISD::XOR)
- return SDValue();
-
- uint64_t C;
- if (!isAllConstantBuildVector(Xor.getOperand(1), C))
- return SDValue();
- unsigned ElemSizeInBits = VT.getScalarSizeInBits();
- APInt CAsAPInt(ElemSizeInBits, C);
- if (CAsAPInt != APInt::getAllOnesValue(ElemSizeInBits))
- return SDValue();
- ExtendOpA = Xor.getOperand(0);
- ExtendOpB = ShiftOp0.getOperand(0);
- } else if (ShiftOp0Opc == ISD::ADD) {
- ExtendOpA = ShiftOp0.getOperand(0);
- ExtendOpB = ShiftOp0.getOperand(1);
- } else
- return SDValue();
- unsigned ExtendOpAOpc = ExtendOpA.getOpcode();
- unsigned ExtendOpBOpc = ExtendOpB.getOpcode();
- if (!(ExtendOpAOpc == ExtendOpBOpc &&
- (ExtendOpAOpc == ISD::ZERO_EXTEND || ExtendOpAOpc == ISD::SIGN_EXTEND)))
- return SDValue();
-
-
- SDValue OpA = ExtendOpA.getOperand(0);
- SDValue OpB = ExtendOpB.getOperand(0);
- EVT OpAVT = OpA.getValueType();
- assert(ExtendOpA.getValueType() == ExtendOpB.getValueType());
- if (!(VT == OpAVT && OpAVT == OpB.getValueType()))
- return SDValue();
- SDLoc DL(N);
- bool IsSignExtend = ExtendOpAOpc == ISD::SIGN_EXTEND;
- bool IsRHADD = ShiftOp0Opc == ISD::SUB;
- unsigned HADDOpc = IsSignExtend
- ? (IsRHADD ? AArch64ISD::SRHADD : AArch64ISD::SHADD)
- : (IsRHADD ? AArch64ISD::URHADD : AArch64ISD::UHADD);
- SDValue ResultHADD = DAG.getNode(HADDOpc, DL, VT, OpA, OpB);
- return ResultHADD;
- }
- static bool hasPairwiseAdd(unsigned Opcode, EVT VT, bool FullFP16) {
- switch (Opcode) {
- case ISD::FADD:
- return (FullFP16 && VT == MVT::f16) || VT == MVT::f32 || VT == MVT::f64;
- case ISD::ADD:
- return VT == MVT::i64;
- default:
- return false;
- }
- }
- static SDValue performExtractVectorEltCombine(SDNode *N, SelectionDAG &DAG) {
- SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
- ConstantSDNode *ConstantN1 = dyn_cast<ConstantSDNode>(N1);
- EVT VT = N->getValueType(0);
- const bool FullFP16 =
- static_cast<const AArch64Subtarget &>(DAG.getSubtarget()).hasFullFP16();
-
-
-
-
-
-
-
- if (ConstantN1 && ConstantN1->getZExtValue() == 0 &&
- hasPairwiseAdd(N0->getOpcode(), VT, FullFP16)) {
- SDLoc DL(N0);
- SDValue N00 = N0->getOperand(0);
- SDValue N01 = N0->getOperand(1);
- ShuffleVectorSDNode *Shuffle = dyn_cast<ShuffleVectorSDNode>(N01);
- SDValue Other = N00;
-
- if (!Shuffle) {
- Shuffle = dyn_cast<ShuffleVectorSDNode>(N00);
- Other = N01;
- }
- if (Shuffle && Shuffle->getMaskElt(0) == 1 &&
- Other == Shuffle->getOperand(0)) {
- return DAG.getNode(N0->getOpcode(), DL, VT,
- DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, VT, Other,
- DAG.getConstant(0, DL, MVT::i64)),
- DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, VT, Other,
- DAG.getConstant(1, DL, MVT::i64)));
- }
- }
- return SDValue();
- }
- static SDValue performConcatVectorsCombine(SDNode *N,
- TargetLowering::DAGCombinerInfo &DCI,
- SelectionDAG &DAG) {
- SDLoc dl(N);
- EVT VT = N->getValueType(0);
- SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
- unsigned N0Opc = N0->getOpcode(), N1Opc = N1->getOpcode();
-
-
-
-
-
-
-
-
-
-
-
- if (N->getNumOperands() == 2 && N0Opc == ISD::TRUNCATE &&
- N1Opc == ISD::TRUNCATE) {
- SDValue N00 = N0->getOperand(0);
- SDValue N10 = N1->getOperand(0);
- EVT N00VT = N00.getValueType();
- if (N00VT == N10.getValueType() &&
- (N00VT == MVT::v2i64 || N00VT == MVT::v4i32) &&
- N00VT.getScalarSizeInBits() == 4 * VT.getScalarSizeInBits()) {
- MVT MidVT = (N00VT == MVT::v2i64 ? MVT::v4i32 : MVT::v8i16);
- SmallVector<int, 8> Mask(MidVT.getVectorNumElements());
- for (size_t i = 0; i < Mask.size(); ++i)
- Mask[i] = i * 2;
- return DAG.getNode(ISD::TRUNCATE, dl, VT,
- DAG.getVectorShuffle(
- MidVT, dl,
- DAG.getNode(ISD::BITCAST, dl, MidVT, N00),
- DAG.getNode(ISD::BITCAST, dl, MidVT, N10), Mask));
- }
- }
-
-
- if (DCI.isBeforeLegalizeOps())
- return SDValue();
-
-
-
-
-
-
-
-
-
-
-
- if (N->getNumOperands() == 2 && N0Opc == N1Opc &&
- (N0Opc == AArch64ISD::URHADD || N0Opc == AArch64ISD::SRHADD ||
- N0Opc == AArch64ISD::UHADD || N0Opc == AArch64ISD::SHADD)) {
- SDValue N00 = N0->getOperand(0);
- SDValue N01 = N0->getOperand(1);
- SDValue N10 = N1->getOperand(0);
- SDValue N11 = N1->getOperand(1);
- EVT N00VT = N00.getValueType();
- EVT N10VT = N10.getValueType();
- if (N00->getOpcode() == ISD::EXTRACT_SUBVECTOR &&
- N01->getOpcode() == ISD::EXTRACT_SUBVECTOR &&
- N10->getOpcode() == ISD::EXTRACT_SUBVECTOR &&
- N11->getOpcode() == ISD::EXTRACT_SUBVECTOR && N00VT == N10VT) {
- SDValue N00Source = N00->getOperand(0);
- SDValue N01Source = N01->getOperand(0);
- SDValue N10Source = N10->getOperand(0);
- SDValue N11Source = N11->getOperand(0);
- if (N00Source == N10Source && N01Source == N11Source &&
- N00Source.getValueType() == VT && N01Source.getValueType() == VT) {
- assert(N0.getValueType() == N1.getValueType());
- uint64_t N00Index = N00.getConstantOperandVal(1);
- uint64_t N01Index = N01.getConstantOperandVal(1);
- uint64_t N10Index = N10.getConstantOperandVal(1);
- uint64_t N11Index = N11.getConstantOperandVal(1);
- if (N00Index == N01Index && N10Index == N11Index && N00Index == 0 &&
- N10Index == N00VT.getVectorNumElements())
- return DAG.getNode(N0Opc, dl, VT, N00Source, N01Source);
- }
- }
- }
-
-
-
- if (N0 == N1 && VT.getVectorNumElements() == 2) {
- assert(VT.getScalarSizeInBits() == 64);
- return DAG.getNode(AArch64ISD::DUPLANE64, dl, VT, WidenVector(N0, DAG),
- DAG.getConstant(0, dl, MVT::i64));
- }
-
-
-
-
-
-
-
-
- if (N1Opc != ISD::BITCAST)
- return SDValue();
- SDValue RHS = N1->getOperand(0);
- MVT RHSTy = RHS.getValueType().getSimpleVT();
-
- if (!RHSTy.isVector())
- return SDValue();
- LLVM_DEBUG(
- dbgs() << "aarch64-lower: concat_vectors bitcast simplification\n");
- MVT ConcatTy = MVT::getVectorVT(RHSTy.getVectorElementType(),
- RHSTy.getVectorNumElements() * 2);
- return DAG.getNode(ISD::BITCAST, dl, VT,
- DAG.getNode(ISD::CONCAT_VECTORS, dl, ConcatTy,
- DAG.getNode(ISD::BITCAST, dl, RHSTy, N0),
- RHS));
- }
- static SDValue tryCombineFixedPointConvert(SDNode *N,
- TargetLowering::DAGCombinerInfo &DCI,
- SelectionDAG &DAG) {
-
-
- if (DCI.isBeforeLegalizeOps())
- return SDValue();
-
-
-
-
-
-
-
-
-
- SDValue Op1 = N->getOperand(1);
- if (Op1.getOpcode() == ISD::EXTRACT_VECTOR_ELT) {
-
- SDValue IID = N->getOperand(0);
- SDValue Shift = N->getOperand(2);
- SDValue Vec = Op1.getOperand(0);
- SDValue Lane = Op1.getOperand(1);
- EVT ResTy = N->getValueType(0);
- EVT VecResTy;
- SDLoc DL(N);
-
-
-
- assert(Vec.getValueSizeInBits() == 128 &&
- "unexpected vector size on extract_vector_elt!");
- if (Vec.getValueType() == MVT::v4i32)
- VecResTy = MVT::v4f32;
- else if (Vec.getValueType() == MVT::v2i64)
- VecResTy = MVT::v2f64;
- else
- llvm_unreachable("unexpected vector type!");
- SDValue Convert =
- DAG.getNode(ISD::INTRINSIC_WO_CHAIN, DL, VecResTy, IID, Vec, Shift);
- return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, ResTy, Convert, Lane);
- }
- return SDValue();
- }
- static SDValue tryExtendDUPToExtractHigh(SDValue N, SelectionDAG &DAG) {
- switch (N.getOpcode()) {
- case AArch64ISD::DUP:
- case AArch64ISD::DUPLANE8:
- case AArch64ISD::DUPLANE16:
- case AArch64ISD::DUPLANE32:
- case AArch64ISD::DUPLANE64:
- case AArch64ISD::MOVI:
- case AArch64ISD::MOVIshift:
- case AArch64ISD::MOVIedit:
- case AArch64ISD::MOVImsl:
- case AArch64ISD::MVNIshift:
- case AArch64ISD::MVNImsl:
- break;
- default:
-
-
-
- return SDValue();
- }
- MVT NarrowTy = N.getSimpleValueType();
- if (!NarrowTy.is64BitVector())
- return SDValue();
- MVT ElementTy = NarrowTy.getVectorElementType();
- unsigned NumElems = NarrowTy.getVectorNumElements();
- MVT NewVT = MVT::getVectorVT(ElementTy, NumElems * 2);
- SDLoc dl(N);
- return DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, NarrowTy,
- DAG.getNode(N->getOpcode(), dl, NewVT, N->ops()),
- DAG.getConstant(NumElems, dl, MVT::i64));
- }
- static bool isEssentiallyExtractHighSubvector(SDValue N) {
- if (N.getOpcode() == ISD::BITCAST)
- N = N.getOperand(0);
- if (N.getOpcode() != ISD::EXTRACT_SUBVECTOR)
- return false;
- return cast<ConstantSDNode>(N.getOperand(1))->getAPIntValue() ==
- N.getOperand(0).getValueType().getVectorNumElements() / 2;
- }
- struct GenericSetCCInfo {
- const SDValue *Opnd0;
- const SDValue *Opnd1;
- ISD::CondCode CC;
- };
- struct AArch64SetCCInfo {
- const SDValue *Cmp;
- AArch64CC::CondCode CC;
- };
- union SetCCInfo {
- GenericSetCCInfo Generic;
- AArch64SetCCInfo AArch64;
- };
- struct SetCCInfoAndKind {
- SetCCInfo Info;
- bool IsAArch64;
- };
- static bool isSetCC(SDValue Op, SetCCInfoAndKind &SetCCInfo) {
-
- if (Op.getOpcode() == ISD::SETCC) {
- SetCCInfo.Info.Generic.Opnd0 = &Op.getOperand(0);
- SetCCInfo.Info.Generic.Opnd1 = &Op.getOperand(1);
- SetCCInfo.Info.Generic.CC = cast<CondCodeSDNode>(Op.getOperand(2))->get();
- SetCCInfo.IsAArch64 = false;
- return true;
- }
-
-
-
-
- if (Op.getOpcode() != AArch64ISD::CSEL)
- return false;
-
-
- SetCCInfo.Info.AArch64.Cmp = &Op.getOperand(3);
- SetCCInfo.IsAArch64 = true;
- SetCCInfo.Info.AArch64.CC = static_cast<AArch64CC::CondCode>(
- cast<ConstantSDNode>(Op.getOperand(2))->getZExtValue());
-
-
-
- ConstantSDNode *TValue = dyn_cast<ConstantSDNode>(Op.getOperand(0));
- ConstantSDNode *FValue = dyn_cast<ConstantSDNode>(Op.getOperand(1));
-
- if (!TValue || !FValue)
- return false;
-
- if (!TValue->isOne()) {
-
- std::swap(TValue, FValue);
- SetCCInfo.Info.AArch64.CC =
- AArch64CC::getInvertedCondCode(SetCCInfo.Info.AArch64.CC);
- }
- return TValue->isOne() && FValue->isNullValue();
- }
- static bool isSetCCOrZExtSetCC(const SDValue& Op, SetCCInfoAndKind &Info) {
- if (isSetCC(Op, Info))
- return true;
- return ((Op.getOpcode() == ISD::ZERO_EXTEND) &&
- isSetCC(Op->getOperand(0), Info));
- }
- static SDValue performSetccAddFolding(SDNode *Op, SelectionDAG &DAG) {
- assert(Op && Op->getOpcode() == ISD::ADD && "Unexpected operation!");
- SDValue LHS = Op->getOperand(0);
- SDValue RHS = Op->getOperand(1);
- SetCCInfoAndKind InfoAndKind;
-
- if (!isSetCCOrZExtSetCC(LHS, InfoAndKind)) {
- std::swap(LHS, RHS);
- if (!isSetCCOrZExtSetCC(LHS, InfoAndKind))
- return SDValue();
- }
-
- EVT CmpVT = InfoAndKind.IsAArch64
- ? InfoAndKind.Info.AArch64.Cmp->getOperand(0).getValueType()
- : InfoAndKind.Info.Generic.Opnd0->getValueType();
- if (CmpVT != MVT::i32 && CmpVT != MVT::i64)
- return SDValue();
- SDValue CCVal;
- SDValue Cmp;
- SDLoc dl(Op);
- if (InfoAndKind.IsAArch64) {
- CCVal = DAG.getConstant(
- AArch64CC::getInvertedCondCode(InfoAndKind.Info.AArch64.CC), dl,
- MVT::i32);
- Cmp = *InfoAndKind.Info.AArch64.Cmp;
- } else
- Cmp = getAArch64Cmp(
- *InfoAndKind.Info.Generic.Opnd0, *InfoAndKind.Info.Generic.Opnd1,
- ISD::getSetCCInverse(InfoAndKind.Info.Generic.CC, CmpVT), CCVal, DAG,
- dl);
- EVT VT = Op->getValueType(0);
- LHS = DAG.getNode(ISD::ADD, dl, VT, RHS, DAG.getConstant(1, dl, VT));
- return DAG.getNode(AArch64ISD::CSEL, dl, VT, RHS, LHS, CCVal, Cmp);
- }
- static SDValue performUADDVCombine(SDNode *N, SelectionDAG &DAG) {
- EVT VT = N->getValueType(0);
-
- if (N->getOpcode() != ISD::ADD || !VT.isScalarInteger())
- return SDValue();
- SDValue LHS = N->getOperand(0);
- SDValue RHS = N->getOperand(1);
- if (LHS.getOpcode() != ISD::EXTRACT_VECTOR_ELT ||
- RHS.getOpcode() != ISD::EXTRACT_VECTOR_ELT || LHS.getValueType() != VT)
- return SDValue();
- auto *LHSN1 = dyn_cast<ConstantSDNode>(LHS->getOperand(1));
- auto *RHSN1 = dyn_cast<ConstantSDNode>(RHS->getOperand(1));
- if (!LHSN1 || LHSN1 != RHSN1 || !RHSN1->isNullValue())
- return SDValue();
- SDValue Op1 = LHS->getOperand(0);
- SDValue Op2 = RHS->getOperand(0);
- EVT OpVT1 = Op1.getValueType();
- EVT OpVT2 = Op2.getValueType();
- if (Op1.getOpcode() != AArch64ISD::UADDV || OpVT1 != OpVT2 ||
- Op2.getOpcode() != AArch64ISD::UADDV ||
- OpVT1.getVectorElementType() != VT)
- return SDValue();
- SDValue Val1 = Op1.getOperand(0);
- SDValue Val2 = Op2.getOperand(0);
- EVT ValVT = Val1->getValueType(0);
- SDLoc DL(N);
- SDValue AddVal = DAG.getNode(ISD::ADD, DL, ValVT, Val1, Val2);
- return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, VT,
- DAG.getNode(AArch64ISD::UADDV, DL, ValVT, AddVal),
- DAG.getConstant(0, DL, MVT::i64));
- }
- static SDValue performAddSubLongCombine(SDNode *N,
- TargetLowering::DAGCombinerInfo &DCI,
- SelectionDAG &DAG) {
- if (DCI.isBeforeLegalizeOps())
- return SDValue();
- MVT VT = N->getSimpleValueType(0);
- if (!VT.is128BitVector()) {
- if (N->getOpcode() == ISD::ADD)
- return performSetccAddFolding(N, DAG);
- return SDValue();
- }
-
- SDValue LHS = N->getOperand(0);
- SDValue RHS = N->getOperand(1);
- if ((LHS.getOpcode() != ISD::ZERO_EXTEND &&
- LHS.getOpcode() != ISD::SIGN_EXTEND) ||
- LHS.getOpcode() != RHS.getOpcode())
- return SDValue();
- unsigned ExtType = LHS.getOpcode();
-
-
- if (isEssentiallyExtractHighSubvector(LHS.getOperand(0))) {
- RHS = tryExtendDUPToExtractHigh(RHS.getOperand(0), DAG);
- if (!RHS.getNode())
- return SDValue();
- RHS = DAG.getNode(ExtType, SDLoc(N), VT, RHS);
- } else if (isEssentiallyExtractHighSubvector(RHS.getOperand(0))) {
- LHS = tryExtendDUPToExtractHigh(LHS.getOperand(0), DAG);
- if (!LHS.getNode())
- return SDValue();
- LHS = DAG.getNode(ExtType, SDLoc(N), VT, LHS);
- }
- return DAG.getNode(N->getOpcode(), SDLoc(N), VT, LHS, RHS);
- }
- static SDValue performAddSubCombine(SDNode *N,
- TargetLowering::DAGCombinerInfo &DCI,
- SelectionDAG &DAG) {
-
- if (SDValue Val = performUADDVCombine(N, DAG))
- return Val;
- return performAddSubLongCombine(N, DCI, DAG);
- }
- static SDValue tryCombineLongOpWithDup(unsigned IID, SDNode *N,
- TargetLowering::DAGCombinerInfo &DCI,
- SelectionDAG &DAG) {
- if (DCI.isBeforeLegalizeOps())
- return SDValue();
- SDValue LHS = N->getOperand((IID == Intrinsic::not_intrinsic) ? 0 : 1);
- SDValue RHS = N->getOperand((IID == Intrinsic::not_intrinsic) ? 1 : 2);
- assert(LHS.getValueType().is64BitVector() &&
- RHS.getValueType().is64BitVector() &&
- "unexpected shape for long operation");
-
-
-
- if (isEssentiallyExtractHighSubvector(LHS)) {
- RHS = tryExtendDUPToExtractHigh(RHS, DAG);
- if (!RHS.getNode())
- return SDValue();
- } else if (isEssentiallyExtractHighSubvector(RHS)) {
- LHS = tryExtendDUPToExtractHigh(LHS, DAG);
- if (!LHS.getNode())
- return SDValue();
- }
- if (IID == Intrinsic::not_intrinsic)
- return DAG.getNode(N->getOpcode(), SDLoc(N), N->getValueType(0), LHS, RHS);
- return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, SDLoc(N), N->getValueType(0),
- N->getOperand(0), LHS, RHS);
- }
- static SDValue tryCombineShiftImm(unsigned IID, SDNode *N, SelectionDAG &DAG) {
- MVT ElemTy = N->getSimpleValueType(0).getScalarType();
- unsigned ElemBits = ElemTy.getSizeInBits();
- int64_t ShiftAmount;
- if (BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(N->getOperand(2))) {
- APInt SplatValue, SplatUndef;
- unsigned SplatBitSize;
- bool HasAnyUndefs;
- if (!BVN->isConstantSplat(SplatValue, SplatUndef, SplatBitSize,
- HasAnyUndefs, ElemBits) ||
- SplatBitSize != ElemBits)
- return SDValue();
- ShiftAmount = SplatValue.getSExtValue();
- } else if (ConstantSDNode *CVN = dyn_cast<ConstantSDNode>(N->getOperand(2))) {
- ShiftAmount = CVN->getSExtValue();
- } else
- return SDValue();
- unsigned Opcode;
- bool IsRightShift;
- switch (IID) {
- default:
- llvm_unreachable("Unknown shift intrinsic");
- case Intrinsic::aarch64_neon_sqshl:
- Opcode = AArch64ISD::SQSHL_I;
- IsRightShift = false;
- break;
- case Intrinsic::aarch64_neon_uqshl:
- Opcode = AArch64ISD::UQSHL_I;
- IsRightShift = false;
- break;
- case Intrinsic::aarch64_neon_srshl:
- Opcode = AArch64ISD::SRSHR_I;
- IsRightShift = true;
- break;
- case Intrinsic::aarch64_neon_urshl:
- Opcode = AArch64ISD::URSHR_I;
- IsRightShift = true;
- break;
- case Intrinsic::aarch64_neon_sqshlu:
- Opcode = AArch64ISD::SQSHLU_I;
- IsRightShift = false;
- break;
- case Intrinsic::aarch64_neon_sshl:
- case Intrinsic::aarch64_neon_ushl:
-
-
-
- Opcode = AArch64ISD::VSHL;
- IsRightShift = false;
- break;
- }
- if (IsRightShift && ShiftAmount <= -1 && ShiftAmount >= -(int)ElemBits) {
- SDLoc dl(N);
- return DAG.getNode(Opcode, dl, N->getValueType(0), N->getOperand(1),
- DAG.getConstant(-ShiftAmount, dl, MVT::i32));
- } else if (!IsRightShift && ShiftAmount >= 0 && ShiftAmount < ElemBits) {
- SDLoc dl(N);
- return DAG.getNode(Opcode, dl, N->getValueType(0), N->getOperand(1),
- DAG.getConstant(ShiftAmount, dl, MVT::i32));
- }
- return SDValue();
- }
- static SDValue tryCombineCRC32(unsigned Mask, SDNode *N, SelectionDAG &DAG) {
- SDValue AndN = N->getOperand(2);
- if (AndN.getOpcode() != ISD::AND)
- return SDValue();
- ConstantSDNode *CMask = dyn_cast<ConstantSDNode>(AndN.getOperand(1));
- if (!CMask || CMask->getZExtValue() != Mask)
- return SDValue();
- return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, SDLoc(N), MVT::i32,
- N->getOperand(0), N->getOperand(1), AndN.getOperand(0));
- }
- static SDValue combineAcrossLanesIntrinsic(unsigned Opc, SDNode *N,
- SelectionDAG &DAG) {
- SDLoc dl(N);
- return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, N->getValueType(0),
- DAG.getNode(Opc, dl,
- N->getOperand(1).getSimpleValueType(),
- N->getOperand(1)),
- DAG.getConstant(0, dl, MVT::i64));
- }
- static SDValue LowerSVEIntrinsicIndex(SDNode *N, SelectionDAG &DAG) {
- SDLoc DL(N);
- SDValue Op1 = N->getOperand(1);
- SDValue Op2 = N->getOperand(2);
- EVT ScalarTy = Op1.getValueType();
- if ((ScalarTy == MVT::i8) || (ScalarTy == MVT::i16)) {
- Op1 = DAG.getNode(ISD::ANY_EXTEND, DL, MVT::i32, Op1);
- Op2 = DAG.getNode(ISD::ANY_EXTEND, DL, MVT::i32, Op2);
- }
- return DAG.getNode(AArch64ISD::INDEX_VECTOR, DL, N->getValueType(0),
- Op1, Op2);
- }
- static SDValue LowerSVEIntrinsicDUP(SDNode *N, SelectionDAG &DAG) {
- SDLoc dl(N);
- SDValue Scalar = N->getOperand(3);
- EVT ScalarTy = Scalar.getValueType();
- if ((ScalarTy == MVT::i8) || (ScalarTy == MVT::i16))
- Scalar = DAG.getNode(ISD::ANY_EXTEND, dl, MVT::i32, Scalar);
- SDValue Passthru = N->getOperand(1);
- SDValue Pred = N->getOperand(2);
- return DAG.getNode(AArch64ISD::DUP_MERGE_PASSTHRU, dl, N->getValueType(0),
- Pred, Scalar, Passthru);
- }
- static SDValue LowerSVEIntrinsicEXT(SDNode *N, SelectionDAG &DAG) {
- SDLoc dl(N);
- LLVMContext &Ctx = *DAG.getContext();
- EVT VT = N->getValueType(0);
- assert(VT.isScalableVector() && "Expected a scalable vector.");
-
- if (VT.getSizeInBits().getKnownMinSize() != AArch64::SVEBitsPerBlock)
- return SDValue();
- unsigned ElemSize = VT.getVectorElementType().getSizeInBits() / 8;
- unsigned ByteSize = VT.getSizeInBits().getKnownMinSize() / 8;
- EVT ByteVT =
- EVT::getVectorVT(Ctx, MVT::i8, ElementCount::getScalable(ByteSize));
-
- SDValue Op0 = DAG.getNode(ISD::BITCAST, dl, ByteVT, N->getOperand(1));
- SDValue Op1 = DAG.getNode(ISD::BITCAST, dl, ByteVT, N->getOperand(2));
- SDValue Op2 = DAG.getNode(ISD::MUL, dl, MVT::i32, N->getOperand(3),
- DAG.getConstant(ElemSize, dl, MVT::i32));
- SDValue EXT = DAG.getNode(AArch64ISD::EXT, dl, ByteVT, Op0, Op1, Op2);
- return DAG.getNode(ISD::BITCAST, dl, VT, EXT);
- }
- static SDValue tryConvertSVEWideCompare(SDNode *N, ISD::CondCode CC,
- TargetLowering::DAGCombinerInfo &DCI,
- SelectionDAG &DAG) {
- if (DCI.isBeforeLegalize())
- return SDValue();
- SDValue Comparator = N->getOperand(3);
- if (Comparator.getOpcode() == AArch64ISD::DUP ||
- Comparator.getOpcode() == ISD::SPLAT_VECTOR) {
- unsigned IID = getIntrinsicID(N);
- EVT VT = N->getValueType(0);
- EVT CmpVT = N->getOperand(2).getValueType();
- SDValue Pred = N->getOperand(1);
- SDValue Imm;
- SDLoc DL(N);
- switch (IID) {
- default:
- llvm_unreachable("Called with wrong intrinsic!");
- break;
-
- case Intrinsic::aarch64_sve_cmpeq_wide:
- case Intrinsic::aarch64_sve_cmpne_wide:
- case Intrinsic::aarch64_sve_cmpge_wide:
- case Intrinsic::aarch64_sve_cmpgt_wide:
- case Intrinsic::aarch64_sve_cmplt_wide:
- case Intrinsic::aarch64_sve_cmple_wide: {
- if (auto *CN = dyn_cast<ConstantSDNode>(Comparator.getOperand(0))) {
- int64_t ImmVal = CN->getSExtValue();
- if (ImmVal >= -16 && ImmVal <= 15)
- Imm = DAG.getConstant(ImmVal, DL, MVT::i32);
- else
- return SDValue();
- }
- break;
- }
-
- case Intrinsic::aarch64_sve_cmphs_wide:
- case Intrinsic::aarch64_sve_cmphi_wide:
- case Intrinsic::aarch64_sve_cmplo_wide:
- case Intrinsic::aarch64_sve_cmpls_wide: {
- if (auto *CN = dyn_cast<ConstantSDNode>(Comparator.getOperand(0))) {
- uint64_t ImmVal = CN->getZExtValue();
- if (ImmVal <= 127)
- Imm = DAG.getConstant(ImmVal, DL, MVT::i32);
- else
- return SDValue();
- }
- break;
- }
- }
- if (!Imm)
- return SDValue();
- SDValue Splat = DAG.getNode(ISD::SPLAT_VECTOR, DL, CmpVT, Imm);
- return DAG.getNode(AArch64ISD::SETCC_MERGE_ZERO, DL, VT, Pred,
- N->getOperand(2), Splat, DAG.getCondCode(CC));
- }
- return SDValue();
- }
- static SDValue getPTest(SelectionDAG &DAG, EVT VT, SDValue Pg, SDValue Op,
- AArch64CC::CondCode Cond) {
- const TargetLowering &TLI = DAG.getTargetLoweringInfo();
- SDLoc DL(Op);
- assert(Op.getValueType().isScalableVector() &&
- TLI.isTypeLegal(Op.getValueType()) &&
- "Expected legal scalable vector type!");
-
- EVT OutVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT);
- SDValue TVal = DAG.getConstant(1, DL, OutVT);
- SDValue FVal = DAG.getConstant(0, DL, OutVT);
-
- SDValue Test = DAG.getNode(AArch64ISD::PTEST, DL, MVT::Other, Pg, Op);
-
-
- SDValue CC = DAG.getConstant(getInvertedCondCode(Cond), DL, MVT::i32);
- SDValue Res = DAG.getNode(AArch64ISD::CSEL, DL, OutVT, FVal, TVal, CC, Test);
- return DAG.getZExtOrTrunc(Res, DL, VT);
- }
- static SDValue combineSVEReductionInt(SDNode *N, unsigned Opc,
- SelectionDAG &DAG) {
- SDLoc DL(N);
- SDValue Pred = N->getOperand(1);
- SDValue VecToReduce = N->getOperand(2);
-
-
- EVT ReduceVT = getPackedSVEVectorVT(N->getValueType(0));
- SDValue Reduce = DAG.getNode(Opc, DL, ReduceVT, Pred, VecToReduce);
-
-
- SDValue Zero = DAG.getConstant(0, DL, MVT::i64);
- return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, N->getValueType(0), Reduce,
- Zero);
- }
- static SDValue combineSVEReductionFP(SDNode *N, unsigned Opc,
- SelectionDAG &DAG) {
- SDLoc DL(N);
- SDValue Pred = N->getOperand(1);
- SDValue VecToReduce = N->getOperand(2);
- EVT ReduceVT = VecToReduce.getValueType();
- SDValue Reduce = DAG.getNode(Opc, DL, ReduceVT, Pred, VecToReduce);
-
-
- SDValue Zero = DAG.getConstant(0, DL, MVT::i64);
- return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, N->getValueType(0), Reduce,
- Zero);
- }
- static SDValue combineSVEReductionOrderedFP(SDNode *N, unsigned Opc,
- SelectionDAG &DAG) {
- SDLoc DL(N);
- SDValue Pred = N->getOperand(1);
- SDValue InitVal = N->getOperand(2);
- SDValue VecToReduce = N->getOperand(3);
- EVT ReduceVT = VecToReduce.getValueType();
-
-
- SDValue Zero = DAG.getConstant(0, DL, MVT::i64);
- InitVal = DAG.getNode(ISD::INSERT_VECTOR_ELT, DL, ReduceVT,
- DAG.getUNDEF(ReduceVT), InitVal, Zero);
- SDValue Reduce = DAG.getNode(Opc, DL, ReduceVT, Pred, InitVal, VecToReduce);
-
-
- return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, N->getValueType(0), Reduce,
- Zero);
- }
- static SDValue convertMergedOpToPredOp(SDNode *N, unsigned PredOpc,
- SelectionDAG &DAG) {
- assert(N->getOpcode() == ISD::INTRINSIC_WO_CHAIN && "Expected intrinsic!");
- assert(N->getNumOperands() == 4 && "Expected 3 operand intrinsic!");
- SDValue Pg = N->getOperand(1);
-
- if ((Pg.getOpcode() == AArch64ISD::PTRUE) &&
- (Pg.getConstantOperandVal(0) == AArch64SVEPredPattern::all))
- return DAG.getNode(PredOpc, SDLoc(N), N->getValueType(0), Pg,
- N->getOperand(2), N->getOperand(3));
-
- return SDValue();
- }
- static SDValue performIntrinsicCombine(SDNode *N,
- TargetLowering::DAGCombinerInfo &DCI,
- const AArch64Subtarget *Subtarget) {
- SelectionDAG &DAG = DCI.DAG;
- unsigned IID = getIntrinsicID(N);
- switch (IID) {
- default:
- break;
- case Intrinsic::aarch64_neon_vcvtfxs2fp:
- case Intrinsic::aarch64_neon_vcvtfxu2fp:
- return tryCombineFixedPointConvert(N, DCI, DAG);
- case Intrinsic::aarch64_neon_saddv:
- return combineAcrossLanesIntrinsic(AArch64ISD::SADDV, N, DAG);
- case Intrinsic::aarch64_neon_uaddv:
- return combineAcrossLanesIntrinsic(AArch64ISD::UADDV, N, DAG);
- case Intrinsic::aarch64_neon_sminv:
- return combineAcrossLanesIntrinsic(AArch64ISD::SMINV, N, DAG);
- case Intrinsic::aarch64_neon_uminv:
- return combineAcrossLanesIntrinsic(AArch64ISD::UMINV, N, DAG);
- case Intrinsic::aarch64_neon_smaxv:
- return combineAcrossLanesIntrinsic(AArch64ISD::SMAXV, N, DAG);
- case Intrinsic::aarch64_neon_umaxv:
- return combineAcrossLanesIntrinsic(AArch64ISD::UMAXV, N, DAG);
- case Intrinsic::aarch64_neon_fmax:
- return DAG.getNode(ISD::FMAXIMUM, SDLoc(N), N->getValueType(0),
- N->getOperand(1), N->getOperand(2));
- case Intrinsic::aarch64_neon_fmin:
- return DAG.getNode(ISD::FMINIMUM, SDLoc(N), N->getValueType(0),
- N->getOperand(1), N->getOperand(2));
- case Intrinsic::aarch64_neon_fmaxnm:
- return DAG.getNode(ISD::FMAXNUM, SDLoc(N), N->getValueType(0),
- N->getOperand(1), N->getOperand(2));
- case Intrinsic::aarch64_neon_fminnm:
- return DAG.getNode(ISD::FMINNUM, SDLoc(N), N->getValueType(0),
- N->getOperand(1), N->getOperand(2));
- case Intrinsic::aarch64_neon_smull:
- case Intrinsic::aarch64_neon_umull:
- case Intrinsic::aarch64_neon_pmull:
- case Intrinsic::aarch64_neon_sqdmull:
- return tryCombineLongOpWithDup(IID, N, DCI, DAG);
- case Intrinsic::aarch64_neon_sqshl:
- case Intrinsic::aarch64_neon_uqshl:
- case Intrinsic::aarch64_neon_sqshlu:
- case Intrinsic::aarch64_neon_srshl:
- case Intrinsic::aarch64_neon_urshl:
- case Intrinsic::aarch64_neon_sshl:
- case Intrinsic::aarch64_neon_ushl:
- return tryCombineShiftImm(IID, N, DAG);
- case Intrinsic::aarch64_crc32b:
- case Intrinsic::aarch64_crc32cb:
- return tryCombineCRC32(0xff, N, DAG);
- case Intrinsic::aarch64_crc32h:
- case Intrinsic::aarch64_crc32ch:
- return tryCombineCRC32(0xffff, N, DAG);
- case Intrinsic::aarch64_sve_saddv:
-
- if (N->getOperand(2)->getValueType(0).getVectorElementType() == MVT::i64)
- return combineSVEReductionInt(N, AArch64ISD::UADDV_PRED, DAG);
- else
- return combineSVEReductionInt(N, AArch64ISD::SADDV_PRED, DAG);
- case Intrinsic::aarch64_sve_uaddv:
- return combineSVEReductionInt(N, AArch64ISD::UADDV_PRED, DAG);
- case Intrinsic::aarch64_sve_smaxv:
- return combineSVEReductionInt(N, AArch64ISD::SMAXV_PRED, DAG);
- case Intrinsic::aarch64_sve_umaxv:
- return combineSVEReductionInt(N, AArch64ISD::UMAXV_PRED, DAG);
- case Intrinsic::aarch64_sve_sminv:
- return combineSVEReductionInt(N, AArch64ISD::SMINV_PRED, DAG);
- case Intrinsic::aarch64_sve_uminv:
- return combineSVEReductionInt(N, AArch64ISD::UMINV_PRED, DAG);
- case Intrinsic::aarch64_sve_orv:
- return combineSVEReductionInt(N, AArch64ISD::ORV_PRED, DAG);
- case Intrinsic::aarch64_sve_eorv:
- return combineSVEReductionInt(N, AArch64ISD::EORV_PRED, DAG);
- case Intrinsic::aarch64_sve_andv:
- return combineSVEReductionInt(N, AArch64ISD::ANDV_PRED, DAG);
- case Intrinsic::aarch64_sve_index:
- return LowerSVEIntrinsicIndex(N, DAG);
- case Intrinsic::aarch64_sve_dup:
- return LowerSVEIntrinsicDUP(N, DAG);
- case Intrinsic::aarch64_sve_dup_x:
- return DAG.getNode(ISD::SPLAT_VECTOR, SDLoc(N), N->getValueType(0),
- N->getOperand(1));
- case Intrinsic::aarch64_sve_ext:
- return LowerSVEIntrinsicEXT(N, DAG);
- case Intrinsic::aarch64_sve_smin:
- return convertMergedOpToPredOp(N, AArch64ISD::SMIN_PRED, DAG);
- case Intrinsic::aarch64_sve_umin:
- return convertMergedOpToPredOp(N, AArch64ISD::UMIN_PRED, DAG);
- case Intrinsic::aarch64_sve_smax:
- return convertMergedOpToPredOp(N, AArch64ISD::SMAX_PRED, DAG);
- case Intrinsic::aarch64_sve_umax:
- return convertMergedOpToPredOp(N, AArch64ISD::UMAX_PRED, DAG);
- case Intrinsic::aarch64_sve_lsl:
- return convertMergedOpToPredOp(N, AArch64ISD::SHL_PRED, DAG);
- case Intrinsic::aarch64_sve_lsr:
- return convertMergedOpToPredOp(N, AArch64ISD::SRL_PRED, DAG);
- case Intrinsic::aarch64_sve_asr:
- return convertMergedOpToPredOp(N, AArch64ISD::SRA_PRED, DAG);
- case Intrinsic::aarch64_sve_cmphs:
- if (!N->getOperand(2).getValueType().isFloatingPoint())
- return DAG.getNode(AArch64ISD::SETCC_MERGE_ZERO, SDLoc(N),
- N->getValueType(0), N->getOperand(1), N->getOperand(2),
- N->getOperand(3), DAG.getCondCode(ISD::SETUGE));
- break;
- case Intrinsic::aarch64_sve_cmphi:
- if (!N->getOperand(2).getValueType().isFloatingPoint())
- return DAG.getNode(AArch64ISD::SETCC_MERGE_ZERO, SDLoc(N),
- N->getValueType(0), N->getOperand(1), N->getOperand(2),
- N->getOperand(3), DAG.getCondCode(ISD::SETUGT));
- break;
- case Intrinsic::aarch64_sve_cmpge:
- if (!N->getOperand(2).getValueType().isFloatingPoint())
- return DAG.getNode(AArch64ISD::SETCC_MERGE_ZERO, SDLoc(N),
- N->getValueType(0), N->getOperand(1), N->getOperand(2),
- N->getOperand(3), DAG.getCondCode(ISD::SETGE));
- break;
- case Intrinsic::aarch64_sve_cmpgt:
- if (!N->getOperand(2).getValueType().isFloatingPoint())
- return DAG.getNode(AArch64ISD::SETCC_MERGE_ZERO, SDLoc(N),
- N->getValueType(0), N->getOperand(1), N->getOperand(2),
- N->getOperand(3), DAG.getCondCode(ISD::SETGT));
- break;
- case Intrinsic::aarch64_sve_cmpeq:
- if (!N->getOperand(2).getValueType().isFloatingPoint())
- return DAG.getNode(AArch64ISD::SETCC_MERGE_ZERO, SDLoc(N),
- N->getValueType(0), N->getOperand(1), N->getOperand(2),
- N->getOperand(3), DAG.getCondCode(ISD::SETEQ));
- break;
- case Intrinsic::aarch64_sve_cmpne:
- if (!N->getOperand(2).getValueType().isFloatingPoint())
- return DAG.getNode(AArch64ISD::SETCC_MERGE_ZERO, SDLoc(N),
- N->getValueType(0), N->getOperand(1), N->getOperand(2),
- N->getOperand(3), DAG.getCondCode(ISD::SETNE));
- break;
- case Intrinsic::aarch64_sve_fadda:
- return combineSVEReductionOrderedFP(N, AArch64ISD::FADDA_PRED, DAG);
- case Intrinsic::aarch64_sve_faddv:
- return combineSVEReductionFP(N, AArch64ISD::FADDV_PRED, DAG);
- case Intrinsic::aarch64_sve_fmaxnmv:
- return combineSVEReductionFP(N, AArch64ISD::FMAXNMV_PRED, DAG);
- case Intrinsic::aarch64_sve_fmaxv:
- return combineSVEReductionFP(N, AArch64ISD::FMAXV_PRED, DAG);
- case Intrinsic::aarch64_sve_fminnmv:
- return combineSVEReductionFP(N, AArch64ISD::FMINNMV_PRED, DAG);
- case Intrinsic::aarch64_sve_fminv:
- return combineSVEReductionFP(N, AArch64ISD::FMINV_PRED, DAG);
- case Intrinsic::aarch64_sve_sel:
- return DAG.getNode(ISD::VSELECT, SDLoc(N), N->getValueType(0),
- N->getOperand(1), N->getOperand(2), N->getOperand(3));
- case Intrinsic::aarch64_sve_cmpeq_wide:
- return tryConvertSVEWideCompare(N, ISD::SETEQ, DCI, DAG);
- case Intrinsic::aarch64_sve_cmpne_wide:
- return tryConvertSVEWideCompare(N, ISD::SETNE, DCI, DAG);
- case Intrinsic::aarch64_sve_cmpge_wide:
- return tryConvertSVEWideCompare(N, ISD::SETGE, DCI, DAG);
- case Intrinsic::aarch64_sve_cmpgt_wide:
- return tryConvertSVEWideCompare(N, ISD::SETGT, DCI, DAG);
- case Intrinsic::aarch64_sve_cmplt_wide:
- return tryConvertSVEWideCompare(N, ISD::SETLT, DCI, DAG);
- case Intrinsic::aarch64_sve_cmple_wide:
- return tryConvertSVEWideCompare(N, ISD::SETLE, DCI, DAG);
- case Intrinsic::aarch64_sve_cmphs_wide:
- return tryConvertSVEWideCompare(N, ISD::SETUGE, DCI, DAG);
- case Intrinsic::aarch64_sve_cmphi_wide:
- return tryConvertSVEWideCompare(N, ISD::SETUGT, DCI, DAG);
- case Intrinsic::aarch64_sve_cmplo_wide:
- return tryConvertSVEWideCompare(N, ISD::SETULT, DCI, DAG);
- case Intrinsic::aarch64_sve_cmpls_wide:
- return tryConvertSVEWideCompare(N, ISD::SETULE, DCI, DAG);
- case Intrinsic::aarch64_sve_ptest_any:
- return getPTest(DAG, N->getValueType(0), N->getOperand(1), N->getOperand(2),
- AArch64CC::ANY_ACTIVE);
- case Intrinsic::aarch64_sve_ptest_first:
- return getPTest(DAG, N->getValueType(0), N->getOperand(1), N->getOperand(2),
- AArch64CC::FIRST_ACTIVE);
- case Intrinsic::aarch64_sve_ptest_last:
- return getPTest(DAG, N->getValueType(0), N->getOperand(1), N->getOperand(2),
- AArch64CC::LAST_ACTIVE);
- }
- return SDValue();
- }
- static SDValue performExtendCombine(SDNode *N,
- TargetLowering::DAGCombinerInfo &DCI,
- SelectionDAG &DAG) {
-
-
-
-
- if (!DCI.isBeforeLegalizeOps() && N->getOpcode() == ISD::ZERO_EXTEND &&
- (N->getOperand(0).getOpcode() == AArch64ISD::UABD ||
- N->getOperand(0).getOpcode() == AArch64ISD::SABD)) {
- SDNode *ABDNode = N->getOperand(0).getNode();
- SDValue NewABD =
- tryCombineLongOpWithDup(Intrinsic::not_intrinsic, ABDNode, DCI, DAG);
- if (!NewABD.getNode())
- return SDValue();
- return DAG.getNode(ISD::ZERO_EXTEND, SDLoc(N), N->getValueType(0), NewABD);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- if (!DCI.isBeforeLegalizeOps())
- return SDValue();
-
-
-
- const TargetLowering &TLI = DAG.getTargetLoweringInfo();
- EVT ResVT = N->getValueType(0);
- if (!ResVT.isVector() || TLI.isTypeLegal(ResVT))
- return SDValue();
-
-
-
- SDValue Src = N->getOperand(0);
- EVT SrcVT = Src->getValueType(0);
- if (!ResVT.isSimple() || !SrcVT.isSimple())
- return SDValue();
-
-
- if (SrcVT.getSizeInBits().getKnownMinSize() != 64)
- return SDValue();
- unsigned SrcEltSize = SrcVT.getScalarSizeInBits();
- ElementCount SrcEC = SrcVT.getVectorElementCount();
- SrcVT = MVT::getVectorVT(MVT::getIntegerVT(SrcEltSize * 2), SrcEC);
- SDLoc DL(N);
- Src = DAG.getNode(N->getOpcode(), DL, SrcVT, Src);
-
-
- EVT LoVT, HiVT;
- SDValue Lo, Hi;
- LoVT = HiVT = ResVT.getHalfNumVectorElementsVT(*DAG.getContext());
- EVT InNVT = EVT::getVectorVT(*DAG.getContext(), SrcVT.getVectorElementType(),
- LoVT.getVectorElementCount());
- Lo = DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, InNVT, Src,
- DAG.getConstant(0, DL, MVT::i64));
- Hi = DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, InNVT, Src,
- DAG.getConstant(InNVT.getVectorMinNumElements(), DL, MVT::i64));
- Lo = DAG.getNode(N->getOpcode(), DL, LoVT, Lo);
- Hi = DAG.getNode(N->getOpcode(), DL, HiVT, Hi);
-
-
- return DAG.getNode(ISD::CONCAT_VECTORS, DL, ResVT, Lo, Hi);
- }
- static SDValue splitStoreSplat(SelectionDAG &DAG, StoreSDNode &St,
- SDValue SplatVal, unsigned NumVecElts) {
- assert(!St.isTruncatingStore() && "cannot split truncating vector store");
- unsigned OrigAlignment = St.getAlignment();
- unsigned EltOffset = SplatVal.getValueType().getSizeInBits() / 8;
-
-
-
-
- SDLoc DL(&St);
- SDValue BasePtr = St.getBasePtr();
- uint64_t BaseOffset = 0;
- const MachinePointerInfo &PtrInfo = St.getPointerInfo();
- SDValue NewST1 =
- DAG.getStore(St.getChain(), DL, SplatVal, BasePtr, PtrInfo,
- OrigAlignment, St.getMemOperand()->getFlags());
-
- if (BasePtr->getOpcode() == ISD::ADD &&
- isa<ConstantSDNode>(BasePtr->getOperand(1))) {
- BaseOffset = cast<ConstantSDNode>(BasePtr->getOperand(1))->getSExtValue();
- BasePtr = BasePtr->getOperand(0);
- }
- unsigned Offset = EltOffset;
- while (--NumVecElts) {
- unsigned Alignment = MinAlign(OrigAlignment, Offset);
- SDValue OffsetPtr =
- DAG.getNode(ISD::ADD, DL, MVT::i64, BasePtr,
- DAG.getConstant(BaseOffset + Offset, DL, MVT::i64));
- NewST1 = DAG.getStore(NewST1.getValue(0), DL, SplatVal, OffsetPtr,
- PtrInfo.getWithOffset(Offset), Alignment,
- St.getMemOperand()->getFlags());
- Offset += EltOffset;
- }
- return NewST1;
- }
- static MVT getSVEContainerType(EVT ContentTy) {
- assert(ContentTy.isSimple() && "No SVE containers for extended types");
- switch (ContentTy.getSimpleVT().SimpleTy) {
- default:
- llvm_unreachable("No known SVE container for this MVT type");
- case MVT::nxv2i8:
- case MVT::nxv2i16:
- case MVT::nxv2i32:
- case MVT::nxv2i64:
- case MVT::nxv2f32:
- case MVT::nxv2f64:
- return MVT::nxv2i64;
- case MVT::nxv4i8:
- case MVT::nxv4i16:
- case MVT::nxv4i32:
- case MVT::nxv4f32:
- return MVT::nxv4i32;
- case MVT::nxv8i8:
- case MVT::nxv8i16:
- case MVT::nxv8f16:
- case MVT::nxv8bf16:
- return MVT::nxv8i16;
- case MVT::nxv16i8:
- return MVT::nxv16i8;
- }
- }
- static SDValue performLD1Combine(SDNode *N, SelectionDAG &DAG, unsigned Opc) {
- SDLoc DL(N);
- EVT VT = N->getValueType(0);
- if (VT.getSizeInBits().getKnownMinSize() > AArch64::SVEBitsPerBlock)
- return SDValue();
- EVT ContainerVT = VT;
- if (ContainerVT.isInteger())
- ContainerVT = getSVEContainerType(ContainerVT);
- SDVTList VTs = DAG.getVTList(ContainerVT, MVT::Other);
- SDValue Ops[] = { N->getOperand(0),
- N->getOperand(2),
- N->getOperand(3),
- DAG.getValueType(VT) };
- SDValue Load = DAG.getNode(Opc, DL, VTs, Ops);
- SDValue LoadChain = SDValue(Load.getNode(), 1);
- if (ContainerVT.isInteger() && (VT != ContainerVT))
- Load = DAG.getNode(ISD::TRUNCATE, DL, VT, Load.getValue(0));
- return DAG.getMergeValues({ Load, LoadChain }, DL);
- }
- static SDValue performLDNT1Combine(SDNode *N, SelectionDAG &DAG) {
- SDLoc DL(N);
- EVT VT = N->getValueType(0);
- EVT PtrTy = N->getOperand(3).getValueType();
- if (VT == MVT::nxv8bf16 &&
- !static_cast<const AArch64Subtarget &>(DAG.getSubtarget()).hasBF16())
- return SDValue();
- EVT LoadVT = VT;
- if (VT.isFloatingPoint())
- LoadVT = VT.changeTypeToInteger();
- auto *MINode = cast<MemIntrinsicSDNode>(N);
- SDValue PassThru = DAG.getConstant(0, DL, LoadVT);
- SDValue L = DAG.getMaskedLoad(LoadVT, DL, MINode->getChain(),
- MINode->getOperand(3), DAG.getUNDEF(PtrTy),
- MINode->getOperand(2), PassThru,
- MINode->getMemoryVT(), MINode->getMemOperand(),
- ISD::UNINDEXED, ISD::NON_EXTLOAD, false);
- if (VT.isFloatingPoint()) {
- SDValue Ops[] = { DAG.getNode(ISD::BITCAST, DL, VT, L), L.getValue(1) };
- return DAG.getMergeValues(Ops, DL);
- }
- return L;
- }
- template <unsigned Opcode>
- static SDValue performLD1ReplicateCombine(SDNode *N, SelectionDAG &DAG) {
- static_assert(Opcode == AArch64ISD::LD1RQ_MERGE_ZERO ||
- Opcode == AArch64ISD::LD1RO_MERGE_ZERO,
- "Unsupported opcode.");
- SDLoc DL(N);
- EVT VT = N->getValueType(0);
- if (VT == MVT::nxv8bf16 &&
- !static_cast<const AArch64Subtarget &>(DAG.getSubtarget()).hasBF16())
- return SDValue();
- EVT LoadVT = VT;
- if (VT.isFloatingPoint())
- LoadVT = VT.changeTypeToInteger();
- SDValue Ops[] = {N->getOperand(0), N->getOperand(2), N->getOperand(3)};
- SDValue Load = DAG.getNode(Opcode, DL, {LoadVT, MVT::Other}, Ops);
- SDValue LoadChain = SDValue(Load.getNode(), 1);
- if (VT.isFloatingPoint())
- Load = DAG.getNode(ISD::BITCAST, DL, VT, Load.getValue(0));
- return DAG.getMergeValues({Load, LoadChain}, DL);
- }
- static SDValue performST1Combine(SDNode *N, SelectionDAG &DAG) {
- SDLoc DL(N);
- SDValue Data = N->getOperand(2);
- EVT DataVT = Data.getValueType();
- EVT HwSrcVt = getSVEContainerType(DataVT);
- SDValue InputVT = DAG.getValueType(DataVT);
- if (DataVT == MVT::nxv8bf16 &&
- !static_cast<const AArch64Subtarget &>(DAG.getSubtarget()).hasBF16())
- return SDValue();
- if (DataVT.isFloatingPoint())
- InputVT = DAG.getValueType(HwSrcVt);
- SDValue SrcNew;
- if (Data.getValueType().isFloatingPoint())
- SrcNew = DAG.getNode(ISD::BITCAST, DL, HwSrcVt, Data);
- else
- SrcNew = DAG.getNode(ISD::ANY_EXTEND, DL, HwSrcVt, Data);
- SDValue Ops[] = { N->getOperand(0),
- SrcNew,
- N->getOperand(4),
- N->getOperand(3),
- InputVT
- };
- return DAG.getNode(AArch64ISD::ST1_PRED, DL, N->getValueType(0), Ops);
- }
- static SDValue performSTNT1Combine(SDNode *N, SelectionDAG &DAG) {
- SDLoc DL(N);
- SDValue Data = N->getOperand(2);
- EVT DataVT = Data.getValueType();
- EVT PtrTy = N->getOperand(4).getValueType();
- if (DataVT == MVT::nxv8bf16 &&
- !static_cast<const AArch64Subtarget &>(DAG.getSubtarget()).hasBF16())
- return SDValue();
- if (DataVT.isFloatingPoint())
- Data = DAG.getNode(ISD::BITCAST, DL, DataVT.changeTypeToInteger(), Data);
- auto *MINode = cast<MemIntrinsicSDNode>(N);
- return DAG.getMaskedStore(MINode->getChain(), DL, Data, MINode->getOperand(4),
- DAG.getUNDEF(PtrTy), MINode->getOperand(3),
- MINode->getMemoryVT(), MINode->getMemOperand(),
- ISD::UNINDEXED, false, false);
- }
- static SDValue replaceZeroVectorStore(SelectionDAG &DAG, StoreSDNode &St) {
- SDValue StVal = St.getValue();
- EVT VT = StVal.getValueType();
-
- if (VT.isScalableVector())
- return SDValue();
-
-
- int NumVecElts = VT.getVectorNumElements();
- if (!(((NumVecElts == 2 || NumVecElts == 3) &&
- VT.getVectorElementType().getSizeInBits() == 64) ||
- ((NumVecElts == 2 || NumVecElts == 3 || NumVecElts == 4) &&
- VT.getVectorElementType().getSizeInBits() == 32)))
- return SDValue();
- if (StVal.getOpcode() != ISD::BUILD_VECTOR)
- return SDValue();
-
-
-
- if (!StVal.hasOneUse())
- return SDValue();
-
-
- if (St.isTruncatingStore())
- return SDValue();
-
-
- if (DAG.isBaseWithConstantOffset(St.getBasePtr())) {
- int64_t Offset = St.getBasePtr()->getConstantOperandVal(1);
- if (Offset < -512 || Offset > 504)
- return SDValue();
- }
- for (int I = 0; I < NumVecElts; ++I) {
- SDValue EltVal = StVal.getOperand(I);
- if (!isNullConstant(EltVal) && !isNullFPConstant(EltVal))
- return SDValue();
- }
-
-
- SDLoc DL(&St);
- unsigned ZeroReg;
- EVT ZeroVT;
- if (VT.getVectorElementType().getSizeInBits() == 32) {
- ZeroReg = AArch64::WZR;
- ZeroVT = MVT::i32;
- } else {
- ZeroReg = AArch64::XZR;
- ZeroVT = MVT::i64;
- }
- SDValue SplatVal =
- DAG.getCopyFromReg(DAG.getEntryNode(), DL, ZeroReg, ZeroVT);
- return splitStoreSplat(DAG, St, SplatVal, NumVecElts);
- }
- static SDValue replaceSplatVectorStore(SelectionDAG &DAG, StoreSDNode &St) {
- SDValue StVal = St.getValue();
- EVT VT = StVal.getValueType();
-
-
- if (VT.isFloatingPoint())
- return SDValue();
-
- unsigned NumVecElts = VT.getVectorNumElements();
- if (NumVecElts != 4 && NumVecElts != 2)
- return SDValue();
-
-
- if (St.isTruncatingStore())
- return SDValue();
-
-
-
- std::bitset<4> IndexNotInserted((1 << NumVecElts) - 1);
- SDValue SplatVal;
- for (unsigned I = 0; I < NumVecElts; ++I) {
-
- if (StVal.getOpcode() != ISD::INSERT_VECTOR_ELT)
- return SDValue();
-
- if (I == 0)
- SplatVal = StVal.getOperand(1);
- else if (StVal.getOperand(1) != SplatVal)
- return SDValue();
-
- ConstantSDNode *CIndex = dyn_cast<ConstantSDNode>(StVal.getOperand(2));
- if (!CIndex)
- return SDValue();
- uint64_t IndexVal = CIndex->getZExtValue();
- if (IndexVal >= NumVecElts)
- return SDValue();
- IndexNotInserted.reset(IndexVal);
- StVal = StVal.getOperand(0);
- }
-
- if (IndexNotInserted.any())
- return SDValue();
- return splitStoreSplat(DAG, St, SplatVal, NumVecElts);
- }
- static SDValue splitStores(SDNode *N, TargetLowering::DAGCombinerInfo &DCI,
- SelectionDAG &DAG,
- const AArch64Subtarget *Subtarget) {
- StoreSDNode *S = cast<StoreSDNode>(N);
- if (S->isVolatile() || S->isIndexed())
- return SDValue();
- SDValue StVal = S->getValue();
- EVT VT = StVal.getValueType();
- if (!VT.isFixedLengthVector())
- return SDValue();
-
-
-
- if (SDValue ReplacedZeroSplat = replaceZeroVectorStore(DAG, *S))
- return ReplacedZeroSplat;
-
-
-
- if (!Subtarget->isMisaligned128StoreSlow())
- return SDValue();
-
- if (DAG.getMachineFunction().getFunction().hasMinSize())
- return SDValue();
-
-
- if (VT.getVectorNumElements() < 2 || VT == MVT::v2i64)
- return SDValue();
-
-
-
-
-
- if (VT.getSizeInBits() != 128 || S->getAlignment() >= 16 ||
- S->getAlignment() <= 2)
- return SDValue();
-
-
-
- if (SDValue ReplacedSplat = replaceSplatVectorStore(DAG, *S))
- return ReplacedSplat;
- SDLoc DL(S);
-
- EVT HalfVT = VT.getHalfNumVectorElementsVT(*DAG.getContext());
- unsigned NumElts = HalfVT.getVectorNumElements();
- SDValue SubVector0 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, HalfVT, StVal,
- DAG.getConstant(0, DL, MVT::i64));
- SDValue SubVector1 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, HalfVT, StVal,
- DAG.getConstant(NumElts, DL, MVT::i64));
- SDValue BasePtr = S->getBasePtr();
- SDValue NewST1 =
- DAG.getStore(S->getChain(), DL, SubVector0, BasePtr, S->getPointerInfo(),
- S->getAlignment(), S->getMemOperand()->getFlags());
- SDValue OffsetPtr = DAG.getNode(ISD::ADD, DL, MVT::i64, BasePtr,
- DAG.getConstant(8, DL, MVT::i64));
- return DAG.getStore(NewST1.getValue(0), DL, SubVector1, OffsetPtr,
- S->getPointerInfo(), S->getAlignment(),
- S->getMemOperand()->getFlags());
- }
- static SDValue performUzpCombine(SDNode *N, SelectionDAG &DAG) {
- SDLoc DL(N);
- SDValue Op0 = N->getOperand(0);
- SDValue Op1 = N->getOperand(1);
- EVT ResVT = N->getValueType(0);
-
- if (Op0.getOpcode() == AArch64ISD::UUNPKLO) {
- if (Op0.getOperand(0).getOpcode() == AArch64ISD::UZP1) {
- SDValue X = Op0.getOperand(0).getOperand(0);
- return DAG.getNode(AArch64ISD::UZP1, DL, ResVT, X, Op1);
- }
- }
-
- if (Op1.getOpcode() == AArch64ISD::UUNPKHI) {
- if (Op1.getOperand(0).getOpcode() == AArch64ISD::UZP1) {
- SDValue Z = Op1.getOperand(0).getOperand(1);
- return DAG.getNode(AArch64ISD::UZP1, DL, ResVT, Op0, Z);
- }
- }
- return SDValue();
- }
- static SDValue performPostLD1Combine(SDNode *N,
- TargetLowering::DAGCombinerInfo &DCI,
- bool IsLaneOp) {
- if (DCI.isBeforeLegalizeOps())
- return SDValue();
- SelectionDAG &DAG = DCI.DAG;
- EVT VT = N->getValueType(0);
- if (VT.isScalableVector())
- return SDValue();
- unsigned LoadIdx = IsLaneOp ? 1 : 0;
- SDNode *LD = N->getOperand(LoadIdx).getNode();
-
- if (LD->getOpcode() != ISD::LOAD)
- return SDValue();
-
- SDValue Lane;
- if (IsLaneOp) {
- Lane = N->getOperand(2);
- auto *LaneC = dyn_cast<ConstantSDNode>(Lane);
- if (!LaneC || LaneC->getZExtValue() >= VT.getVectorNumElements())
- return SDValue();
- }
- LoadSDNode *LoadSDN = cast<LoadSDNode>(LD);
- EVT MemVT = LoadSDN->getMemoryVT();
-
- if (MemVT != VT.getVectorElementType())
- return SDValue();
-
-
- for (SDNode::use_iterator UI = LD->use_begin(), UE = LD->use_end(); UI != UE;
- ++UI) {
- if (UI.getUse().getResNo() == 1)
- continue;
- if (*UI != N)
- return SDValue();
- }
- SDValue Addr = LD->getOperand(1);
- SDValue Vector = N->getOperand(0);
-
- for (SDNode::use_iterator UI = Addr.getNode()->use_begin(), UE =
- Addr.getNode()->use_end(); UI != UE; ++UI) {
- SDNode *User = *UI;
- if (User->getOpcode() != ISD::ADD
- || UI.getUse().getResNo() != Addr.getResNo())
- continue;
-
- SDValue Inc = User->getOperand(User->getOperand(0) == Addr ? 1 : 0);
- if (ConstantSDNode *CInc = dyn_cast<ConstantSDNode>(Inc.getNode())) {
- uint32_t IncVal = CInc->getZExtValue();
- unsigned NumBytes = VT.getScalarSizeInBits() / 8;
- if (IncVal != NumBytes)
- continue;
- Inc = DAG.getRegister(AArch64::XZR, MVT::i64);
- }
-
-
- SmallPtrSet<const SDNode *, 32> Visited;
- SmallVector<const SDNode *, 16> Worklist;
- Visited.insert(Addr.getNode());
- Worklist.push_back(User);
- Worklist.push_back(LD);
- Worklist.push_back(Vector.getNode());
- if (SDNode::hasPredecessorHelper(LD, Visited, Worklist) ||
- SDNode::hasPredecessorHelper(User, Visited, Worklist))
- continue;
- SmallVector<SDValue, 8> Ops;
- Ops.push_back(LD->getOperand(0));
- if (IsLaneOp) {
- Ops.push_back(Vector);
- Ops.push_back(Lane);
- }
- Ops.push_back(Addr);
- Ops.push_back(Inc);
- EVT Tys[3] = { VT, MVT::i64, MVT::Other };
- SDVTList SDTys = DAG.getVTList(Tys);
- unsigned NewOp = IsLaneOp ? AArch64ISD::LD1LANEpost : AArch64ISD::LD1DUPpost;
- SDValue UpdN = DAG.getMemIntrinsicNode(NewOp, SDLoc(N), SDTys, Ops,
- MemVT,
- LoadSDN->getMemOperand());
-
- SDValue NewResults[] = {
- SDValue(LD, 0),
- SDValue(UpdN.getNode(), 2)
- };
- DCI.CombineTo(LD, NewResults);
- DCI.CombineTo(N, SDValue(UpdN.getNode(), 0));
- DCI.CombineTo(User, SDValue(UpdN.getNode(), 1));
- break;
- }
- return SDValue();
- }
- static bool performTBISimplification(SDValue Addr,
- TargetLowering::DAGCombinerInfo &DCI,
- SelectionDAG &DAG) {
- APInt DemandedMask = APInt::getLowBitsSet(64, 56);
- KnownBits Known;
- TargetLowering::TargetLoweringOpt TLO(DAG, !DCI.isBeforeLegalize(),
- !DCI.isBeforeLegalizeOps());
- const TargetLowering &TLI = DAG.getTargetLoweringInfo();
- if (TLI.SimplifyDemandedBits(Addr, DemandedMask, Known, TLO)) {
- DCI.CommitTargetLoweringOpt(TLO);
- return true;
- }
- return false;
- }
- static SDValue performSTORECombine(SDNode *N,
- TargetLowering::DAGCombinerInfo &DCI,
- SelectionDAG &DAG,
- const AArch64Subtarget *Subtarget) {
- if (SDValue Split = splitStores(N, DCI, DAG, Subtarget))
- return Split;
- if (Subtarget->supportsAddressTopByteIgnored() &&
- performTBISimplification(N->getOperand(2), DCI, DAG))
- return SDValue(N, 0);
- return SDValue();
- }
- static SDValue performMaskedGatherScatterCombine(SDNode *N,
- TargetLowering::DAGCombinerInfo &DCI,
- SelectionDAG &DAG) {
- MaskedGatherScatterSDNode *MGS = cast<MaskedGatherScatterSDNode>(N);
- assert(MGS && "Can only combine gather load or scatter store nodes");
- SDLoc DL(MGS);
- SDValue Chain = MGS->getChain();
- SDValue Scale = MGS->getScale();
- SDValue Index = MGS->getIndex();
- SDValue Mask = MGS->getMask();
- SDValue BasePtr = MGS->getBasePtr();
- ISD::MemIndexType IndexType = MGS->getIndexType();
- EVT IdxVT = Index.getValueType();
- if (DCI.isBeforeLegalize()) {
-
-
- if ((IdxVT.getVectorElementType() == MVT::i8) ||
- (IdxVT.getVectorElementType() == MVT::i16)) {
- EVT NewIdxVT = IdxVT.changeVectorElementType(MVT::i32);
- if (MGS->isIndexSigned())
- Index = DAG.getNode(ISD::SIGN_EXTEND, DL, NewIdxVT, Index);
- else
- Index = DAG.getNode(ISD::ZERO_EXTEND, DL, NewIdxVT, Index);
- if (auto *MGT = dyn_cast<MaskedGatherSDNode>(MGS)) {
- SDValue PassThru = MGT->getPassThru();
- SDValue Ops[] = { Chain, PassThru, Mask, BasePtr, Index, Scale };
- return DAG.getMaskedGather(DAG.getVTList(N->getValueType(0), MVT::Other),
- PassThru.getValueType(), DL, Ops,
- MGT->getMemOperand(),
- MGT->getIndexType(), MGT->getExtensionType());
- } else {
- auto *MSC = cast<MaskedScatterSDNode>(MGS);
- SDValue Data = MSC->getValue();
- SDValue Ops[] = { Chain, Data, Mask, BasePtr, Index, Scale };
- return DAG.getMaskedScatter(DAG.getVTList(MVT::Other),
- MSC->getMemoryVT(), DL, Ops,
- MSC->getMemOperand(), IndexType,
- MSC->isTruncatingStore());
- }
- }
- }
- return SDValue();
- }
- static SDValue performNEONPostLDSTCombine(SDNode *N,
- TargetLowering::DAGCombinerInfo &DCI,
- SelectionDAG &DAG) {
- if (DCI.isBeforeLegalize() || DCI.isCalledByLegalizer())
- return SDValue();
- unsigned AddrOpIdx = N->getNumOperands() - 1;
- SDValue Addr = N->getOperand(AddrOpIdx);
-
- for (SDNode::use_iterator UI = Addr.getNode()->use_begin(),
- UE = Addr.getNode()->use_end(); UI != UE; ++UI) {
- SDNode *User = *UI;
- if (User->getOpcode() != ISD::ADD ||
- UI.getUse().getResNo() != Addr.getResNo())
- continue;
-
-
- SmallPtrSet<const SDNode *, 32> Visited;
- SmallVector<const SDNode *, 16> Worklist;
- Visited.insert(Addr.getNode());
- Worklist.push_back(N);
- Worklist.push_back(User);
- if (SDNode::hasPredecessorHelper(N, Visited, Worklist) ||
- SDNode::hasPredecessorHelper(User, Visited, Worklist))
- continue;
-
- bool IsStore = false;
- bool IsLaneOp = false;
- bool IsDupOp = false;
- unsigned NewOpc = 0;
- unsigned NumVecs = 0;
- unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
- switch (IntNo) {
- default: llvm_unreachable("unexpected intrinsic for Neon base update");
- case Intrinsic::aarch64_neon_ld2: NewOpc = AArch64ISD::LD2post;
- NumVecs = 2; break;
- case Intrinsic::aarch64_neon_ld3: NewOpc = AArch64ISD::LD3post;
- NumVecs = 3; break;
- case Intrinsic::aarch64_neon_ld4: NewOpc = AArch64ISD::LD4post;
- NumVecs = 4; break;
- case Intrinsic::aarch64_neon_st2: NewOpc = AArch64ISD::ST2post;
- NumVecs = 2; IsStore = true; break;
- case Intrinsic::aarch64_neon_st3: NewOpc = AArch64ISD::ST3post;
- NumVecs = 3; IsStore = true; break;
- case Intrinsic::aarch64_neon_st4: NewOpc = AArch64ISD::ST4post;
- NumVecs = 4; IsStore = true; break;
- case Intrinsic::aarch64_neon_ld1x2: NewOpc = AArch64ISD::LD1x2post;
- NumVecs = 2; break;
- case Intrinsic::aarch64_neon_ld1x3: NewOpc = AArch64ISD::LD1x3post;
- NumVecs = 3; break;
- case Intrinsic::aarch64_neon_ld1x4: NewOpc = AArch64ISD::LD1x4post;
- NumVecs = 4; break;
- case Intrinsic::aarch64_neon_st1x2: NewOpc = AArch64ISD::ST1x2post;
- NumVecs = 2; IsStore = true; break;
- case Intrinsic::aarch64_neon_st1x3: NewOpc = AArch64ISD::ST1x3post;
- NumVecs = 3; IsStore = true; break;
- case Intrinsic::aarch64_neon_st1x4: NewOpc = AArch64ISD::ST1x4post;
- NumVecs = 4; IsStore = true; break;
- case Intrinsic::aarch64_neon_ld2r: NewOpc = AArch64ISD::LD2DUPpost;
- NumVecs = 2; IsDupOp = true; break;
- case Intrinsic::aarch64_neon_ld3r: NewOpc = AArch64ISD::LD3DUPpost;
- NumVecs = 3; IsDupOp = true; break;
- case Intrinsic::aarch64_neon_ld4r: NewOpc = AArch64ISD::LD4DUPpost;
- NumVecs = 4; IsDupOp = true; break;
- case Intrinsic::aarch64_neon_ld2lane: NewOpc = AArch64ISD::LD2LANEpost;
- NumVecs = 2; IsLaneOp = true; break;
- case Intrinsic::aarch64_neon_ld3lane: NewOpc = AArch64ISD::LD3LANEpost;
- NumVecs = 3; IsLaneOp = true; break;
- case Intrinsic::aarch64_neon_ld4lane: NewOpc = AArch64ISD::LD4LANEpost;
- NumVecs = 4; IsLaneOp = true; break;
- case Intrinsic::aarch64_neon_st2lane: NewOpc = AArch64ISD::ST2LANEpost;
- NumVecs = 2; IsStore = true; IsLaneOp = true; break;
- case Intrinsic::aarch64_neon_st3lane: NewOpc = AArch64ISD::ST3LANEpost;
- NumVecs = 3; IsStore = true; IsLaneOp = true; break;
- case Intrinsic::aarch64_neon_st4lane: NewOpc = AArch64ISD::ST4LANEpost;
- NumVecs = 4; IsStore = true; IsLaneOp = true; break;
- }
- EVT VecTy;
- if (IsStore)
- VecTy = N->getOperand(2).getValueType();
- else
- VecTy = N->getValueType(0);
-
- SDValue Inc = User->getOperand(User->getOperand(0) == Addr ? 1 : 0);
- if (ConstantSDNode *CInc = dyn_cast<ConstantSDNode>(Inc.getNode())) {
- uint32_t IncVal = CInc->getZExtValue();
- unsigned NumBytes = NumVecs * VecTy.getSizeInBits() / 8;
- if (IsLaneOp || IsDupOp)
- NumBytes /= VecTy.getVectorNumElements();
- if (IncVal != NumBytes)
- continue;
- Inc = DAG.getRegister(AArch64::XZR, MVT::i64);
- }
- SmallVector<SDValue, 8> Ops;
- Ops.push_back(N->getOperand(0));
-
- if (IsLaneOp || IsStore)
- for (unsigned i = 2; i < AddrOpIdx; ++i)
- Ops.push_back(N->getOperand(i));
- Ops.push_back(Addr);
- Ops.push_back(Inc);
-
- EVT Tys[6];
- unsigned NumResultVecs = (IsStore ? 0 : NumVecs);
- unsigned n;
- for (n = 0; n < NumResultVecs; ++n)
- Tys[n] = VecTy;
- Tys[n++] = MVT::i64;
- Tys[n] = MVT::Other;
- SDVTList SDTys = DAG.getVTList(makeArrayRef(Tys, NumResultVecs + 2));
- MemIntrinsicSDNode *MemInt = cast<MemIntrinsicSDNode>(N);
- SDValue UpdN = DAG.getMemIntrinsicNode(NewOpc, SDLoc(N), SDTys, Ops,
- MemInt->getMemoryVT(),
- MemInt->getMemOperand());
-
- std::vector<SDValue> NewResults;
- for (unsigned i = 0; i < NumResultVecs; ++i) {
- NewResults.push_back(SDValue(UpdN.getNode(), i));
- }
- NewResults.push_back(SDValue(UpdN.getNode(), NumResultVecs + 1));
- DCI.CombineTo(N, NewResults);
- DCI.CombineTo(User, SDValue(UpdN.getNode(), NumResultVecs));
- break;
- }
- return SDValue();
- }
- static
- bool checkValueWidth(SDValue V, unsigned width, ISD::LoadExtType &ExtType) {
- ExtType = ISD::NON_EXTLOAD;
- switch(V.getNode()->getOpcode()) {
- default:
- return false;
- case ISD::LOAD: {
- LoadSDNode *LoadNode = cast<LoadSDNode>(V.getNode());
- if ((LoadNode->getMemoryVT() == MVT::i8 && width == 8)
- || (LoadNode->getMemoryVT() == MVT::i16 && width == 16)) {
- ExtType = LoadNode->getExtensionType();
- return true;
- }
- return false;
- }
- case ISD::AssertSext: {
- VTSDNode *TypeNode = cast<VTSDNode>(V.getNode()->getOperand(1));
- if ((TypeNode->getVT() == MVT::i8 && width == 8)
- || (TypeNode->getVT() == MVT::i16 && width == 16)) {
- ExtType = ISD::SEXTLOAD;
- return true;
- }
- return false;
- }
- case ISD::AssertZext: {
- VTSDNode *TypeNode = cast<VTSDNode>(V.getNode()->getOperand(1));
- if ((TypeNode->getVT() == MVT::i8 && width == 8)
- || (TypeNode->getVT() == MVT::i16 && width == 16)) {
- ExtType = ISD::ZEXTLOAD;
- return true;
- }
- return false;
- }
- case ISD::Constant:
- case ISD::TargetConstant: {
- return std::abs(cast<ConstantSDNode>(V.getNode())->getSExtValue()) <
- 1LL << (width - 1);
- }
- }
- return true;
- }
- static bool isEquivalentMaskless(unsigned CC, unsigned width,
- ISD::LoadExtType ExtType, int AddConstant,
- int CompConstant) {
-
-
-
- int MaxUInt = (1 << width);
-
-
-
-
-
- if (ExtType == ISD::SEXTLOAD)
- AddConstant -= (1 << (width-1));
- switch(CC) {
- case AArch64CC::LE:
- case AArch64CC::GT:
- if ((AddConstant == 0) ||
- (CompConstant == MaxUInt - 1 && AddConstant < 0) ||
- (AddConstant >= 0 && CompConstant < 0) ||
- (AddConstant <= 0 && CompConstant <= 0 && CompConstant < AddConstant))
- return true;
- break;
- case AArch64CC::LT:
- case AArch64CC::GE:
- if ((AddConstant == 0) ||
- (AddConstant >= 0 && CompConstant <= 0) ||
- (AddConstant <= 0 && CompConstant <= 0 && CompConstant <= AddConstant))
- return true;
- break;
- case AArch64CC::HI:
- case AArch64CC::LS:
- if ((AddConstant >= 0 && CompConstant < 0) ||
- (AddConstant <= 0 && CompConstant >= -1 &&
- CompConstant < AddConstant + MaxUInt))
- return true;
- break;
- case AArch64CC::PL:
- case AArch64CC::MI:
- if ((AddConstant == 0) ||
- (AddConstant > 0 && CompConstant <= 0) ||
- (AddConstant < 0 && CompConstant <= AddConstant))
- return true;
- break;
- case AArch64CC::LO:
- case AArch64CC::HS:
- if ((AddConstant >= 0 && CompConstant <= 0) ||
- (AddConstant <= 0 && CompConstant >= 0 &&
- CompConstant <= AddConstant + MaxUInt))
- return true;
- break;
- case AArch64CC::EQ:
- case AArch64CC::NE:
- if ((AddConstant > 0 && CompConstant < 0) ||
- (AddConstant < 0 && CompConstant >= 0 &&
- CompConstant < AddConstant + MaxUInt) ||
- (AddConstant >= 0 && CompConstant >= 0 &&
- CompConstant >= AddConstant) ||
- (AddConstant <= 0 && CompConstant < 0 && CompConstant < AddConstant))
- return true;
- break;
- case AArch64CC::VS:
- case AArch64CC::VC:
- case AArch64CC::AL:
- case AArch64CC::NV:
- return true;
- case AArch64CC::Invalid:
- break;
- }
- return false;
- }
- static
- SDValue performCONDCombine(SDNode *N,
- TargetLowering::DAGCombinerInfo &DCI,
- SelectionDAG &DAG, unsigned CCIndex,
- unsigned CmpIndex) {
- unsigned CC = cast<ConstantSDNode>(N->getOperand(CCIndex))->getSExtValue();
- SDNode *SubsNode = N->getOperand(CmpIndex).getNode();
- unsigned CondOpcode = SubsNode->getOpcode();
- if (CondOpcode != AArch64ISD::SUBS)
- return SDValue();
-
-
- SDNode *AndNode = SubsNode->getOperand(0).getNode();
- unsigned MaskBits = 0;
- if (AndNode->getOpcode() != ISD::AND)
- return SDValue();
- if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(AndNode->getOperand(1))) {
- uint32_t CNV = CN->getZExtValue();
- if (CNV == 255)
- MaskBits = 8;
- else if (CNV == 65535)
- MaskBits = 16;
- }
- if (!MaskBits)
- return SDValue();
- SDValue AddValue = AndNode->getOperand(0);
- if (AddValue.getOpcode() != ISD::ADD)
- return SDValue();
-
- SDValue AddInputValue1 = AddValue.getNode()->getOperand(0);
- SDValue AddInputValue2 = AddValue.getNode()->getOperand(1);
- SDValue SubsInputValue = SubsNode->getOperand(1);
-
-
- if (!isa<ConstantSDNode>(AddInputValue2.getNode()) ||
- !isa<ConstantSDNode>(SubsInputValue.getNode()))
- return SDValue();
- ISD::LoadExtType ExtType;
- if (!checkValueWidth(SubsInputValue, MaskBits, ExtType) ||
- !checkValueWidth(AddInputValue2, MaskBits, ExtType) ||
- !checkValueWidth(AddInputValue1, MaskBits, ExtType) )
- return SDValue();
- if(!isEquivalentMaskless(CC, MaskBits, ExtType,
- cast<ConstantSDNode>(AddInputValue2.getNode())->getSExtValue(),
- cast<ConstantSDNode>(SubsInputValue.getNode())->getSExtValue()))
- return SDValue();
-
- SDVTList VTs = DAG.getVTList(SubsNode->getValueType(0),
- SubsNode->getValueType(1));
- SDValue Ops[] = { AddValue, SubsNode->getOperand(1) };
- SDValue NewValue = DAG.getNode(CondOpcode, SDLoc(SubsNode), VTs, Ops);
- DAG.ReplaceAllUsesWith(SubsNode, NewValue.getNode());
- return SDValue(N, 0);
- }
- static SDValue performBRCONDCombine(SDNode *N,
- TargetLowering::DAGCombinerInfo &DCI,
- SelectionDAG &DAG) {
- MachineFunction &MF = DAG.getMachineFunction();
-
-
-
- if (MF.getFunction().hasFnAttribute(Attribute::SpeculativeLoadHardening))
- return SDValue();
- if (SDValue NV = performCONDCombine(N, DCI, DAG, 2, 3))
- N = NV.getNode();
- SDValue Chain = N->getOperand(0);
- SDValue Dest = N->getOperand(1);
- SDValue CCVal = N->getOperand(2);
- SDValue Cmp = N->getOperand(3);
- assert(isa<ConstantSDNode>(CCVal) && "Expected a ConstantSDNode here!");
- unsigned CC = cast<ConstantSDNode>(CCVal)->getZExtValue();
- if (CC != AArch64CC::EQ && CC != AArch64CC::NE)
- return SDValue();
- unsigned CmpOpc = Cmp.getOpcode();
- if (CmpOpc != AArch64ISD::ADDS && CmpOpc != AArch64ISD::SUBS)
- return SDValue();
-
-
- if (!Cmp->hasNUsesOfValue(0, 0) || !Cmp->hasNUsesOfValue(1, 1))
- return SDValue();
- SDValue LHS = Cmp.getOperand(0);
- SDValue RHS = Cmp.getOperand(1);
- assert(LHS.getValueType() == RHS.getValueType() &&
- "Expected the value type to be the same for both operands!");
- if (LHS.getValueType() != MVT::i32 && LHS.getValueType() != MVT::i64)
- return SDValue();
- if (isNullConstant(LHS))
- std::swap(LHS, RHS);
- if (!isNullConstant(RHS))
- return SDValue();
- if (LHS.getOpcode() == ISD::SHL || LHS.getOpcode() == ISD::SRA ||
- LHS.getOpcode() == ISD::SRL)
- return SDValue();
-
- SDValue BR;
- if (CC == AArch64CC::EQ)
- BR = DAG.getNode(AArch64ISD::CBZ, SDLoc(N), MVT::Other, Chain, LHS, Dest);
- else
- BR = DAG.getNode(AArch64ISD::CBNZ, SDLoc(N), MVT::Other, Chain, LHS, Dest);
-
- DCI.CombineTo(N, BR, false);
- return SDValue();
- }
- static SDValue getTestBitOperand(SDValue Op, unsigned &Bit, bool &Invert,
- SelectionDAG &DAG) {
- if (!Op->hasOneUse())
- return Op;
-
-
-
-
-
- if (Op->getOpcode() == ISD::TRUNCATE &&
- Bit < Op->getValueType(0).getSizeInBits()) {
- return getTestBitOperand(Op->getOperand(0), Bit, Invert, DAG);
- }
-
- if (Op->getOpcode() == ISD::ANY_EXTEND &&
- Bit < Op->getOperand(0).getValueSizeInBits()) {
- return getTestBitOperand(Op->getOperand(0), Bit, Invert, DAG);
- }
- if (Op->getNumOperands() != 2)
- return Op;
- auto *C = dyn_cast<ConstantSDNode>(Op->getOperand(1));
- if (!C)
- return Op;
- switch (Op->getOpcode()) {
- default:
- return Op;
-
- case ISD::AND:
- if ((C->getZExtValue() >> Bit) & 1)
- return getTestBitOperand(Op->getOperand(0), Bit, Invert, DAG);
- return Op;
-
- case ISD::SHL:
- if (C->getZExtValue() <= Bit &&
- (Bit - C->getZExtValue()) < Op->getValueType(0).getSizeInBits()) {
- Bit = Bit - C->getZExtValue();
- return getTestBitOperand(Op->getOperand(0), Bit, Invert, DAG);
- }
- return Op;
-
- case ISD::SRA:
- Bit = Bit + C->getZExtValue();
- if (Bit >= Op->getValueType(0).getSizeInBits())
- Bit = Op->getValueType(0).getSizeInBits() - 1;
- return getTestBitOperand(Op->getOperand(0), Bit, Invert, DAG);
-
- case ISD::SRL:
- if ((Bit + C->getZExtValue()) < Op->getValueType(0).getSizeInBits()) {
- Bit = Bit + C->getZExtValue();
- return getTestBitOperand(Op->getOperand(0), Bit, Invert, DAG);
- }
- return Op;
-
- case ISD::XOR:
- if ((C->getZExtValue() >> Bit) & 1)
- Invert = !Invert;
- return getTestBitOperand(Op->getOperand(0), Bit, Invert, DAG);
- }
- }
- static SDValue performTBZCombine(SDNode *N,
- TargetLowering::DAGCombinerInfo &DCI,
- SelectionDAG &DAG) {
- unsigned Bit = cast<ConstantSDNode>(N->getOperand(2))->getZExtValue();
- bool Invert = false;
- SDValue TestSrc = N->getOperand(1);
- SDValue NewTestSrc = getTestBitOperand(TestSrc, Bit, Invert, DAG);
- if (TestSrc == NewTestSrc)
- return SDValue();
- unsigned NewOpc = N->getOpcode();
- if (Invert) {
- if (NewOpc == AArch64ISD::TBZ)
- NewOpc = AArch64ISD::TBNZ;
- else {
- assert(NewOpc == AArch64ISD::TBNZ);
- NewOpc = AArch64ISD::TBZ;
- }
- }
- SDLoc DL(N);
- return DAG.getNode(NewOpc, DL, MVT::Other, N->getOperand(0), NewTestSrc,
- DAG.getConstant(Bit, DL, MVT::i64), N->getOperand(3));
- }
- static SDValue performVSelectCombine(SDNode *N, SelectionDAG &DAG) {
- SDValue N0 = N->getOperand(0);
- EVT CCVT = N0.getValueType();
- if (N0.getOpcode() != ISD::SETCC || CCVT.getVectorNumElements() != 1 ||
- CCVT.getVectorElementType() != MVT::i1)
- return SDValue();
- EVT ResVT = N->getValueType(0);
- EVT CmpVT = N0.getOperand(0).getValueType();
-
-
- if (ResVT.getSizeInBits() != CmpVT.getSizeInBits())
- return SDValue();
- SDValue IfTrue = N->getOperand(1);
- SDValue IfFalse = N->getOperand(2);
- SDValue SetCC =
- DAG.getSetCC(SDLoc(N), CmpVT.changeVectorElementTypeToInteger(),
- N0.getOperand(0), N0.getOperand(1),
- cast<CondCodeSDNode>(N0.getOperand(2))->get());
- return DAG.getNode(ISD::VSELECT, SDLoc(N), ResVT, SetCC,
- IfTrue, IfFalse);
- }
- static SDValue performSelectCombine(SDNode *N,
- TargetLowering::DAGCombinerInfo &DCI) {
- SelectionDAG &DAG = DCI.DAG;
- SDValue N0 = N->getOperand(0);
- EVT ResVT = N->getValueType(0);
- if (N0.getOpcode() != ISD::SETCC)
- return SDValue();
-
-
-
- assert((N0.getValueType() == MVT::i1 || N0.getValueType() == MVT::i32) &&
- "Scalar-SETCC feeding SELECT has unexpected result type!");
-
-
-
- EVT SrcVT = N0.getOperand(0).getValueType();
-
-
- if (SrcVT == MVT::i1)
- return SDValue();
- int NumMaskElts = ResVT.getSizeInBits() / SrcVT.getSizeInBits();
- if (!ResVT.isVector() || NumMaskElts == 0)
- return SDValue();
- SrcVT = EVT::getVectorVT(*DAG.getContext(), SrcVT, NumMaskElts);
- EVT CCVT = SrcVT.changeVectorElementTypeToInteger();
-
-
-
- if (CCVT.getSizeInBits() != ResVT.getSizeInBits())
- return SDValue();
-
- assert(DCI.isBeforeLegalize() ||
- DAG.getTargetLoweringInfo().isTypeLegal(SrcVT));
-
-
- SDLoc DL(N0);
- SDValue LHS =
- DAG.getNode(ISD::SCALAR_TO_VECTOR, DL, SrcVT, N0.getOperand(0));
- SDValue RHS =
- DAG.getNode(ISD::SCALAR_TO_VECTOR, DL, SrcVT, N0.getOperand(1));
- SDValue SetCC = DAG.getNode(ISD::SETCC, DL, CCVT, LHS, RHS, N0.getOperand(2));
-
- SmallVector<int, 8> DUPMask(CCVT.getVectorNumElements(), 0);
- SDValue Mask = DAG.getVectorShuffle(CCVT, DL, SetCC, SetCC, DUPMask);
- Mask = DAG.getNode(ISD::BITCAST, DL,
- ResVT.changeVectorElementTypeToInteger(), Mask);
- return DAG.getSelect(DL, ResVT, Mask, N->getOperand(1), N->getOperand(2));
- }
- static SDValue performNVCASTCombine(SDNode *N) {
- if (N->getValueType(0) == N->getOperand(0).getValueType())
- return N->getOperand(0);
- return SDValue();
- }
- static SDValue performGlobalAddressCombine(SDNode *N, SelectionDAG &DAG,
- const AArch64Subtarget *Subtarget,
- const TargetMachine &TM) {
- auto *GN = cast<GlobalAddressSDNode>(N);
- if (Subtarget->ClassifyGlobalReference(GN->getGlobal(), TM) !=
- AArch64II::MO_NO_FLAG)
- return SDValue();
- uint64_t MinOffset = -1ull;
- for (SDNode *N : GN->uses()) {
- if (N->getOpcode() != ISD::ADD)
- return SDValue();
- auto *C = dyn_cast<ConstantSDNode>(N->getOperand(0));
- if (!C)
- C = dyn_cast<ConstantSDNode>(N->getOperand(1));
- if (!C)
- return SDValue();
- MinOffset = std::min(MinOffset, C->getZExtValue());
- }
- uint64_t Offset = MinOffset + GN->getOffset();
-
-
-
- if (Offset <= uint64_t(GN->getOffset()))
- return SDValue();
-
-
-
-
-
-
-
-
- if (Offset >= (1 << 21))
- return SDValue();
- const GlobalValue *GV = GN->getGlobal();
- Type *T = GV->getValueType();
- if (!T->isSized() ||
- Offset > GV->getParent()->getDataLayout().getTypeAllocSize(T))
- return SDValue();
- SDLoc DL(GN);
- SDValue Result = DAG.getGlobalAddress(GV, DL, MVT::i64, Offset);
- return DAG.getNode(ISD::SUB, DL, MVT::i64, Result,
- DAG.getConstant(MinOffset, DL, MVT::i64));
- }
- static SDValue getScaledOffsetForBitWidth(SelectionDAG &DAG, SDValue Offset,
- SDLoc DL, unsigned BitWidth) {
- assert(Offset.getValueType().isScalableVector() &&
- "This method is only for scalable vectors of offsets");
- SDValue Shift = DAG.getConstant(Log2_32(BitWidth / 8), DL, MVT::i64);
- SDValue SplatShift = DAG.getNode(ISD::SPLAT_VECTOR, DL, MVT::nxv2i64, Shift);
- return DAG.getNode(ISD::SHL, DL, MVT::nxv2i64, Offset, SplatShift);
- }
- inline static bool isValidImmForSVEVecImmAddrMode(unsigned OffsetInBytes,
- unsigned ScalarSizeInBytes) {
-
- if (OffsetInBytes % ScalarSizeInBytes)
- return false;
-
- if (OffsetInBytes / ScalarSizeInBytes > 31)
- return false;
- return true;
- }
- static bool isValidImmForSVEVecImmAddrMode(SDValue Offset,
- unsigned ScalarSizeInBytes) {
- ConstantSDNode *OffsetConst = dyn_cast<ConstantSDNode>(Offset.getNode());
- return OffsetConst && isValidImmForSVEVecImmAddrMode(
- OffsetConst->getZExtValue(), ScalarSizeInBytes);
- }
- static SDValue performScatterStoreCombine(SDNode *N, SelectionDAG &DAG,
- unsigned Opcode,
- bool OnlyPackedOffsets = true) {
- const SDValue Src = N->getOperand(2);
- const EVT SrcVT = Src->getValueType(0);
- assert(SrcVT.isScalableVector() &&
- "Scatter stores are only possible for SVE vectors");
- SDLoc DL(N);
- MVT SrcElVT = SrcVT.getVectorElementType().getSimpleVT();
-
- if (SrcVT.getSizeInBits().getKnownMinSize() > AArch64::SVEBitsPerBlock)
- return SDValue();
-
- if (SrcElVT.isFloatingPoint())
- if ((SrcVT != MVT::nxv4f32) && (SrcVT != MVT::nxv2f64))
- return SDValue();
-
-
- SDValue Base = N->getOperand(4);
-
-
- SDValue Offset = N->getOperand(5);
-
-
-
- if (Opcode == AArch64ISD::SSTNT1_INDEX_PRED) {
- Offset =
- getScaledOffsetForBitWidth(DAG, Offset, DL, SrcElVT.getSizeInBits());
- Opcode = AArch64ISD::SSTNT1_PRED;
- }
-
-
-
-
-
- if (Opcode == AArch64ISD::SSTNT1_PRED && Offset.getValueType().isVector())
- std::swap(Base, Offset);
-
-
-
-
-
-
- if (Opcode == AArch64ISD::SST1_IMM_PRED) {
- if (!isValidImmForSVEVecImmAddrMode(Offset,
- SrcVT.getScalarSizeInBits() / 8)) {
- if (MVT::nxv4i32 == Base.getValueType().getSimpleVT().SimpleTy)
- Opcode = AArch64ISD::SST1_UXTW_PRED;
- else
- Opcode = AArch64ISD::SST1_PRED;
- std::swap(Base, Offset);
- }
- }
- auto &TLI = DAG.getTargetLoweringInfo();
- if (!TLI.isTypeLegal(Base.getValueType()))
- return SDValue();
-
-
-
- if (!OnlyPackedOffsets &&
- Offset.getValueType().getSimpleVT().SimpleTy == MVT::nxv2i32)
- Offset = DAG.getNode(ISD::ANY_EXTEND, DL, MVT::nxv2i64, Offset).getValue(0);
- if (!TLI.isTypeLegal(Offset.getValueType()))
- return SDValue();
-
- EVT HwSrcVt = getSVEContainerType(SrcVT);
-
-
-
- SDValue InputVT = DAG.getValueType(SrcVT);
- if (SrcVT.isFloatingPoint())
- InputVT = DAG.getValueType(HwSrcVt);
- SDVTList VTs = DAG.getVTList(MVT::Other);
- SDValue SrcNew;
- if (Src.getValueType().isFloatingPoint())
- SrcNew = DAG.getNode(ISD::BITCAST, DL, HwSrcVt, Src);
- else
- SrcNew = DAG.getNode(ISD::ANY_EXTEND, DL, HwSrcVt, Src);
- SDValue Ops[] = {N->getOperand(0),
- SrcNew,
- N->getOperand(3),
- Base,
- Offset,
- InputVT};
- return DAG.getNode(Opcode, DL, VTs, Ops);
- }
- static SDValue performGatherLoadCombine(SDNode *N, SelectionDAG &DAG,
- unsigned Opcode,
- bool OnlyPackedOffsets = true) {
- const EVT RetVT = N->getValueType(0);
- assert(RetVT.isScalableVector() &&
- "Gather loads are only possible for SVE vectors");
- SDLoc DL(N);
-
- if (RetVT.getSizeInBits().getKnownMinSize() > AArch64::SVEBitsPerBlock)
- return SDValue();
-
-
- SDValue Base = N->getOperand(3);
-
-
- SDValue Offset = N->getOperand(4);
-
-
-
- if (Opcode == AArch64ISD::GLDNT1_INDEX_MERGE_ZERO) {
- Offset = getScaledOffsetForBitWidth(DAG, Offset, DL,
- RetVT.getScalarSizeInBits());
- Opcode = AArch64ISD::GLDNT1_MERGE_ZERO;
- }
-
-
-
-
-
- if (Opcode == AArch64ISD::GLDNT1_MERGE_ZERO &&
- Offset.getValueType().isVector())
- std::swap(Base, Offset);
-
-
-
-
-
-
- if (Opcode == AArch64ISD::GLD1_IMM_MERGE_ZERO ||
- Opcode == AArch64ISD::GLDFF1_IMM_MERGE_ZERO) {
- if (!isValidImmForSVEVecImmAddrMode(Offset,
- RetVT.getScalarSizeInBits() / 8)) {
- if (MVT::nxv4i32 == Base.getValueType().getSimpleVT().SimpleTy)
- Opcode = (Opcode == AArch64ISD::GLD1_IMM_MERGE_ZERO)
- ? AArch64ISD::GLD1_UXTW_MERGE_ZERO
- : AArch64ISD::GLDFF1_UXTW_MERGE_ZERO;
- else
- Opcode = (Opcode == AArch64ISD::GLD1_IMM_MERGE_ZERO)
- ? AArch64ISD::GLD1_MERGE_ZERO
- : AArch64ISD::GLDFF1_MERGE_ZERO;
- std::swap(Base, Offset);
- }
- }
- auto &TLI = DAG.getTargetLoweringInfo();
- if (!TLI.isTypeLegal(Base.getValueType()))
- return SDValue();
-
-
-
- if (!OnlyPackedOffsets &&
- Offset.getValueType().getSimpleVT().SimpleTy == MVT::nxv2i32)
- Offset = DAG.getNode(ISD::ANY_EXTEND, DL, MVT::nxv2i64, Offset).getValue(0);
-
- EVT HwRetVt = getSVEContainerType(RetVT);
-
-
-
- SDValue OutVT = DAG.getValueType(RetVT);
- if (RetVT.isFloatingPoint())
- OutVT = DAG.getValueType(HwRetVt);
- SDVTList VTs = DAG.getVTList(HwRetVt, MVT::Other);
- SDValue Ops[] = {N->getOperand(0),
- N->getOperand(2),
- Base, Offset, OutVT};
- SDValue Load = DAG.getNode(Opcode, DL, VTs, Ops);
- SDValue LoadChain = SDValue(Load.getNode(), 1);
- if (RetVT.isInteger() && (RetVT != HwRetVt))
- Load = DAG.getNode(ISD::TRUNCATE, DL, RetVT, Load.getValue(0));
-
-
- if (RetVT.isFloatingPoint())
- Load = DAG.getNode(ISD::BITCAST, DL, RetVT, Load.getValue(0));
- return DAG.getMergeValues({Load, LoadChain}, DL);
- }
- static SDValue
- performSignExtendInRegCombine(SDNode *N, TargetLowering::DAGCombinerInfo &DCI,
- SelectionDAG &DAG) {
- SDLoc DL(N);
- SDValue Src = N->getOperand(0);
- unsigned Opc = Src->getOpcode();
-
- if (Opc == AArch64ISD::UUNPKHI || Opc == AArch64ISD::UUNPKLO) {
- unsigned SOpc = Opc == AArch64ISD::UUNPKHI ? AArch64ISD::SUNPKHI
- : AArch64ISD::SUNPKLO;
-
-
-
-
-
-
-
-
- SDValue ExtOp = Src->getOperand(0);
- auto VT = cast<VTSDNode>(N->getOperand(1))->getVT();
- EVT EltTy = VT.getVectorElementType();
- (void)EltTy;
- assert((EltTy == MVT::i8 || EltTy == MVT::i16 || EltTy == MVT::i32) &&
- "Sign extending from an invalid type");
- EVT ExtVT = VT.getDoubleNumVectorElementsVT(*DAG.getContext());
- SDValue Ext = DAG.getNode(ISD::SIGN_EXTEND_INREG, DL, ExtOp.getValueType(),
- ExtOp, DAG.getValueType(ExtVT));
- return DAG.getNode(SOpc, DL, N->getValueType(0), Ext);
- }
- if (DCI.isBeforeLegalizeOps())
- return SDValue();
- if (!EnableCombineMGatherIntrinsics)
- return SDValue();
-
-
- unsigned NewOpc;
- unsigned MemVTOpNum = 4;
- switch (Opc) {
- case AArch64ISD::LD1_MERGE_ZERO:
- NewOpc = AArch64ISD::LD1S_MERGE_ZERO;
- MemVTOpNum = 3;
- break;
- case AArch64ISD::LDNF1_MERGE_ZERO:
- NewOpc = AArch64ISD::LDNF1S_MERGE_ZERO;
- MemVTOpNum = 3;
- break;
- case AArch64ISD::LDFF1_MERGE_ZERO:
- NewOpc = AArch64ISD::LDFF1S_MERGE_ZERO;
- MemVTOpNum = 3;
- break;
- case AArch64ISD::GLD1_MERGE_ZERO:
- NewOpc = AArch64ISD::GLD1S_MERGE_ZERO;
- break;
- case AArch64ISD::GLD1_SCALED_MERGE_ZERO:
- NewOpc = AArch64ISD::GLD1S_SCALED_MERGE_ZERO;
- break;
- case AArch64ISD::GLD1_SXTW_MERGE_ZERO:
- NewOpc = AArch64ISD::GLD1S_SXTW_MERGE_ZERO;
- break;
- case AArch64ISD::GLD1_SXTW_SCALED_MERGE_ZERO:
- NewOpc = AArch64ISD::GLD1S_SXTW_SCALED_MERGE_ZERO;
- break;
- case AArch64ISD::GLD1_UXTW_MERGE_ZERO:
- NewOpc = AArch64ISD::GLD1S_UXTW_MERGE_ZERO;
- break;
- case AArch64ISD::GLD1_UXTW_SCALED_MERGE_ZERO:
- NewOpc = AArch64ISD::GLD1S_UXTW_SCALED_MERGE_ZERO;
- break;
- case AArch64ISD::GLD1_IMM_MERGE_ZERO:
- NewOpc = AArch64ISD::GLD1S_IMM_MERGE_ZERO;
- break;
- case AArch64ISD::GLDFF1_MERGE_ZERO:
- NewOpc = AArch64ISD::GLDFF1S_MERGE_ZERO;
- break;
- case AArch64ISD::GLDFF1_SCALED_MERGE_ZERO:
- NewOpc = AArch64ISD::GLDFF1S_SCALED_MERGE_ZERO;
- break;
- case AArch64ISD::GLDFF1_SXTW_MERGE_ZERO:
- NewOpc = AArch64ISD::GLDFF1S_SXTW_MERGE_ZERO;
- break;
- case AArch64ISD::GLDFF1_SXTW_SCALED_MERGE_ZERO:
- NewOpc = AArch64ISD::GLDFF1S_SXTW_SCALED_MERGE_ZERO;
- break;
- case AArch64ISD::GLDFF1_UXTW_MERGE_ZERO:
- NewOpc = AArch64ISD::GLDFF1S_UXTW_MERGE_ZERO;
- break;
- case AArch64ISD::GLDFF1_UXTW_SCALED_MERGE_ZERO:
- NewOpc = AArch64ISD::GLDFF1S_UXTW_SCALED_MERGE_ZERO;
- break;
- case AArch64ISD::GLDFF1_IMM_MERGE_ZERO:
- NewOpc = AArch64ISD::GLDFF1S_IMM_MERGE_ZERO;
- break;
- case AArch64ISD::GLDNT1_MERGE_ZERO:
- NewOpc = AArch64ISD::GLDNT1S_MERGE_ZERO;
- break;
- default:
- return SDValue();
- }
- EVT SignExtSrcVT = cast<VTSDNode>(N->getOperand(1))->getVT();
- EVT SrcMemVT = cast<VTSDNode>(Src->getOperand(MemVTOpNum))->getVT();
- if ((SignExtSrcVT != SrcMemVT) || !Src.hasOneUse())
- return SDValue();
- EVT DstVT = N->getValueType(0);
- SDVTList VTs = DAG.getVTList(DstVT, MVT::Other);
- SmallVector<SDValue, 5> Ops;
- for (unsigned I = 0; I < Src->getNumOperands(); ++I)
- Ops.push_back(Src->getOperand(I));
- SDValue ExtLoad = DAG.getNode(NewOpc, SDLoc(N), VTs, Ops);
- DCI.CombineTo(N, ExtLoad);
- DCI.CombineTo(Src.getNode(), ExtLoad, ExtLoad.getValue(1));
-
- return SDValue(N, 0);
- }
- static SDValue legalizeSVEGatherPrefetchOffsVec(SDNode *N, SelectionDAG &DAG) {
- const unsigned OffsetPos = 4;
- SDValue Offset = N->getOperand(OffsetPos);
-
- if (Offset.getValueType().getSimpleVT().SimpleTy != MVT::nxv2i32)
- return SDValue();
-
- SDLoc DL(N);
- Offset = DAG.getNode(ISD::ANY_EXTEND, DL, MVT::nxv2i64, Offset);
- SmallVector<SDValue, 5> Ops(N->op_begin(), N->op_end());
-
- Ops[OffsetPos] = Offset;
- return DAG.getNode(N->getOpcode(), DL, DAG.getVTList(MVT::Other), Ops);
- }
- static SDValue combineSVEPrefetchVecBaseImmOff(SDNode *N, SelectionDAG &DAG,
- unsigned ScalarSizeInBytes) {
- const unsigned ImmPos = 4, OffsetPos = 3;
-
- if (isValidImmForSVEVecImmAddrMode(N->getOperand(ImmPos), ScalarSizeInBytes))
- return SDValue();
-
- SmallVector<SDValue, 5> Ops(N->op_begin(), N->op_end());
- std::swap(Ops[ImmPos], Ops[OffsetPos]);
-
-
- SDLoc DL(N);
- Ops[1] = DAG.getConstant(Intrinsic::aarch64_sve_prfb_gather_uxtw_index, DL,
- MVT::i64);
- return DAG.getNode(N->getOpcode(), DL, DAG.getVTList(MVT::Other), Ops);
- }
- SDValue AArch64TargetLowering::PerformDAGCombine(SDNode *N,
- DAGCombinerInfo &DCI) const {
- SelectionDAG &DAG = DCI.DAG;
- switch (N->getOpcode()) {
- default:
- LLVM_DEBUG(dbgs() << "Custom combining: skipping\n");
- break;
- case ISD::ABS:
- return performABSCombine(N, DAG, DCI, Subtarget);
- case ISD::ADD:
- case ISD::SUB:
- return performAddSubCombine(N, DCI, DAG);
- case ISD::XOR:
- return performXorCombine(N, DAG, DCI, Subtarget);
- case ISD::MUL:
- return performMulCombine(N, DAG, DCI, Subtarget);
- case ISD::SINT_TO_FP:
- case ISD::UINT_TO_FP:
- return performIntToFpCombine(N, DAG, Subtarget);
- case ISD::FP_TO_SINT:
- case ISD::FP_TO_UINT:
- return performFpToIntCombine(N, DAG, DCI, Subtarget);
- case ISD::FDIV:
- return performFDivCombine(N, DAG, DCI, Subtarget);
- case ISD::OR:
- return performORCombine(N, DCI, Subtarget);
- case ISD::AND:
- return performANDCombine(N, DCI);
- case ISD::SRL:
- return performSRLCombine(N, DCI);
- case ISD::INTRINSIC_WO_CHAIN:
- return performIntrinsicCombine(N, DCI, Subtarget);
- case ISD::ANY_EXTEND:
- case ISD::ZERO_EXTEND:
- case ISD::SIGN_EXTEND:
- return performExtendCombine(N, DCI, DAG);
- case ISD::SIGN_EXTEND_INREG:
- return performSignExtendInRegCombine(N, DCI, DAG);
- case ISD::TRUNCATE:
- return performVectorTruncateCombine(N, DCI, DAG);
- case ISD::CONCAT_VECTORS:
- return performConcatVectorsCombine(N, DCI, DAG);
- case ISD::SELECT:
- return performSelectCombine(N, DCI);
- case ISD::VSELECT:
- return performVSelectCombine(N, DCI.DAG);
- case ISD::LOAD:
- if (performTBISimplification(N->getOperand(1), DCI, DAG))
- return SDValue(N, 0);
- break;
- case ISD::STORE:
- return performSTORECombine(N, DCI, DAG, Subtarget);
- case ISD::MGATHER:
- case ISD::MSCATTER:
- return performMaskedGatherScatterCombine(N, DCI, DAG);
- case AArch64ISD::BRCOND:
- return performBRCONDCombine(N, DCI, DAG);
- case AArch64ISD::TBNZ:
- case AArch64ISD::TBZ:
- return performTBZCombine(N, DCI, DAG);
- case AArch64ISD::CSEL:
- return performCONDCombine(N, DCI, DAG, 2, 3);
- case AArch64ISD::DUP:
- return performPostLD1Combine(N, DCI, false);
- case AArch64ISD::NVCAST:
- return performNVCASTCombine(N);
- case AArch64ISD::UZP1:
- return performUzpCombine(N, DAG);
- case ISD::INSERT_VECTOR_ELT:
- return performPostLD1Combine(N, DCI, true);
- case ISD::EXTRACT_VECTOR_ELT:
- return performExtractVectorEltCombine(N, DAG);
- case ISD::VECREDUCE_ADD:
- return performVecReduceAddCombine(N, DCI.DAG, Subtarget);
- case ISD::INTRINSIC_VOID:
- case ISD::INTRINSIC_W_CHAIN:
- switch (cast<ConstantSDNode>(N->getOperand(1))->getZExtValue()) {
- case Intrinsic::aarch64_sve_prfb_gather_scalar_offset:
- return combineSVEPrefetchVecBaseImmOff(N, DAG, 1 );
- case Intrinsic::aarch64_sve_prfh_gather_scalar_offset:
- return combineSVEPrefetchVecBaseImmOff(N, DAG, 2 );
- case Intrinsic::aarch64_sve_prfw_gather_scalar_offset:
- return combineSVEPrefetchVecBaseImmOff(N, DAG, 4 );
- case Intrinsic::aarch64_sve_prfd_gather_scalar_offset:
- return combineSVEPrefetchVecBaseImmOff(N, DAG, 8 );
- case Intrinsic::aarch64_sve_prfb_gather_uxtw_index:
- case Intrinsic::aarch64_sve_prfb_gather_sxtw_index:
- case Intrinsic::aarch64_sve_prfh_gather_uxtw_index:
- case Intrinsic::aarch64_sve_prfh_gather_sxtw_index:
- case Intrinsic::aarch64_sve_prfw_gather_uxtw_index:
- case Intrinsic::aarch64_sve_prfw_gather_sxtw_index:
- case Intrinsic::aarch64_sve_prfd_gather_uxtw_index:
- case Intrinsic::aarch64_sve_prfd_gather_sxtw_index:
- return legalizeSVEGatherPrefetchOffsVec(N, DAG);
- case Intrinsic::aarch64_neon_ld2:
- case Intrinsic::aarch64_neon_ld3:
- case Intrinsic::aarch64_neon_ld4:
- case Intrinsic::aarch64_neon_ld1x2:
- case Intrinsic::aarch64_neon_ld1x3:
- case Intrinsic::aarch64_neon_ld1x4:
- case Intrinsic::aarch64_neon_ld2lane:
- case Intrinsic::aarch64_neon_ld3lane:
- case Intrinsic::aarch64_neon_ld4lane:
- case Intrinsic::aarch64_neon_ld2r:
- case Intrinsic::aarch64_neon_ld3r:
- case Intrinsic::aarch64_neon_ld4r:
- case Intrinsic::aarch64_neon_st2:
- case Intrinsic::aarch64_neon_st3:
- case Intrinsic::aarch64_neon_st4:
- case Intrinsic::aarch64_neon_st1x2:
- case Intrinsic::aarch64_neon_st1x3:
- case Intrinsic::aarch64_neon_st1x4:
- case Intrinsic::aarch64_neon_st2lane:
- case Intrinsic::aarch64_neon_st3lane:
- case Intrinsic::aarch64_neon_st4lane:
- return performNEONPostLDSTCombine(N, DCI, DAG);
- case Intrinsic::aarch64_sve_ldnt1:
- return performLDNT1Combine(N, DAG);
- case Intrinsic::aarch64_sve_ld1rq:
- return performLD1ReplicateCombine<AArch64ISD::LD1RQ_MERGE_ZERO>(N, DAG);
- case Intrinsic::aarch64_sve_ld1ro:
- return performLD1ReplicateCombine<AArch64ISD::LD1RO_MERGE_ZERO>(N, DAG);
- case Intrinsic::aarch64_sve_ldnt1_gather_scalar_offset:
- return performGatherLoadCombine(N, DAG, AArch64ISD::GLDNT1_MERGE_ZERO);
- case Intrinsic::aarch64_sve_ldnt1_gather:
- return performGatherLoadCombine(N, DAG, AArch64ISD::GLDNT1_MERGE_ZERO);
- case Intrinsic::aarch64_sve_ldnt1_gather_index:
- return performGatherLoadCombine(N, DAG,
- AArch64ISD::GLDNT1_INDEX_MERGE_ZERO);
- case Intrinsic::aarch64_sve_ldnt1_gather_uxtw:
- return performGatherLoadCombine(N, DAG, AArch64ISD::GLDNT1_MERGE_ZERO);
- case Intrinsic::aarch64_sve_ld1:
- return performLD1Combine(N, DAG, AArch64ISD::LD1_MERGE_ZERO);
- case Intrinsic::aarch64_sve_ldnf1:
- return performLD1Combine(N, DAG, AArch64ISD::LDNF1_MERGE_ZERO);
- case Intrinsic::aarch64_sve_ldff1:
- return performLD1Combine(N, DAG, AArch64ISD::LDFF1_MERGE_ZERO);
- case Intrinsic::aarch64_sve_st1:
- return performST1Combine(N, DAG);
- case Intrinsic::aarch64_sve_stnt1:
- return performSTNT1Combine(N, DAG);
- case Intrinsic::aarch64_sve_stnt1_scatter_scalar_offset:
- return performScatterStoreCombine(N, DAG, AArch64ISD::SSTNT1_PRED);
- case Intrinsic::aarch64_sve_stnt1_scatter_uxtw:
- return performScatterStoreCombine(N, DAG, AArch64ISD::SSTNT1_PRED);
- case Intrinsic::aarch64_sve_stnt1_scatter:
- return performScatterStoreCombine(N, DAG, AArch64ISD::SSTNT1_PRED);
- case Intrinsic::aarch64_sve_stnt1_scatter_index:
- return performScatterStoreCombine(N, DAG, AArch64ISD::SSTNT1_INDEX_PRED);
- case Intrinsic::aarch64_sve_ld1_gather:
- return performGatherLoadCombine(N, DAG, AArch64ISD::GLD1_MERGE_ZERO);
- case Intrinsic::aarch64_sve_ld1_gather_index:
- return performGatherLoadCombine(N, DAG,
- AArch64ISD::GLD1_SCALED_MERGE_ZERO);
- case Intrinsic::aarch64_sve_ld1_gather_sxtw:
- return performGatherLoadCombine(N, DAG, AArch64ISD::GLD1_SXTW_MERGE_ZERO,
- false);
- case Intrinsic::aarch64_sve_ld1_gather_uxtw:
- return performGatherLoadCombine(N, DAG, AArch64ISD::GLD1_UXTW_MERGE_ZERO,
- false);
- case Intrinsic::aarch64_sve_ld1_gather_sxtw_index:
- return performGatherLoadCombine(N, DAG,
- AArch64ISD::GLD1_SXTW_SCALED_MERGE_ZERO,
- false);
- case Intrinsic::aarch64_sve_ld1_gather_uxtw_index:
- return performGatherLoadCombine(N, DAG,
- AArch64ISD::GLD1_UXTW_SCALED_MERGE_ZERO,
- false);
- case Intrinsic::aarch64_sve_ld1_gather_scalar_offset:
- return performGatherLoadCombine(N, DAG, AArch64ISD::GLD1_IMM_MERGE_ZERO);
- case Intrinsic::aarch64_sve_ldff1_gather:
- return performGatherLoadCombine(N, DAG, AArch64ISD::GLDFF1_MERGE_ZERO);
- case Intrinsic::aarch64_sve_ldff1_gather_index:
- return performGatherLoadCombine(N, DAG,
- AArch64ISD::GLDFF1_SCALED_MERGE_ZERO);
- case Intrinsic::aarch64_sve_ldff1_gather_sxtw:
- return performGatherLoadCombine(N, DAG,
- AArch64ISD::GLDFF1_SXTW_MERGE_ZERO,
- false);
- case Intrinsic::aarch64_sve_ldff1_gather_uxtw:
- return performGatherLoadCombine(N, DAG,
- AArch64ISD::GLDFF1_UXTW_MERGE_ZERO,
- false);
- case Intrinsic::aarch64_sve_ldff1_gather_sxtw_index:
- return performGatherLoadCombine(N, DAG,
- AArch64ISD::GLDFF1_SXTW_SCALED_MERGE_ZERO,
- false);
- case Intrinsic::aarch64_sve_ldff1_gather_uxtw_index:
- return performGatherLoadCombine(N, DAG,
- AArch64ISD::GLDFF1_UXTW_SCALED_MERGE_ZERO,
- false);
- case Intrinsic::aarch64_sve_ldff1_gather_scalar_offset:
- return performGatherLoadCombine(N, DAG,
- AArch64ISD::GLDFF1_IMM_MERGE_ZERO);
- case Intrinsic::aarch64_sve_st1_scatter:
- return performScatterStoreCombine(N, DAG, AArch64ISD::SST1_PRED);
- case Intrinsic::aarch64_sve_st1_scatter_index:
- return performScatterStoreCombine(N, DAG, AArch64ISD::SST1_SCALED_PRED);
- case Intrinsic::aarch64_sve_st1_scatter_sxtw:
- return performScatterStoreCombine(N, DAG, AArch64ISD::SST1_SXTW_PRED,
- false);
- case Intrinsic::aarch64_sve_st1_scatter_uxtw:
- return performScatterStoreCombine(N, DAG, AArch64ISD::SST1_UXTW_PRED,
- false);
- case Intrinsic::aarch64_sve_st1_scatter_sxtw_index:
- return performScatterStoreCombine(N, DAG,
- AArch64ISD::SST1_SXTW_SCALED_PRED,
- false);
- case Intrinsic::aarch64_sve_st1_scatter_uxtw_index:
- return performScatterStoreCombine(N, DAG,
- AArch64ISD::SST1_UXTW_SCALED_PRED,
- false);
- case Intrinsic::aarch64_sve_st1_scatter_scalar_offset:
- return performScatterStoreCombine(N, DAG, AArch64ISD::SST1_IMM_PRED);
- case Intrinsic::aarch64_sve_tuple_get: {
- SDLoc DL(N);
- SDValue Chain = N->getOperand(0);
- SDValue Src1 = N->getOperand(2);
- SDValue Idx = N->getOperand(3);
- uint64_t IdxConst = cast<ConstantSDNode>(Idx)->getZExtValue();
- EVT ResVT = N->getValueType(0);
- uint64_t NumLanes = ResVT.getVectorElementCount().getKnownMinValue();
- SDValue ExtIdx = DAG.getVectorIdxConstant(IdxConst * NumLanes, DL);
- SDValue Val =
- DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, ResVT, Src1, ExtIdx);
- return DAG.getMergeValues({Val, Chain}, DL);
- }
- case Intrinsic::aarch64_sve_tuple_set: {
- SDLoc DL(N);
- SDValue Chain = N->getOperand(0);
- SDValue Tuple = N->getOperand(2);
- SDValue Idx = N->getOperand(3);
- SDValue Vec = N->getOperand(4);
- EVT TupleVT = Tuple.getValueType();
- uint64_t TupleLanes = TupleVT.getVectorElementCount().getKnownMinValue();
- uint64_t IdxConst = cast<ConstantSDNode>(Idx)->getZExtValue();
- uint64_t NumLanes =
- Vec.getValueType().getVectorElementCount().getKnownMinValue();
- if ((TupleLanes % NumLanes) != 0)
- report_fatal_error("invalid tuple vector!");
- uint64_t NumVecs = TupleLanes / NumLanes;
- SmallVector<SDValue, 4> Opnds;
- for (unsigned I = 0; I < NumVecs; ++I) {
- if (I == IdxConst)
- Opnds.push_back(Vec);
- else {
- SDValue ExtIdx = DAG.getVectorIdxConstant(I * NumLanes, DL);
- Opnds.push_back(DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL,
- Vec.getValueType(), Tuple, ExtIdx));
- }
- }
- SDValue Concat =
- DAG.getNode(ISD::CONCAT_VECTORS, DL, Tuple.getValueType(), Opnds);
- return DAG.getMergeValues({Concat, Chain}, DL);
- }
- case Intrinsic::aarch64_sve_tuple_create2:
- case Intrinsic::aarch64_sve_tuple_create3:
- case Intrinsic::aarch64_sve_tuple_create4: {
- SDLoc DL(N);
- SDValue Chain = N->getOperand(0);
- SmallVector<SDValue, 4> Opnds;
- for (unsigned I = 2; I < N->getNumOperands(); ++I)
- Opnds.push_back(N->getOperand(I));
- EVT VT = Opnds[0].getValueType();
- EVT EltVT = VT.getVectorElementType();
- EVT DestVT = EVT::getVectorVT(*DAG.getContext(), EltVT,
- VT.getVectorElementCount() *
- (N->getNumOperands() - 2));
- SDValue Concat = DAG.getNode(ISD::CONCAT_VECTORS, DL, DestVT, Opnds);
- return DAG.getMergeValues({Concat, Chain}, DL);
- }
- case Intrinsic::aarch64_sve_ld2:
- case Intrinsic::aarch64_sve_ld3:
- case Intrinsic::aarch64_sve_ld4: {
- SDLoc DL(N);
- SDValue Chain = N->getOperand(0);
- SDValue Mask = N->getOperand(2);
- SDValue BasePtr = N->getOperand(3);
- SDValue LoadOps[] = {Chain, Mask, BasePtr};
- unsigned IntrinsicID =
- cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
- SDValue Result =
- LowerSVEStructLoad(IntrinsicID, LoadOps, N->getValueType(0), DAG, DL);
- return DAG.getMergeValues({Result, Chain}, DL);
- }
- default:
- break;
- }
- break;
- case ISD::GlobalAddress:
- return performGlobalAddressCombine(N, DAG, Subtarget, getTargetMachine());
- }
- return SDValue();
- }
- bool AArch64TargetLowering::isUsedByReturnOnly(SDNode *N,
- SDValue &Chain) const {
- if (N->getNumValues() != 1)
- return false;
- if (!N->hasNUsesOfValue(1, 0))
- return false;
- SDValue TCChain = Chain;
- SDNode *Copy = *N->use_begin();
- if (Copy->getOpcode() == ISD::CopyToReg) {
-
-
- if (Copy->getOperand(Copy->getNumOperands() - 1).getValueType() ==
- MVT::Glue)
- return false;
- TCChain = Copy->getOperand(0);
- } else if (Copy->getOpcode() != ISD::FP_EXTEND)
- return false;
- bool HasRet = false;
- for (SDNode *Node : Copy->uses()) {
- if (Node->getOpcode() != AArch64ISD::RET_FLAG)
- return false;
- HasRet = true;
- }
- if (!HasRet)
- return false;
- Chain = TCChain;
- return true;
- }
- bool AArch64TargetLowering::mayBeEmittedAsTailCall(const CallInst *CI) const {
- return CI->isTailCall();
- }
- bool AArch64TargetLowering::getIndexedAddressParts(SDNode *Op, SDValue &Base,
- SDValue &Offset,
- ISD::MemIndexedMode &AM,
- bool &IsInc,
- SelectionDAG &DAG) const {
- if (Op->getOpcode() != ISD::ADD && Op->getOpcode() != ISD::SUB)
- return false;
- Base = Op->getOperand(0);
-
-
- if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Op->getOperand(1))) {
- int64_t RHSC = RHS->getSExtValue();
- if (Op->getOpcode() == ISD::SUB)
- RHSC = -(uint64_t)RHSC;
- if (!isInt<9>(RHSC))
- return false;
- IsInc = (Op->getOpcode() == ISD::ADD);
- Offset = Op->getOperand(1);
- return true;
- }
- return false;
- }
- bool AArch64TargetLowering::getPreIndexedAddressParts(SDNode *N, SDValue &Base,
- SDValue &Offset,
- ISD::MemIndexedMode &AM,
- SelectionDAG &DAG) const {
- EVT VT;
- SDValue Ptr;
- if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) {
- VT = LD->getMemoryVT();
- Ptr = LD->getBasePtr();
- } else if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
- VT = ST->getMemoryVT();
- Ptr = ST->getBasePtr();
- } else
- return false;
- bool IsInc;
- if (!getIndexedAddressParts(Ptr.getNode(), Base, Offset, AM, IsInc, DAG))
- return false;
- AM = IsInc ? ISD::PRE_INC : ISD::PRE_DEC;
- return true;
- }
- bool AArch64TargetLowering::getPostIndexedAddressParts(
- SDNode *N, SDNode *Op, SDValue &Base, SDValue &Offset,
- ISD::MemIndexedMode &AM, SelectionDAG &DAG) const {
- EVT VT;
- SDValue Ptr;
- if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) {
- VT = LD->getMemoryVT();
- Ptr = LD->getBasePtr();
- } else if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
- VT = ST->getMemoryVT();
- Ptr = ST->getBasePtr();
- } else
- return false;
- bool IsInc;
- if (!getIndexedAddressParts(Op, Base, Offset, AM, IsInc, DAG))
- return false;
-
-
- if (Ptr != Base)
- return false;
- AM = IsInc ? ISD::POST_INC : ISD::POST_DEC;
- return true;
- }
- static void ReplaceBITCASTResults(SDNode *N, SmallVectorImpl<SDValue> &Results,
- SelectionDAG &DAG) {
- SDLoc DL(N);
- SDValue Op = N->getOperand(0);
- if (N->getValueType(0) != MVT::i16 ||
- (Op.getValueType() != MVT::f16 && Op.getValueType() != MVT::bf16))
- return;
- Op = SDValue(
- DAG.getMachineNode(TargetOpcode::INSERT_SUBREG, DL, MVT::f32,
- DAG.getUNDEF(MVT::i32), Op,
- DAG.getTargetConstant(AArch64::hsub, DL, MVT::i32)),
- 0);
- Op = DAG.getNode(ISD::BITCAST, DL, MVT::i32, Op);
- Results.push_back(DAG.getNode(ISD::TRUNCATE, DL, MVT::i16, Op));
- }
- static void ReplaceReductionResults(SDNode *N,
- SmallVectorImpl<SDValue> &Results,
- SelectionDAG &DAG, unsigned InterOp,
- unsigned AcrossOp) {
- EVT LoVT, HiVT;
- SDValue Lo, Hi;
- SDLoc dl(N);
- std::tie(LoVT, HiVT) = DAG.GetSplitDestVTs(N->getValueType(0));
- std::tie(Lo, Hi) = DAG.SplitVectorOperand(N, 0);
- SDValue InterVal = DAG.getNode(InterOp, dl, LoVT, Lo, Hi);
- SDValue SplitVal = DAG.getNode(AcrossOp, dl, LoVT, InterVal);
- Results.push_back(SplitVal);
- }
- static std::pair<SDValue, SDValue> splitInt128(SDValue N, SelectionDAG &DAG) {
- SDLoc DL(N);
- SDValue Lo = DAG.getNode(ISD::TRUNCATE, DL, MVT::i64, N);
- SDValue Hi = DAG.getNode(ISD::TRUNCATE, DL, MVT::i64,
- DAG.getNode(ISD::SRL, DL, MVT::i128, N,
- DAG.getConstant(64, DL, MVT::i64)));
- return std::make_pair(Lo, Hi);
- }
- void AArch64TargetLowering::ReplaceExtractSubVectorResults(
- SDNode *N, SmallVectorImpl<SDValue> &Results, SelectionDAG &DAG) const {
- SDValue In = N->getOperand(0);
- EVT InVT = In.getValueType();
-
- if (!InVT.isScalableVector() || !InVT.isInteger())
- return;
- SDLoc DL(N);
- EVT VT = N->getValueType(0);
-
- ElementCount ResEC = VT.getVectorElementCount();
- if (InVT.getVectorElementCount() != (ResEC * 2))
- return;
- auto *CIndex = dyn_cast<ConstantSDNode>(N->getOperand(1));
- if (!CIndex)
- return;
- unsigned Index = CIndex->getZExtValue();
- if ((Index != 0) && (Index != ResEC.getKnownMinValue()))
- return;
- unsigned Opcode = (Index == 0) ? AArch64ISD::UUNPKLO : AArch64ISD::UUNPKHI;
- EVT ExtendedHalfVT = VT.widenIntegerVectorElementType(*DAG.getContext());
- SDValue Half = DAG.getNode(Opcode, DL, ExtendedHalfVT, N->getOperand(0));
- Results.push_back(DAG.getNode(ISD::TRUNCATE, DL, VT, Half));
- }
- static SDValue createGPRPairNode(SelectionDAG &DAG, SDValue V) {
- SDLoc dl(V.getNode());
- SDValue VLo = DAG.getAnyExtOrTrunc(V, dl, MVT::i64);
- SDValue VHi = DAG.getAnyExtOrTrunc(
- DAG.getNode(ISD::SRL, dl, MVT::i128, V, DAG.getConstant(64, dl, MVT::i64)),
- dl, MVT::i64);
- if (DAG.getDataLayout().isBigEndian())
- std::swap (VLo, VHi);
- SDValue RegClass =
- DAG.getTargetConstant(AArch64::XSeqPairsClassRegClassID, dl, MVT::i32);
- SDValue SubReg0 = DAG.getTargetConstant(AArch64::sube64, dl, MVT::i32);
- SDValue SubReg1 = DAG.getTargetConstant(AArch64::subo64, dl, MVT::i32);
- const SDValue Ops[] = { RegClass, VLo, SubReg0, VHi, SubReg1 };
- return SDValue(
- DAG.getMachineNode(TargetOpcode::REG_SEQUENCE, dl, MVT::Untyped, Ops), 0);
- }
- static void ReplaceCMP_SWAP_128Results(SDNode *N,
- SmallVectorImpl<SDValue> &Results,
- SelectionDAG &DAG,
- const AArch64Subtarget *Subtarget) {
- assert(N->getValueType(0) == MVT::i128 &&
- "AtomicCmpSwap on types less than 128 should be legal");
- if (Subtarget->hasLSE() || Subtarget->outlineAtomics()) {
-
-
- SDValue Ops[] = {
- createGPRPairNode(DAG, N->getOperand(2)),
- createGPRPairNode(DAG, N->getOperand(3)),
- N->getOperand(1),
- N->getOperand(0),
- };
- MachineMemOperand *MemOp = cast<MemSDNode>(N)->getMemOperand();
- unsigned Opcode;
- switch (MemOp->getOrdering()) {
- case AtomicOrdering::Monotonic:
- Opcode = AArch64::CASPX;
- break;
- case AtomicOrdering::Acquire:
- Opcode = AArch64::CASPAX;
- break;
- case AtomicOrdering::Release:
- Opcode = AArch64::CASPLX;
- break;
- case AtomicOrdering::AcquireRelease:
- case AtomicOrdering::SequentiallyConsistent:
- Opcode = AArch64::CASPALX;
- break;
- default:
- llvm_unreachable("Unexpected ordering!");
- }
- MachineSDNode *CmpSwap = DAG.getMachineNode(
- Opcode, SDLoc(N), DAG.getVTList(MVT::Untyped, MVT::Other), Ops);
- DAG.setNodeMemRefs(CmpSwap, {MemOp});
- unsigned SubReg1 = AArch64::sube64, SubReg2 = AArch64::subo64;
- if (DAG.getDataLayout().isBigEndian())
- std::swap(SubReg1, SubReg2);
- SDValue Lo = DAG.getTargetExtractSubreg(SubReg1, SDLoc(N), MVT::i64,
- SDValue(CmpSwap, 0));
- SDValue Hi = DAG.getTargetExtractSubreg(SubReg2, SDLoc(N), MVT::i64,
- SDValue(CmpSwap, 0));
- Results.push_back(
- DAG.getNode(ISD::BUILD_PAIR, SDLoc(N), MVT::i128, Lo, Hi));
- Results.push_back(SDValue(CmpSwap, 1));
- return;
- }
- auto Desired = splitInt128(N->getOperand(2), DAG);
- auto New = splitInt128(N->getOperand(3), DAG);
- SDValue Ops[] = {N->getOperand(1), Desired.first, Desired.second,
- New.first, New.second, N->getOperand(0)};
- SDNode *CmpSwap = DAG.getMachineNode(
- AArch64::CMP_SWAP_128, SDLoc(N),
- DAG.getVTList(MVT::i64, MVT::i64, MVT::i32, MVT::Other), Ops);
- MachineMemOperand *MemOp = cast<MemSDNode>(N)->getMemOperand();
- DAG.setNodeMemRefs(cast<MachineSDNode>(CmpSwap), {MemOp});
- Results.push_back(DAG.getNode(ISD::BUILD_PAIR, SDLoc(N), MVT::i128,
- SDValue(CmpSwap, 0), SDValue(CmpSwap, 1)));
- Results.push_back(SDValue(CmpSwap, 3));
- }
- void AArch64TargetLowering::ReplaceNodeResults(
- SDNode *N, SmallVectorImpl<SDValue> &Results, SelectionDAG &DAG) const {
- switch (N->getOpcode()) {
- default:
- llvm_unreachable("Don't know how to custom expand this");
- case ISD::BITCAST:
- ReplaceBITCASTResults(N, Results, DAG);
- return;
- case ISD::VECREDUCE_ADD:
- case ISD::VECREDUCE_SMAX:
- case ISD::VECREDUCE_SMIN:
- case ISD::VECREDUCE_UMAX:
- case ISD::VECREDUCE_UMIN:
- Results.push_back(LowerVECREDUCE(SDValue(N, 0), DAG));
- return;
- case ISD::CTPOP:
- if (SDValue Result = LowerCTPOP(SDValue(N, 0), DAG))
- Results.push_back(Result);
- return;
- case AArch64ISD::SADDV:
- ReplaceReductionResults(N, Results, DAG, ISD::ADD, AArch64ISD::SADDV);
- return;
- case AArch64ISD::UADDV:
- ReplaceReductionResults(N, Results, DAG, ISD::ADD, AArch64ISD::UADDV);
- return;
- case AArch64ISD::SMINV:
- ReplaceReductionResults(N, Results, DAG, ISD::SMIN, AArch64ISD::SMINV);
- return;
- case AArch64ISD::UMINV:
- ReplaceReductionResults(N, Results, DAG, ISD::UMIN, AArch64ISD::UMINV);
- return;
- case AArch64ISD::SMAXV:
- ReplaceReductionResults(N, Results, DAG, ISD::SMAX, AArch64ISD::SMAXV);
- return;
- case AArch64ISD::UMAXV:
- ReplaceReductionResults(N, Results, DAG, ISD::UMAX, AArch64ISD::UMAXV);
- return;
- case ISD::FP_TO_UINT:
- case ISD::FP_TO_SINT:
- assert(N->getValueType(0) == MVT::i128 && "unexpected illegal conversion");
-
- return;
- case ISD::ATOMIC_CMP_SWAP:
- ReplaceCMP_SWAP_128Results(N, Results, DAG, Subtarget);
- return;
- case ISD::LOAD: {
- assert(SDValue(N, 0).getValueType() == MVT::i128 &&
- "unexpected load's value type");
- LoadSDNode *LoadNode = cast<LoadSDNode>(N);
- if (!LoadNode->isVolatile() || LoadNode->getMemoryVT() != MVT::i128) {
-
-
- return;
- }
- SDValue Result = DAG.getMemIntrinsicNode(
- AArch64ISD::LDP, SDLoc(N),
- DAG.getVTList({MVT::i64, MVT::i64, MVT::Other}),
- {LoadNode->getChain(), LoadNode->getBasePtr()}, LoadNode->getMemoryVT(),
- LoadNode->getMemOperand());
- SDValue Pair = DAG.getNode(ISD::BUILD_PAIR, SDLoc(N), MVT::i128,
- Result.getValue(0), Result.getValue(1));
- Results.append({Pair, Result.getValue(2) });
- return;
- }
- case ISD::EXTRACT_SUBVECTOR:
- ReplaceExtractSubVectorResults(N, Results, DAG);
- return;
- case ISD::INTRINSIC_WO_CHAIN: {
- EVT VT = N->getValueType(0);
- assert((VT == MVT::i8 || VT == MVT::i16) &&
- "custom lowering for unexpected type");
- ConstantSDNode *CN = cast<ConstantSDNode>(N->getOperand(0));
- Intrinsic::ID IntID = static_cast<Intrinsic::ID>(CN->getZExtValue());
- switch (IntID) {
- default:
- return;
- case Intrinsic::aarch64_sve_clasta_n: {
- SDLoc DL(N);
- auto Op2 = DAG.getNode(ISD::ANY_EXTEND, DL, MVT::i32, N->getOperand(2));
- auto V = DAG.getNode(AArch64ISD::CLASTA_N, DL, MVT::i32,
- N->getOperand(1), Op2, N->getOperand(3));
- Results.push_back(DAG.getNode(ISD::TRUNCATE, DL, VT, V));
- return;
- }
- case Intrinsic::aarch64_sve_clastb_n: {
- SDLoc DL(N);
- auto Op2 = DAG.getNode(ISD::ANY_EXTEND, DL, MVT::i32, N->getOperand(2));
- auto V = DAG.getNode(AArch64ISD::CLASTB_N, DL, MVT::i32,
- N->getOperand(1), Op2, N->getOperand(3));
- Results.push_back(DAG.getNode(ISD::TRUNCATE, DL, VT, V));
- return;
- }
- case Intrinsic::aarch64_sve_lasta: {
- SDLoc DL(N);
- auto V = DAG.getNode(AArch64ISD::LASTA, DL, MVT::i32,
- N->getOperand(1), N->getOperand(2));
- Results.push_back(DAG.getNode(ISD::TRUNCATE, DL, VT, V));
- return;
- }
- case Intrinsic::aarch64_sve_lastb: {
- SDLoc DL(N);
- auto V = DAG.getNode(AArch64ISD::LASTB, DL, MVT::i32,
- N->getOperand(1), N->getOperand(2));
- Results.push_back(DAG.getNode(ISD::TRUNCATE, DL, VT, V));
- return;
- }
- }
- }
- }
- }
- bool AArch64TargetLowering::useLoadStackGuardNode() const {
- if (Subtarget->isTargetAndroid() || Subtarget->isTargetFuchsia())
- return TargetLowering::useLoadStackGuardNode();
- return true;
- }
- unsigned AArch64TargetLowering::combineRepeatedFPDivisors() const {
-
-
- return 3;
- }
- TargetLoweringBase::LegalizeTypeAction
- AArch64TargetLowering::getPreferredVectorAction(MVT VT) const {
-
-
- if (VT == MVT::v1i8 || VT == MVT::v1i16 || VT == MVT::v1i32 ||
- VT == MVT::v1f32)
- return TypeWidenVector;
- return TargetLoweringBase::getPreferredVectorAction(VT);
- }
- bool AArch64TargetLowering::shouldExpandAtomicStoreInIR(StoreInst *SI) const {
- unsigned Size = SI->getValueOperand()->getType()->getPrimitiveSizeInBits();
- return Size == 128;
- }
- TargetLowering::AtomicExpansionKind
- AArch64TargetLowering::shouldExpandAtomicLoadInIR(LoadInst *LI) const {
- unsigned Size = LI->getType()->getPrimitiveSizeInBits();
- return Size == 128 ? AtomicExpansionKind::LLSC : AtomicExpansionKind::None;
- }
- TargetLowering::AtomicExpansionKind
- AArch64TargetLowering::shouldExpandAtomicRMWInIR(AtomicRMWInst *AI) const {
- if (AI->isFloatingPointOperation())
- return AtomicExpansionKind::CmpXChg;
- unsigned Size = AI->getType()->getPrimitiveSizeInBits();
- if (Size > 128) return AtomicExpansionKind::None;
-
-
- if (AI->getOperation() != AtomicRMWInst::Nand && Size < 128) {
- if (Subtarget->hasLSE())
- return AtomicExpansionKind::None;
- if (Subtarget->outlineAtomics()) {
-
-
-
-
-
-
- if (AI->getOperation() != AtomicRMWInst::Min &&
- AI->getOperation() != AtomicRMWInst::Max &&
- AI->getOperation() != AtomicRMWInst::UMin &&
- AI->getOperation() != AtomicRMWInst::UMax) {
- return AtomicExpansionKind::None;
- }
- }
- }
-
-
-
-
-
- if (getTargetMachine().getOptLevel() == CodeGenOpt::None)
- return AtomicExpansionKind::CmpXChg;
- return AtomicExpansionKind::LLSC;
- }
- TargetLowering::AtomicExpansionKind
- AArch64TargetLowering::shouldExpandAtomicCmpXchgInIR(
- AtomicCmpXchgInst *AI) const {
-
- if (Subtarget->hasLSE() || Subtarget->outlineAtomics())
- return AtomicExpansionKind::None;
-
-
-
-
-
- if (getTargetMachine().getOptLevel() == CodeGenOpt::None)
- return AtomicExpansionKind::None;
- return AtomicExpansionKind::LLSC;
- }
- Value *AArch64TargetLowering::emitLoadLinked(IRBuilder<> &Builder, Value *Addr,
- AtomicOrdering Ord) const {
- Module *M = Builder.GetInsertBlock()->getParent()->getParent();
- Type *ValTy = cast<PointerType>(Addr->getType())->getElementType();
- bool IsAcquire = isAcquireOrStronger(Ord);
-
-
-
- if (ValTy->getPrimitiveSizeInBits() == 128) {
- Intrinsic::ID Int =
- IsAcquire ? Intrinsic::aarch64_ldaxp : Intrinsic::aarch64_ldxp;
- Function *Ldxr = Intrinsic::getDeclaration(M, Int);
- Addr = Builder.CreateBitCast(Addr, Type::getInt8PtrTy(M->getContext()));
- Value *LoHi = Builder.CreateCall(Ldxr, Addr, "lohi");
- Value *Lo = Builder.CreateExtractValue(LoHi, 0, "lo");
- Value *Hi = Builder.CreateExtractValue(LoHi, 1, "hi");
- Lo = Builder.CreateZExt(Lo, ValTy, "lo64");
- Hi = Builder.CreateZExt(Hi, ValTy, "hi64");
- return Builder.CreateOr(
- Lo, Builder.CreateShl(Hi, ConstantInt::get(ValTy, 64)), "val64");
- }
- Type *Tys[] = { Addr->getType() };
- Intrinsic::ID Int =
- IsAcquire ? Intrinsic::aarch64_ldaxr : Intrinsic::aarch64_ldxr;
- Function *Ldxr = Intrinsic::getDeclaration(M, Int, Tys);
- Type *EltTy = cast<PointerType>(Addr->getType())->getElementType();
- const DataLayout &DL = M->getDataLayout();
- IntegerType *IntEltTy = Builder.getIntNTy(DL.getTypeSizeInBits(EltTy));
- Value *Trunc = Builder.CreateTrunc(Builder.CreateCall(Ldxr, Addr), IntEltTy);
- return Builder.CreateBitCast(Trunc, EltTy);
- }
- void AArch64TargetLowering::emitAtomicCmpXchgNoStoreLLBalance(
- IRBuilder<> &Builder) const {
- Module *M = Builder.GetInsertBlock()->getParent()->getParent();
- Builder.CreateCall(Intrinsic::getDeclaration(M, Intrinsic::aarch64_clrex));
- }
- Value *AArch64TargetLowering::emitStoreConditional(IRBuilder<> &Builder,
- Value *Val, Value *Addr,
- AtomicOrdering Ord) const {
- Module *M = Builder.GetInsertBlock()->getParent()->getParent();
- bool IsRelease = isReleaseOrStronger(Ord);
-
-
-
- if (Val->getType()->getPrimitiveSizeInBits() == 128) {
- Intrinsic::ID Int =
- IsRelease ? Intrinsic::aarch64_stlxp : Intrinsic::aarch64_stxp;
- Function *Stxr = Intrinsic::getDeclaration(M, Int);
- Type *Int64Ty = Type::getInt64Ty(M->getContext());
- Value *Lo = Builder.CreateTrunc(Val, Int64Ty, "lo");
- Value *Hi = Builder.CreateTrunc(Builder.CreateLShr(Val, 64), Int64Ty, "hi");
- Addr = Builder.CreateBitCast(Addr, Type::getInt8PtrTy(M->getContext()));
- return Builder.CreateCall(Stxr, {Lo, Hi, Addr});
- }
- Intrinsic::ID Int =
- IsRelease ? Intrinsic::aarch64_stlxr : Intrinsic::aarch64_stxr;
- Type *Tys[] = { Addr->getType() };
- Function *Stxr = Intrinsic::getDeclaration(M, Int, Tys);
- const DataLayout &DL = M->getDataLayout();
- IntegerType *IntValTy = Builder.getIntNTy(DL.getTypeSizeInBits(Val->getType()));
- Val = Builder.CreateBitCast(Val, IntValTy);
- return Builder.CreateCall(Stxr,
- {Builder.CreateZExtOrBitCast(
- Val, Stxr->getFunctionType()->getParamType(0)),
- Addr});
- }
- bool AArch64TargetLowering::functionArgumentNeedsConsecutiveRegisters(
- Type *Ty, CallingConv::ID CallConv, bool isVarArg) const {
- if (Ty->isArrayTy())
- return true;
- const TypeSize &TySize = Ty->getPrimitiveSizeInBits();
- if (TySize.isScalable() && TySize.getKnownMinSize() > 128)
- return true;
- return false;
- }
- bool AArch64TargetLowering::shouldNormalizeToSelectSequence(LLVMContext &,
- EVT) const {
- return false;
- }
- static Value *UseTlsOffset(IRBuilder<> &IRB, unsigned Offset) {
- Module *M = IRB.GetInsertBlock()->getParent()->getParent();
- Function *ThreadPointerFunc =
- Intrinsic::getDeclaration(M, Intrinsic::thread_pointer);
- return IRB.CreatePointerCast(
- IRB.CreateConstGEP1_32(IRB.getInt8Ty(), IRB.CreateCall(ThreadPointerFunc),
- Offset),
- IRB.getInt8PtrTy()->getPointerTo(0));
- }
- Value *AArch64TargetLowering::getIRStackGuard(IRBuilder<> &IRB) const {
-
-
-
- if (Subtarget->isTargetAndroid())
- return UseTlsOffset(IRB, 0x28);
-
-
- if (Subtarget->isTargetFuchsia())
- return UseTlsOffset(IRB, -0x10);
- return TargetLowering::getIRStackGuard(IRB);
- }
- void AArch64TargetLowering::insertSSPDeclarations(Module &M) const {
-
- if (Subtarget->getTargetTriple().isWindowsMSVCEnvironment()) {
-
- M.getOrInsertGlobal("__security_cookie",
- Type::getInt8PtrTy(M.getContext()));
-
- FunctionCallee SecurityCheckCookie = M.getOrInsertFunction(
- "__security_check_cookie", Type::getVoidTy(M.getContext()),
- Type::getInt8PtrTy(M.getContext()));
- if (Function *F = dyn_cast<Function>(SecurityCheckCookie.getCallee())) {
- F->setCallingConv(CallingConv::Win64);
- F->addAttribute(1, Attribute::AttrKind::InReg);
- }
- return;
- }
- TargetLowering::insertSSPDeclarations(M);
- }
- Value *AArch64TargetLowering::getSDagStackGuard(const Module &M) const {
-
- if (Subtarget->getTargetTriple().isWindowsMSVCEnvironment())
- return M.getGlobalVariable("__security_cookie");
- return TargetLowering::getSDagStackGuard(M);
- }
- Function *AArch64TargetLowering::getSSPStackGuardCheck(const Module &M) const {
-
- if (Subtarget->getTargetTriple().isWindowsMSVCEnvironment())
- return M.getFunction("__security_check_cookie");
- return TargetLowering::getSSPStackGuardCheck(M);
- }
- Value *AArch64TargetLowering::getSafeStackPointerLocation(IRBuilder<> &IRB) const {
-
-
-
- if (Subtarget->isTargetAndroid())
- return UseTlsOffset(IRB, 0x48);
-
-
- if (Subtarget->isTargetFuchsia())
- return UseTlsOffset(IRB, -0x8);
- return TargetLowering::getSafeStackPointerLocation(IRB);
- }
- bool AArch64TargetLowering::isMaskAndCmp0FoldingBeneficial(
- const Instruction &AndI) const {
-
-
-
-
-
- ConstantInt* Mask = dyn_cast<ConstantInt>(AndI.getOperand(1));
- if (!Mask)
- return false;
- return Mask->getValue().isPowerOf2();
- }
- bool AArch64TargetLowering::
- shouldProduceAndByConstByHoistingConstFromShiftsLHSOfAnd(
- SDValue X, ConstantSDNode *XC, ConstantSDNode *CC, SDValue Y,
- unsigned OldShiftOpcode, unsigned NewShiftOpcode,
- SelectionDAG &DAG) const {
-
- if (!TargetLowering::shouldProduceAndByConstByHoistingConstFromShiftsLHSOfAnd(
- X, XC, CC, Y, OldShiftOpcode, NewShiftOpcode, DAG))
- return false;
-
- return X.getValueType().isScalarInteger() || NewShiftOpcode == ISD::SHL;
- }
- bool AArch64TargetLowering::shouldExpandShift(SelectionDAG &DAG,
- SDNode *N) const {
- if (DAG.getMachineFunction().getFunction().hasMinSize() &&
- !Subtarget->isTargetWindows() && !Subtarget->isTargetDarwin())
- return false;
- return true;
- }
- void AArch64TargetLowering::initializeSplitCSR(MachineBasicBlock *Entry) const {
-
- AArch64FunctionInfo *AFI = Entry->getParent()->getInfo<AArch64FunctionInfo>();
- AFI->setIsSplitCSR(true);
- }
- void AArch64TargetLowering::insertCopiesSplitCSR(
- MachineBasicBlock *Entry,
- const SmallVectorImpl<MachineBasicBlock *> &Exits) const {
- const AArch64RegisterInfo *TRI = Subtarget->getRegisterInfo();
- const MCPhysReg *IStart = TRI->getCalleeSavedRegsViaCopy(Entry->getParent());
- if (!IStart)
- return;
- const TargetInstrInfo *TII = Subtarget->getInstrInfo();
- MachineRegisterInfo *MRI = &Entry->getParent()->getRegInfo();
- MachineBasicBlock::iterator MBBI = Entry->begin();
- for (const MCPhysReg *I = IStart; *I; ++I) {
- const TargetRegisterClass *RC = nullptr;
- if (AArch64::GPR64RegClass.contains(*I))
- RC = &AArch64::GPR64RegClass;
- else if (AArch64::FPR64RegClass.contains(*I))
- RC = &AArch64::FPR64RegClass;
- else
- llvm_unreachable("Unexpected register class in CSRsViaCopy!");
- Register NewVR = MRI->createVirtualRegister(RC);
-
-
-
-
-
- assert(Entry->getParent()->getFunction().hasFnAttribute(
- Attribute::NoUnwind) &&
- "Function should be nounwind in insertCopiesSplitCSR!");
- Entry->addLiveIn(*I);
- BuildMI(*Entry, MBBI, DebugLoc(), TII->get(TargetOpcode::COPY), NewVR)
- .addReg(*I);
-
- for (auto *Exit : Exits)
- BuildMI(*Exit, Exit->getFirstTerminator(), DebugLoc(),
- TII->get(TargetOpcode::COPY), *I)
- .addReg(NewVR);
- }
- }
- bool AArch64TargetLowering::isIntDivCheap(EVT VT, AttributeList Attr) const {
-
-
-
-
-
-
-
- bool OptSize = Attr.hasFnAttribute(Attribute::MinSize);
- return OptSize && !VT.isVector();
- }
- bool AArch64TargetLowering::preferIncOfAddToSubOfNot(EVT VT) const {
-
- return VT.isScalarInteger();
- }
- bool AArch64TargetLowering::enableAggressiveFMAFusion(EVT VT) const {
- return Subtarget->hasAggressiveFMA() && VT.isFloatingPoint();
- }
- unsigned
- AArch64TargetLowering::getVaListSizeInBits(const DataLayout &DL) const {
- if (Subtarget->isTargetDarwin() || Subtarget->isTargetWindows())
- return getPointerTy(DL).getSizeInBits();
- return 3 * getPointerTy(DL).getSizeInBits() + 2 * 32;
- }
- void AArch64TargetLowering::finalizeLowering(MachineFunction &MF) const {
- MF.getFrameInfo().computeMaxCallFrameSize(MF);
- TargetLoweringBase::finalizeLowering(MF);
- }
- bool AArch64TargetLowering::needsFixedCatchObjects() const {
- return false;
- }
- bool AArch64TargetLowering::shouldLocalize(
- const MachineInstr &MI, const TargetTransformInfo *TTI) const {
- switch (MI.getOpcode()) {
- case TargetOpcode::G_GLOBAL_VALUE: {
-
-
-
- const GlobalValue &GV = *MI.getOperand(1).getGlobal();
- if (GV.isThreadLocal() && Subtarget->isTargetMachO())
- return false;
- break;
- }
-
-
- case AArch64::ADRP:
- case AArch64::G_ADD_LOW:
- return true;
- default:
- break;
- }
- return TargetLoweringBase::shouldLocalize(MI, TTI);
- }
- bool AArch64TargetLowering::fallBackToDAGISel(const Instruction &Inst) const {
- if (isa<ScalableVectorType>(Inst.getType()))
- return true;
- for (unsigned i = 0; i < Inst.getNumOperands(); ++i)
- if (isa<ScalableVectorType>(Inst.getOperand(i)->getType()))
- return true;
- if (const AllocaInst *AI = dyn_cast<AllocaInst>(&Inst)) {
- if (isa<ScalableVectorType>(AI->getAllocatedType()))
- return true;
- }
- return false;
- }
- static EVT getContainerForFixedLengthVector(SelectionDAG &DAG, EVT VT) {
- assert(VT.isFixedLengthVector() &&
- DAG.getTargetLoweringInfo().isTypeLegal(VT) &&
- "Expected legal fixed length vector!");
- switch (VT.getVectorElementType().getSimpleVT().SimpleTy) {
- default:
- llvm_unreachable("unexpected element type for SVE container");
- case MVT::i8:
- return EVT(MVT::nxv16i8);
- case MVT::i16:
- return EVT(MVT::nxv8i16);
- case MVT::i32:
- return EVT(MVT::nxv4i32);
- case MVT::i64:
- return EVT(MVT::nxv2i64);
- case MVT::f16:
- return EVT(MVT::nxv8f16);
- case MVT::f32:
- return EVT(MVT::nxv4f32);
- case MVT::f64:
- return EVT(MVT::nxv2f64);
- }
- }
- static SDValue getPredicateForFixedLengthVector(SelectionDAG &DAG, SDLoc &DL,
- EVT VT) {
- assert(VT.isFixedLengthVector() &&
- DAG.getTargetLoweringInfo().isTypeLegal(VT) &&
- "Expected legal fixed length vector!");
- int PgPattern;
- switch (VT.getVectorNumElements()) {
- default:
- llvm_unreachable("unexpected element count for SVE predicate");
- case 1:
- PgPattern = AArch64SVEPredPattern::vl1;
- break;
- case 2:
- PgPattern = AArch64SVEPredPattern::vl2;
- break;
- case 4:
- PgPattern = AArch64SVEPredPattern::vl4;
- break;
- case 8:
- PgPattern = AArch64SVEPredPattern::vl8;
- break;
- case 16:
- PgPattern = AArch64SVEPredPattern::vl16;
- break;
- case 32:
- PgPattern = AArch64SVEPredPattern::vl32;
- break;
- case 64:
- PgPattern = AArch64SVEPredPattern::vl64;
- break;
- case 128:
- PgPattern = AArch64SVEPredPattern::vl128;
- break;
- case 256:
- PgPattern = AArch64SVEPredPattern::vl256;
- break;
- }
-
-
-
- MVT MaskVT;
- switch (VT.getVectorElementType().getSimpleVT().SimpleTy) {
- default:
- llvm_unreachable("unexpected element type for SVE predicate");
- case MVT::i8:
- MaskVT = MVT::nxv16i1;
- break;
- case MVT::i16:
- case MVT::f16:
- MaskVT = MVT::nxv8i1;
- break;
- case MVT::i32:
- case MVT::f32:
- MaskVT = MVT::nxv4i1;
- break;
- case MVT::i64:
- case MVT::f64:
- MaskVT = MVT::nxv2i1;
- break;
- }
- return DAG.getNode(AArch64ISD::PTRUE, DL, MaskVT,
- DAG.getTargetConstant(PgPattern, DL, MVT::i64));
- }
- static SDValue getPredicateForScalableVector(SelectionDAG &DAG, SDLoc &DL,
- EVT VT) {
- assert(VT.isScalableVector() && DAG.getTargetLoweringInfo().isTypeLegal(VT) &&
- "Expected legal scalable vector!");
- auto PredTy = VT.changeVectorElementType(MVT::i1);
- return getPTrue(DAG, DL, PredTy, AArch64SVEPredPattern::all);
- }
- static SDValue getPredicateForVector(SelectionDAG &DAG, SDLoc &DL, EVT VT) {
- if (VT.isFixedLengthVector())
- return getPredicateForFixedLengthVector(DAG, DL, VT);
- return getPredicateForScalableVector(DAG, DL, VT);
- }
- static SDValue convertToScalableVector(SelectionDAG &DAG, EVT VT, SDValue V) {
- assert(VT.isScalableVector() &&
- "Expected to convert into a scalable vector!");
- assert(V.getValueType().isFixedLengthVector() &&
- "Expected a fixed length vector operand!");
- SDLoc DL(V);
- SDValue Zero = DAG.getConstant(0, DL, MVT::i64);
- return DAG.getNode(ISD::INSERT_SUBVECTOR, DL, VT, DAG.getUNDEF(VT), V, Zero);
- }
- static SDValue convertFromScalableVector(SelectionDAG &DAG, EVT VT, SDValue V) {
- assert(VT.isFixedLengthVector() &&
- "Expected to convert into a fixed length vector!");
- assert(V.getValueType().isScalableVector() &&
- "Expected a scalable vector operand!");
- SDLoc DL(V);
- SDValue Zero = DAG.getConstant(0, DL, MVT::i64);
- return DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, VT, V, Zero);
- }
- SDValue AArch64TargetLowering::LowerFixedLengthVectorLoadToSVE(
- SDValue Op, SelectionDAG &DAG) const {
- auto Load = cast<LoadSDNode>(Op);
- SDLoc DL(Op);
- EVT VT = Op.getValueType();
- EVT ContainerVT = getContainerForFixedLengthVector(DAG, VT);
- auto NewLoad = DAG.getMaskedLoad(
- ContainerVT, DL, Load->getChain(), Load->getBasePtr(), Load->getOffset(),
- getPredicateForFixedLengthVector(DAG, DL, VT), DAG.getUNDEF(ContainerVT),
- Load->getMemoryVT(), Load->getMemOperand(), Load->getAddressingMode(),
- Load->getExtensionType());
- auto Result = convertFromScalableVector(DAG, VT, NewLoad);
- SDValue MergedValues[2] = {Result, Load->getChain()};
- return DAG.getMergeValues(MergedValues, DL);
- }
- SDValue AArch64TargetLowering::LowerFixedLengthVectorStoreToSVE(
- SDValue Op, SelectionDAG &DAG) const {
- auto Store = cast<StoreSDNode>(Op);
- SDLoc DL(Op);
- EVT VT = Store->getValue().getValueType();
- EVT ContainerVT = getContainerForFixedLengthVector(DAG, VT);
- auto NewValue = convertToScalableVector(DAG, ContainerVT, Store->getValue());
- return DAG.getMaskedStore(
- Store->getChain(), DL, NewValue, Store->getBasePtr(), Store->getOffset(),
- getPredicateForFixedLengthVector(DAG, DL, VT), Store->getMemoryVT(),
- Store->getMemOperand(), Store->getAddressingMode(),
- Store->isTruncatingStore());
- }
- SDValue AArch64TargetLowering::LowerFixedLengthVectorIntDivideToSVE(
- SDValue Op, SelectionDAG &DAG) const {
- SDLoc dl(Op);
- EVT VT = Op.getValueType();
- EVT EltVT = VT.getVectorElementType();
- bool Signed = Op.getOpcode() == ISD::SDIV;
- unsigned PredOpcode = Signed ? AArch64ISD::SDIV_PRED : AArch64ISD::UDIV_PRED;
-
- if (EltVT == MVT::i32 || EltVT == MVT::i64)
- return LowerToPredicatedOp(Op, DAG, PredOpcode, true);
-
- EVT ContainerVT = getContainerForFixedLengthVector(DAG, VT);
- EVT HalfVT = VT.getHalfNumVectorElementsVT(*DAG.getContext());
- EVT FixedWidenedVT = HalfVT.widenIntegerVectorElementType(*DAG.getContext());
- EVT ScalableWidenedVT = getContainerForFixedLengthVector(DAG, FixedWidenedVT);
-
- SDValue Op0 = convertToScalableVector(DAG, ContainerVT, Op.getOperand(0));
- SDValue Op1 = convertToScalableVector(DAG, ContainerVT, Op.getOperand(1));
-
- unsigned UnpkLo = Signed ? AArch64ISD::SUNPKLO : AArch64ISD::UUNPKLO;
- unsigned UnpkHi = Signed ? AArch64ISD::SUNPKHI : AArch64ISD::UUNPKHI;
- SDValue Op0Lo = DAG.getNode(UnpkLo, dl, ScalableWidenedVT, Op0);
- SDValue Op1Lo = DAG.getNode(UnpkLo, dl, ScalableWidenedVT, Op1);
- SDValue Op0Hi = DAG.getNode(UnpkHi, dl, ScalableWidenedVT, Op0);
- SDValue Op1Hi = DAG.getNode(UnpkHi, dl, ScalableWidenedVT, Op1);
-
- Op0Lo = convertFromScalableVector(DAG, FixedWidenedVT, Op0Lo);
- Op1Lo = convertFromScalableVector(DAG, FixedWidenedVT, Op1Lo);
- Op0Hi = convertFromScalableVector(DAG, FixedWidenedVT, Op0Hi);
- Op1Hi = convertFromScalableVector(DAG, FixedWidenedVT, Op1Hi);
- SDValue ResultLo = DAG.getNode(Op.getOpcode(), dl, FixedWidenedVT,
- Op0Lo, Op1Lo);
- SDValue ResultHi = DAG.getNode(Op.getOpcode(), dl, FixedWidenedVT,
- Op0Hi, Op1Hi);
-
- ResultLo = convertToScalableVector(DAG, ScalableWidenedVT, ResultLo);
- ResultHi = convertToScalableVector(DAG, ScalableWidenedVT, ResultHi);
- SDValue ScalableResult = DAG.getNode(AArch64ISD::UZP1, dl, ContainerVT,
- ResultLo, ResultHi);
- return convertFromScalableVector(DAG, VT, ScalableResult);
- }
- SDValue AArch64TargetLowering::LowerFixedLengthVectorIntExtendToSVE(
- SDValue Op, SelectionDAG &DAG) const {
- EVT VT = Op.getValueType();
- assert(VT.isFixedLengthVector() && "Expected fixed length vector type!");
- SDLoc DL(Op);
- SDValue Val = Op.getOperand(0);
- EVT ContainerVT = getContainerForFixedLengthVector(DAG, Val.getValueType());
- Val = convertToScalableVector(DAG, ContainerVT, Val);
- bool Signed = Op.getOpcode() == ISD::SIGN_EXTEND;
- unsigned ExtendOpc = Signed ? AArch64ISD::SUNPKLO : AArch64ISD::UUNPKLO;
-
- switch (ContainerVT.getSimpleVT().SimpleTy) {
- default:
- llvm_unreachable("unimplemented container type");
- case MVT::nxv16i8:
- Val = DAG.getNode(ExtendOpc, DL, MVT::nxv8i16, Val);
- if (VT.getVectorElementType() == MVT::i16)
- break;
- LLVM_FALLTHROUGH;
- case MVT::nxv8i16:
- Val = DAG.getNode(ExtendOpc, DL, MVT::nxv4i32, Val);
- if (VT.getVectorElementType() == MVT::i32)
- break;
- LLVM_FALLTHROUGH;
- case MVT::nxv4i32:
- Val = DAG.getNode(ExtendOpc, DL, MVT::nxv2i64, Val);
- assert(VT.getVectorElementType() == MVT::i64 && "Unexpected element type!");
- break;
- }
- return convertFromScalableVector(DAG, VT, Val);
- }
- SDValue AArch64TargetLowering::LowerFixedLengthVectorTruncateToSVE(
- SDValue Op, SelectionDAG &DAG) const {
- EVT VT = Op.getValueType();
- assert(VT.isFixedLengthVector() && "Expected fixed length vector type!");
- SDLoc DL(Op);
- SDValue Val = Op.getOperand(0);
- EVT ContainerVT = getContainerForFixedLengthVector(DAG, Val.getValueType());
- Val = convertToScalableVector(DAG, ContainerVT, Val);
-
- switch (ContainerVT.getSimpleVT().SimpleTy) {
- default:
- llvm_unreachable("unimplemented container type");
- case MVT::nxv2i64:
- Val = DAG.getNode(ISD::BITCAST, DL, MVT::nxv4i32, Val);
- Val = DAG.getNode(AArch64ISD::UZP1, DL, MVT::nxv4i32, Val, Val);
- if (VT.getVectorElementType() == MVT::i32)
- break;
- LLVM_FALLTHROUGH;
- case MVT::nxv4i32:
- Val = DAG.getNode(ISD::BITCAST, DL, MVT::nxv8i16, Val);
- Val = DAG.getNode(AArch64ISD::UZP1, DL, MVT::nxv8i16, Val, Val);
- if (VT.getVectorElementType() == MVT::i16)
- break;
- LLVM_FALLTHROUGH;
- case MVT::nxv8i16:
- Val = DAG.getNode(ISD::BITCAST, DL, MVT::nxv16i8, Val);
- Val = DAG.getNode(AArch64ISD::UZP1, DL, MVT::nxv16i8, Val, Val);
- assert(VT.getVectorElementType() == MVT::i8 && "Unexpected element type!");
- break;
- }
- return convertFromScalableVector(DAG, VT, Val);
- }
- SDValue AArch64TargetLowering::LowerToPredicatedOp(SDValue Op,
- SelectionDAG &DAG,
- unsigned NewOp,
- bool OverrideNEON) const {
- EVT VT = Op.getValueType();
- SDLoc DL(Op);
- auto Pg = getPredicateForVector(DAG, DL, VT);
- if (useSVEForFixedLengthVectorVT(VT, OverrideNEON)) {
- EVT ContainerVT = getContainerForFixedLengthVector(DAG, VT);
-
- SmallVector<SDValue, 4> Operands = {Pg};
- for (const SDValue &V : Op->op_values()) {
- if (isa<CondCodeSDNode>(V)) {
- Operands.push_back(V);
- continue;
- }
- if (const VTSDNode *VTNode = dyn_cast<VTSDNode>(V)) {
- EVT VTArg = VTNode->getVT().getVectorElementType();
- EVT NewVTArg = ContainerVT.changeVectorElementType(VTArg);
- Operands.push_back(DAG.getValueType(NewVTArg));
- continue;
- }
- assert(useSVEForFixedLengthVectorVT(V.getValueType(), OverrideNEON) &&
- "Only fixed length vectors are supported!");
- Operands.push_back(convertToScalableVector(DAG, ContainerVT, V));
- }
- if (isMergePassthruOpcode(NewOp))
- Operands.push_back(DAG.getUNDEF(ContainerVT));
- auto ScalableRes = DAG.getNode(NewOp, DL, ContainerVT, Operands);
- return convertFromScalableVector(DAG, VT, ScalableRes);
- }
- assert(VT.isScalableVector() && "Only expect to lower scalable vector op!");
- SmallVector<SDValue, 4> Operands = {Pg};
- for (const SDValue &V : Op->op_values()) {
- assert((!V.getValueType().isVector() ||
- V.getValueType().isScalableVector()) &&
- "Only scalable vectors are supported!");
- Operands.push_back(V);
- }
- if (isMergePassthruOpcode(NewOp))
- Operands.push_back(DAG.getUNDEF(VT));
- return DAG.getNode(NewOp, DL, VT, Operands);
- }
- SDValue AArch64TargetLowering::LowerToScalableOp(SDValue Op,
- SelectionDAG &DAG) const {
- EVT VT = Op.getValueType();
- assert(useSVEForFixedLengthVectorVT(VT) &&
- "Only expected to lower fixed length vector operation!");
- EVT ContainerVT = getContainerForFixedLengthVector(DAG, VT);
-
- SmallVector<SDValue, 4> Ops;
- for (const SDValue &V : Op->op_values()) {
- assert(!isa<VTSDNode>(V) && "Unexpected VTSDNode node!");
-
- if (!V.getValueType().isVector()) {
- Ops.push_back(V);
- continue;
- }
-
- assert(useSVEForFixedLengthVectorVT(V.getValueType()) &&
- "Only fixed length vectors are supported!");
- Ops.push_back(convertToScalableVector(DAG, ContainerVT, V));
- }
- auto ScalableRes = DAG.getNode(Op.getOpcode(), SDLoc(Op), ContainerVT, Ops);
- return convertFromScalableVector(DAG, VT, ScalableRes);
- }
- SDValue AArch64TargetLowering::LowerVECREDUCE_SEQ_FADD(SDValue ScalarOp,
- SelectionDAG &DAG) const {
- SDLoc DL(ScalarOp);
- SDValue AccOp = ScalarOp.getOperand(0);
- SDValue VecOp = ScalarOp.getOperand(1);
- EVT SrcVT = VecOp.getValueType();
- EVT ResVT = SrcVT.getVectorElementType();
- EVT ContainerVT = SrcVT;
- if (SrcVT.isFixedLengthVector()) {
- ContainerVT = getContainerForFixedLengthVector(DAG, SrcVT);
- VecOp = convertToScalableVector(DAG, ContainerVT, VecOp);
- }
- SDValue Pg = getPredicateForVector(DAG, DL, SrcVT);
- SDValue Zero = DAG.getConstant(0, DL, MVT::i64);
-
- AccOp = DAG.getNode(ISD::INSERT_VECTOR_ELT, DL, ContainerVT,
- DAG.getUNDEF(ContainerVT), AccOp, Zero);
-
- SDValue Rdx = DAG.getNode(AArch64ISD::FADDA_PRED, DL, ContainerVT,
- Pg, AccOp, VecOp);
- return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, ResVT, Rdx, Zero);
- }
- SDValue AArch64TargetLowering::LowerPredReductionToSVE(SDValue ReduceOp,
- SelectionDAG &DAG) const {
- SDLoc DL(ReduceOp);
- SDValue Op = ReduceOp.getOperand(0);
- EVT OpVT = Op.getValueType();
- EVT VT = ReduceOp.getValueType();
- if (!OpVT.isScalableVector() || OpVT.getVectorElementType() != MVT::i1)
- return SDValue();
- SDValue Pg = getPredicateForVector(DAG, DL, OpVT);
- switch (ReduceOp.getOpcode()) {
- default:
- return SDValue();
- case ISD::VECREDUCE_OR:
- return getPTest(DAG, VT, Pg, Op, AArch64CC::ANY_ACTIVE);
- case ISD::VECREDUCE_AND: {
- Op = DAG.getNode(ISD::XOR, DL, OpVT, Op, Pg);
- return getPTest(DAG, VT, Pg, Op, AArch64CC::NONE_ACTIVE);
- }
- case ISD::VECREDUCE_XOR: {
- SDValue ID =
- DAG.getTargetConstant(Intrinsic::aarch64_sve_cntp, DL, MVT::i64);
- SDValue Cntp =
- DAG.getNode(ISD::INTRINSIC_WO_CHAIN, DL, MVT::i64, ID, Pg, Op);
- return DAG.getAnyExtOrTrunc(Cntp, DL, VT);
- }
- }
- return SDValue();
- }
- SDValue AArch64TargetLowering::LowerReductionToSVE(unsigned Opcode,
- SDValue ScalarOp,
- SelectionDAG &DAG) const {
- SDLoc DL(ScalarOp);
- SDValue VecOp = ScalarOp.getOperand(0);
- EVT SrcVT = VecOp.getValueType();
- if (useSVEForFixedLengthVectorVT(SrcVT, true)) {
- EVT ContainerVT = getContainerForFixedLengthVector(DAG, SrcVT);
- VecOp = convertToScalableVector(DAG, ContainerVT, VecOp);
- }
-
- EVT ResVT = (Opcode == AArch64ISD::UADDV_PRED) ? MVT::i64 :
- SrcVT.getVectorElementType();
- EVT RdxVT = SrcVT;
- if (SrcVT.isFixedLengthVector() || Opcode == AArch64ISD::UADDV_PRED)
- RdxVT = getPackedSVEVectorVT(ResVT);
- SDValue Pg = getPredicateForVector(DAG, DL, SrcVT);
- SDValue Rdx = DAG.getNode(Opcode, DL, RdxVT, Pg, VecOp);
- SDValue Res = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, ResVT,
- Rdx, DAG.getConstant(0, DL, MVT::i64));
-
- if (ResVT != ScalarOp.getValueType())
- Res = DAG.getAnyExtOrTrunc(Res, DL, ScalarOp.getValueType());
- return Res;
- }
- SDValue
- AArch64TargetLowering::LowerFixedLengthVectorSelectToSVE(SDValue Op,
- SelectionDAG &DAG) const {
- EVT VT = Op.getValueType();
- SDLoc DL(Op);
- EVT InVT = Op.getOperand(1).getValueType();
- EVT ContainerVT = getContainerForFixedLengthVector(DAG, InVT);
- SDValue Op1 = convertToScalableVector(DAG, ContainerVT, Op->getOperand(1));
- SDValue Op2 = convertToScalableVector(DAG, ContainerVT, Op->getOperand(2));
-
-
- EVT MaskVT = Op.getOperand(0).getValueType();
- EVT MaskContainerVT = getContainerForFixedLengthVector(DAG, MaskVT);
- auto Mask = convertToScalableVector(DAG, MaskContainerVT, Op.getOperand(0));
- Mask = DAG.getNode(ISD::TRUNCATE, DL,
- MaskContainerVT.changeVectorElementType(MVT::i1), Mask);
- auto ScalableRes = DAG.getNode(ISD::VSELECT, DL, ContainerVT,
- Mask, Op1, Op2);
- return convertFromScalableVector(DAG, VT, ScalableRes);
- }
- SDValue AArch64TargetLowering::LowerFixedLengthVectorSetccToSVE(
- SDValue Op, SelectionDAG &DAG) const {
- SDLoc DL(Op);
- EVT InVT = Op.getOperand(0).getValueType();
- EVT ContainerVT = getContainerForFixedLengthVector(DAG, InVT);
- assert(useSVEForFixedLengthVectorVT(InVT) &&
- "Only expected to lower fixed length vector operation!");
- assert(Op.getValueType() == InVT.changeTypeToInteger() &&
- "Expected integer result of the same bit length as the inputs!");
-
- if (InVT.isFloatingPoint())
- return SDValue();
- auto Op1 = convertToScalableVector(DAG, ContainerVT, Op.getOperand(0));
- auto Op2 = convertToScalableVector(DAG, ContainerVT, Op.getOperand(1));
- auto Pg = getPredicateForFixedLengthVector(DAG, DL, InVT);
- EVT CmpVT = Pg.getValueType();
- auto Cmp = DAG.getNode(AArch64ISD::SETCC_MERGE_ZERO, DL, CmpVT,
- {Pg, Op1, Op2, Op.getOperand(2)});
- EVT PromoteVT = ContainerVT.changeTypeToInteger();
- auto Promote = DAG.getBoolExtOrTrunc(Cmp, DL, PromoteVT, InVT);
- return convertFromScalableVector(DAG, Op.getValueType(), Promote);
- }
- SDValue AArch64TargetLowering::getSVESafeBitCast(EVT VT, SDValue Op,
- SelectionDAG &DAG) const {
- SDLoc DL(Op);
- EVT InVT = Op.getValueType();
- const TargetLowering &TLI = DAG.getTargetLoweringInfo();
- (void)TLI;
- assert(VT.isScalableVector() && TLI.isTypeLegal(VT) &&
- InVT.isScalableVector() && TLI.isTypeLegal(InVT) &&
- "Only expect to cast between legal scalable vector types!");
- assert((VT.getVectorElementType() == MVT::i1) ==
- (InVT.getVectorElementType() == MVT::i1) &&
- "Cannot cast between data and predicate scalable vector types!");
- if (InVT == VT)
- return Op;
- if (VT.getVectorElementType() == MVT::i1)
- return DAG.getNode(AArch64ISD::REINTERPRET_CAST, DL, VT, Op);
- EVT PackedVT = getPackedSVEVectorVT(VT.getVectorElementType());
- EVT PackedInVT = getPackedSVEVectorVT(InVT.getVectorElementType());
- assert((VT == PackedVT || InVT == PackedInVT) &&
- "Cannot cast between unpacked scalable vector types!");
-
- if (InVT != PackedInVT)
- Op = DAG.getNode(AArch64ISD::REINTERPRET_CAST, DL, PackedInVT, Op);
- Op = DAG.getNode(ISD::BITCAST, DL, PackedVT, Op);
-
- if (VT != PackedVT)
- Op = DAG.getNode(AArch64ISD::REINTERPRET_CAST, DL, VT, Op);
- return Op;
- }
|