@@ -135,13 +135,17 @@ static cl::opt<bool, true>
135
135
cl::location(DisableLIRP::Strlen), cl::init(false ),
136
136
cl::ReallyHidden);
137
137
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.
138
142
bool DisableLIRP::Wcslen;
139
143
static 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);
145
149
146
150
static cl::opt<bool > UseLIRCodeSizeHeurs (
147
151
" use-lir-code-size-heurs" ,
@@ -1670,8 +1674,8 @@ class StrlenVerifier {
1670
1674
return false ;
1671
1675
1672
1676
// 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)
1675
1679
if (!dyn_cast<SCEVConstant>(AddRecEv->getStepRecurrence (*SE)))
1676
1680
return false ;
1677
1681
}
@@ -1764,7 +1768,8 @@ bool LoopIdiomRecognize::recognizeAndInsertStrLen() {
1764
1768
BasicBlock *LoopExitBB = CurLoop->getExitBlock ();
1765
1769
1766
1770
IRBuilder<> Builder (Preheader->getTerminator ());
1767
- SCEVExpander Expander (*SE, Preheader->getModule ()->getDataLayout (), " strlen_idiom" );
1771
+ SCEVExpander Expander (*SE, Preheader->getModule ()->getDataLayout (),
1772
+ " strlen_idiom" );
1768
1773
Value *MaterialzedBase = Expander.expandCodeFor (
1769
1774
Verifier.LoadBaseEv , Verifier.LoadBaseEv ->getType (),
1770
1775
Builder.GetInsertPoint ());
@@ -1810,7 +1815,7 @@ bool LoopIdiomRecognize::recognizeAndInsertStrLen() {
1810
1815
1811
1816
// All LCSSA Loop Phi are dead, the left over dead loop body can be cleaned
1812
1817
// up by later passes
1813
- for (PHINode *PN : Cleanup)
1818
+ for (PHINode *PN : Cleanup)
1814
1819
RecursivelyDeleteDeadPHINode (PN);
1815
1820
SE->forgetLoop (CurLoop);
1816
1821
0 commit comments