Skip to content

Conversation

@milos1397
Copy link

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.

@milos1397 milos1397 requested a review from nikic as a code owner December 15, 2025 16:31
@github-actions
Copy link

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 @ followed by their GitHub username.

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.

@llvmbot llvmbot added llvm:instcombine Covers the InstCombine, InstSimplify and AggressiveInstCombine passes llvm:transforms labels Dec 15, 2025
@llvmbot
Copy link
Member

llvmbot commented Dec 15, 2025

@llvm/pr-subscribers-llvm-transforms

Author: Miloš Poletanović (milos1397)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/172332.diff

1 Files Affected:

  • (modified) llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp (+6-6)
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;

@gandhi56 gandhi56 self-requested a review December 15, 2025 17:55
@gandhi56
Copy link
Contributor

@milos1397 Could you please reduce and attach the test case? The change seems fine to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llvm:instcombine Covers the InstCombine, InstSimplify and AggressiveInstCombine passes llvm:transforms

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants