Skip to content

Commit 528daea

Browse files
committed
address fmt
1 parent dee2518 commit 528daea

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
138142
bool DisableLIRP::Wcslen;
139143
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);
145149

146150
static 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

llvm/test/Transforms/LoopIdiom/wcslen16.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2-
; RUN: opt -passes='loop(loop-idiom),verify' < %s -S | FileCheck %s
2+
; RUN: opt -passes='loop(loop-idiom),verify' -enable-loop-idiom-wcslen < %s -S | FileCheck %s
33

44
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
55
target triple = "x86_64-unknown-linux-gnu"

llvm/test/Transforms/LoopIdiom/wcslen32.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2-
; RUN: opt -passes='loop-idiom' < %s -S | FileCheck %s
2+
; RUN: opt -passes='loop(loop-idiom),verify' -enable-loop-idiom-wcslen < %s -S | FileCheck %s
33

44
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
55
target triple = "x86_64-unknown-linux-gnu"

0 commit comments

Comments
 (0)