Skip to content

[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

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion llvm/lib/Analysis/ValueTracking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions llvm/test/Analysis/ValueTracking/pr152700.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
; Check that we do not crash (see PR #152700)
; RUN: opt < %s -passes=instcombine
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
; 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.


declare noundef i32 @llvm.nvvm.read.ptx.sreg.nctaid.x()
declare i32 @llvm.umin.i32(i32, i32)
define i32 @foo(i1 %c, i32 %arg) {
entry:
%i = call i32 @llvm.nvvm.read.ptx.sreg.nctaid.x()
br i1 %c, label %bb.1, label %bb.2
bb.1:
br label %bb.2
bb.2:
%phi = phi i32 [ %i, %entry ], [ 0, %bb.1 ]
%res = call i32 @llvm.umin.i32(i32 %phi, i32 %arg)
ret i32 %res
}
Loading