-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[ValueTracking] Add missing check for two-value PN recurrance matching #152700
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
[ValueTracking] Add missing check for two-value PN recurrance matching #152700
Conversation
|
@llvm/pr-subscribers-llvm-analysis Author: Ivan R. Ivanov (ivanradanov) ChangesWhen InstTy is a type like IntrinsicInst which can have a variable number of arguments, we can encounter a case where Operation will have fewer than two arguments and error at the getOperand() calls. I think this was introduced by c11ea449e59cf An alternative fix would be to have a version of Full diff: https://github.com/llvm/llvm-project/pull/152700.diff 1 Files Affected:
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 1e70228905c33..b142fc6cc1334 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -9147,7 +9147,8 @@ static bool matchTwoInputRecurrence(const PHINode *PN, InstTy *&Inst,
return false;
for (unsigned I = 0; I != 2; ++I) {
- if (auto *Operation = dyn_cast<InstTy>(PN->getIncomingValue(I))) {
+ if (auto *Operation = dyn_cast<InstTy>(PN->getIncomingValue(I));
+ Operation && Operation->getNumOperands() == 2) {
Value *LHS = Operation->getOperand(0);
Value *RHS = Operation->getOperand(1);
if (LHS != PN && RHS != PN)
|
When InstTy is a type like IntrinsicInst which can have a variable number of arguments, we can encounter a case where Opetaion will have fewer than two arguments and error at the getOperand() calls.
nikic
left a comment
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 you please add a test?
|
I added a test. For reference, before the patch, this is how it crashes: I also noticed that the |
222ec9d to
ab28b45
Compare
2e1cc47 to
a5bc84b
Compare
nikic
left a comment
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, thanks
| @@ -0,0 +1,16 @@ | |||
| ; Check that we do not crash (see PR #152700) | |||
| ; RUN: opt < %s -passes=instcombine | |||
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.
| ; RUN: opt < %s -passes=instcombine | |
| ; RUN: opt < %s -passes=instcombine | FileCheck %s |
and generate check lines with update_test_checks.py. We prefer checking the output even for crash tests.
When InstTy is a type like IntrinsicInst which can have a variable number of arguments, we can encounter a case where Operation will have fewer than two arguments and error at the getOperand() calls.
I think this was introduced by c11ea449e59cf
An alternative fix would be to have a version of
matchTwoInputRecurrencewhere we passIto it here and checkI == Operationin the if instead ofOperation->getNumOperands() == 2.