[ValueTracking] fix isOnlyUsedInZeroEqualityComparison with no users

This is another problem exposed by:
https://bugs.llvm.org/PR50836
This commit is contained in:
Sanjay Patel 2021-09-22 15:01:53 -04:00
parent b05804ab4c
commit a85d7a56c7
2 changed files with 16 additions and 2 deletions

View File

@ -280,8 +280,7 @@ bool llvm::haveNoCommonBitsSet(const Value *LHS, const Value *RHS,
}
bool llvm::isOnlyUsedInZeroEqualityComparison(const Instruction *I) {
// FIXME: Should not return true if there are no users.
return all_of(I->users(), [](const User *U) {
return !I->user_empty() && all_of(I->users(), [](const User *U) {
ICmpInst::Predicate P;
return match(U, m_ICmp(P, m_Value(), m_Zero())) && ICmpInst::isEquality(P);
});

View File

@ -0,0 +1,15 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -instcombine -S | FileCheck %s
target datalayout = "p:64:64"
; This would crash - PR50836
define i64 @strlen(i32* %s) {
; CHECK-LABEL: @strlen(
; CHECK-NEXT: [[R:%.*]] = call i64 @strlen(i32* noundef nonnull dereferenceable(1) [[S:%.*]])
; CHECK-NEXT: ret i64 0
;
%r = call i64 @strlen(i32* %s)
ret i64 0
}