-
Notifications
You must be signed in to change notification settings - Fork 15.5k
[InstCombine] Fix unsafe PHINode cast and simplify logic in PointerReplacer #172332
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
base: main
Are you sure you want to change the base?
Conversation
|
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
|
@llvm/pr-subscribers-llvm-transforms Author: Miloš Poletanović (milos1397) ChangesHandles issue #171883 Basically, if the operand of the Full diff: https://github.com/llvm/llvm-project/pull/172332.diff 1 Files Affected:
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
index 9491610190c10..ea5587f4c9412 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
@@ -296,12 +296,12 @@ bool PointerReplacer::collectUsers() {
/// TODO: Handle poison and null pointers for PHI and select.
// If all incoming values are available, mark this PHI as
// replacable and push it's users into the worklist.
- bool IsReplaceable = true;
- if (all_of(PHI->incoming_values(), [&](Value *V) {
- if (!isa<Instruction>(V))
- return IsReplaceable = false;
- return isAvailable(cast<Instruction>(V));
- })) {
+ bool IsReplaceable = all_of(PHI->incoming_values(), [](Value *V) {
+ return isa<Instruction>(V);
+ });
+ if (IsReplaceable && all_of(PHI->incoming_values(), [&](Value *V) {
+ return isAvailable(cast<Instruction>(V));
+ })) {
UsersToReplace.insert(PHI);
PushUsersToWorklist(PHI);
continue;
|
|
@milos1397 Could you please reduce and attach the test case? The change seems fine to me. |
| %l_631.0 = phi ptr addrspace(5) [ %l_631.1, %BS_LABEL_7 ], [ %arrayidx, %sw.epilog ], [ undef, %entry ], [ undef, %entry ] | ||
| %cmp = icmp ugt ptr addrspace(5) %l_631.0, null | ||
| br label %BS_LABEL_7 | ||
| } No newline at end of file |
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.
Missing newline
Handles issue #171883
Basically, if the operand of the$\phi$ is an Instruction but it's not available, the condition would just break, and when we reach the deferral check, execution would continue even though there is a non-Instruction operand, leading to a crash in the subsequent processing loop.