-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reland "[Transforms] LoopIdiomRecognize recognize strlen and wcslen (#108985)" #131412
Conversation
Co-authored-by: Michael Kruse <github@meinersbur.de>
✅ With the latest revision this PR passed the C/C++ code formatter. |
3aa7cce
to
0e951d8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/18/builds/13294 Here is the relevant piece of the build log for the reference
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Just some drive-by notes.)
const ConstantInt *CmpZero = dyn_cast<ConstantInt>(Val); | ||
if (!CmpZero || !CmpZero->isZero()) | ||
return false; | ||
return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like match(Val, m_Zero())
. Though I'm not super clear on why this patch has to add the pointer handling at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for taking. You are right, it's no longer needed. We used to use this to condition the loop preheader on a nullptr
comparison for the base of the string. I will clean this up
dbgs() << "loop exit phi scev: "; | ||
Ev->print(dbgs()); | ||
dbgs() << "\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can use << *Ev
, no need for print().
@@ -0,0 +1,66 @@ | |||
; RUN: opt -passes='loop(loop-idiom),verify' < %s -S | FileCheck %s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
verify
is redundant, it is scheduled automatically.
Another small bug got passed testing without expensive checks and corresponding cleanups: #132421 |
…lvm#108985)" (llvm#131412) Relands llvm#108985 This PR continues the effort made in https://discourse.llvm.org/t/rfc-strlen-loop-idiom-recognition-folding/55848 and https://reviews.llvm.org/D83392 and https://reviews.llvm.org/D88460 to extend `LoopIdiomRecognize` to find and replace loops of the form ```c base = str; while (*str) ++str; ``` and transforming the `strlen` loop idiom into the appropriate `strlen` and `wcslen` library call which will give a small performance boost if replaced. ```c str = base + strlen(base) len = str - base ```
Relands #108985
Fixed the logic error in #108985 that does not bailout if the library function is not emitable.
Fixed this issue and added a test for checking emitable.