@@ -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" ,
@@ -1665,8 +1669,8 @@ class StrlenVerifier {
1665
1669
return false ;
1666
1670
1667
1671
// We only want RecAddExpr with recurrence step that is constant. This
1668
- // is good enough for all the idioms we want to recognize. Later we expand and materialize
1669
- // the recurrence as {base,+,a} -> (base + a * strlen)
1672
+ // is good enough for all the idioms we want to recognize. Later we expand
1673
+ // and materialize the recurrence as {base,+,a} -> (base + a * strlen)
1670
1674
if (!dyn_cast<SCEVConstant>(AddRecEv->getStepRecurrence (*SE)))
1671
1675
return false ;
1672
1676
}
@@ -1759,7 +1763,8 @@ bool LoopIdiomRecognize::recognizeAndInsertStrLen() {
1759
1763
BasicBlock *LoopExitBB = CurLoop->getExitBlock ();
1760
1764
1761
1765
IRBuilder<> Builder (Preheader->getTerminator ());
1762
- SCEVExpander Expander (*SE, Preheader->getModule ()->getDataLayout (), " strlen_idiom" );
1766
+ SCEVExpander Expander (*SE, Preheader->getModule ()->getDataLayout (),
1767
+ " strlen_idiom" );
1763
1768
Value *MaterialzedBase = Expander.expandCodeFor (
1764
1769
Verifier.LoadBaseEv , Verifier.LoadBaseEv ->getType (),
1765
1770
Builder.GetInsertPoint ());
@@ -1805,7 +1810,7 @@ bool LoopIdiomRecognize::recognizeAndInsertStrLen() {
1805
1810
1806
1811
// All LCSSA Loop Phi are dead, the left over dead loop body can be cleaned
1807
1812
// up by later passes
1808
- for (PHINode *PN : Cleanup)
1813
+ for (PHINode *PN : Cleanup)
1809
1814
RecursivelyDeleteDeadPHINode (PN);
1810
1815
SE->forgetLoop (CurLoop);
1811
1816
0 commit comments