[llvm] a85d7a5 - [ValueTracking] fix isOnlyUsedInZeroEqualityComparison with no users

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 22 12:26:44 PDT 2021


Author: Sanjay Patel
Date: 2021-09-22T15:01:53-04:00
New Revision: a85d7a56c7bbd9b3c8409c00f48de47bec5fc8af

URL: https://github.com/llvm/llvm-project/commit/a85d7a56c7bbd9b3c8409c00f48de47bec5fc8af
DIFF: https://github.com/llvm/llvm-project/commit/a85d7a56c7bbd9b3c8409c00f48de47bec5fc8af.diff

LOG: [ValueTracking] fix isOnlyUsedInZeroEqualityComparison with no users

This is another problem exposed by:
https://bugs.llvm.org/PR50836

Added: 
    llvm/test/Transforms/InstCombine/strlen-3.ll

Modified: 
    llvm/lib/Analysis/ValueTracking.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 9458c895094a..174ee97b668e 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -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);
   });

diff  --git a/llvm/test/Transforms/InstCombine/strlen-3.ll b/llvm/test/Transforms/InstCombine/strlen-3.ll
new file mode 100644
index 000000000000..0188f3549115
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/strlen-3.ll
@@ -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
+}


        


More information about the llvm-commits mailing list