@@ -135,13 +135,17 @@ static cl::opt<bool, true>
135135 cl::location(DisableLIRP::Strlen), cl::init(false ),
136136 cl::ReallyHidden);
137137
138+ // / Some target libraries have a significant call overhead for `wcslen`,
139+ // / which can degrade performance when the input string is not long enough
140+ // / to justify the cost. To avoid unnecessary performance penalties,
141+ // / we disable it by default.
138142bool DisableLIRP::Wcslen;
139143static cl::opt<bool , true >
140- DisableLIRPWcslen ( " disable -loop-idiom-wcslen" ,
141- cl::desc (" Proceed with loop idiom recognize pass, but do "
142- " not convert loop(s) to wcslen." ),
143- cl::location(DisableLIRP::Wcslen), cl::init(false ),
144- cl::ReallyHidden);
144+ EnableLIRPWcslen ( " enable -loop-idiom-wcslen" ,
145+ cl::desc (" Proceed with loop idiom recognize pass, "
146+ " enable conversion of loop(s) to wcslen." ),
147+ cl::location(DisableLIRP::Wcslen), cl::init(true ),
148+ cl::ReallyHidden);
145149
146150static cl::opt<bool > UseLIRCodeSizeHeurs (
147151 " use-lir-code-size-heurs" ,
@@ -1670,8 +1674,8 @@ class StrlenVerifier {
16701674 return false ;
16711675
16721676 // We only want RecAddExpr with recurrence step that is constant. This
1673- // is good enough for all the idioms we want to recognize. Later we expand and materialize
1674- // the recurrence as {base,+,a} -> (base + a * strlen)
1677+ // is good enough for all the idioms we want to recognize. Later we expand
1678+ // and materialize the recurrence as {base,+,a} -> (base + a * strlen)
16751679 if (!dyn_cast<SCEVConstant>(AddRecEv->getStepRecurrence (*SE)))
16761680 return false ;
16771681 }
@@ -1764,7 +1768,8 @@ bool LoopIdiomRecognize::recognizeAndInsertStrLen() {
17641768 BasicBlock *LoopExitBB = CurLoop->getExitBlock ();
17651769
17661770 IRBuilder<> Builder (Preheader->getTerminator ());
1767- SCEVExpander Expander (*SE, Preheader->getModule ()->getDataLayout (), " strlen_idiom" );
1771+ SCEVExpander Expander (*SE, Preheader->getModule ()->getDataLayout (),
1772+ " strlen_idiom" );
17681773 Value *MaterialzedBase = Expander.expandCodeFor (
17691774 Verifier.LoadBaseEv , Verifier.LoadBaseEv ->getType (),
17701775 Builder.GetInsertPoint ());
@@ -1810,7 +1815,7 @@ bool LoopIdiomRecognize::recognizeAndInsertStrLen() {
18101815
18111816 // All LCSSA Loop Phi are dead, the left over dead loop body can be cleaned
18121817 // up by later passes
1813- for (PHINode *PN : Cleanup)
1818+ for (PHINode *PN : Cleanup)
18141819 RecursivelyDeleteDeadPHINode (PN);
18151820 SE->forgetLoop (CurLoop);
18161821
0 commit comments