[llvm] def48b0 - [PredicateInfo][SCCP] Remove assertion (PR46814)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 23 10:37:03 PDT 2020


Author: Nikita Popov
Date: 2020-07-23T19:36:51+02:00
New Revision: def48b0e8886ce219b4a77c6e7115a4a86147e04

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

LOG: [PredicateInfo][SCCP] Remove assertion (PR46814)

As long as RenamedOp is not guaranteed to be accurate, we cannot
assert here and should just return false. This was already done
for the other conditions in this function.

Fixes https://bugs.llvm.org/show_bug.cgi?id=46814.

Added: 
    

Modified: 
    llvm/lib/Transforms/Utils/PredicateInfo.cpp
    llvm/test/Transforms/SCCP/predicateinfo-cond.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Utils/PredicateInfo.cpp b/llvm/lib/Transforms/Utils/PredicateInfo.cpp
index 280d3a996d50..d9bd77e999da 100644
--- a/llvm/lib/Transforms/Utils/PredicateInfo.cpp
+++ b/llvm/lib/Transforms/Utils/PredicateInfo.cpp
@@ -837,7 +837,10 @@ Optional<PredicateConstraint> PredicateBase::getConstraint() const {
     }
 
     CmpInst *Cmp = dyn_cast<CmpInst>(Condition);
-    assert(Cmp && "Condition should be a CmpInst");
+    if (!Cmp) {
+      // TODO: Make this an assertion once RenamedOp is fully accurate.
+      return None;
+    }
 
     CmpInst::Predicate Pred;
     Value *OtherOp;

diff  --git a/llvm/test/Transforms/SCCP/predicateinfo-cond.ll b/llvm/test/Transforms/SCCP/predicateinfo-cond.ll
index d98b3cc76d92..8ed96ec9301f 100644
--- a/llvm/test/Transforms/SCCP/predicateinfo-cond.ll
+++ b/llvm/test/Transforms/SCCP/predicateinfo-cond.ll
@@ -98,4 +98,32 @@ if3.end:
   ret i32 %phi2
 }
 
+define void @pr46814(i32 %a) {
+; CHECK-LABEL: @pr46814(
+; CHECK-NEXT:    [[C1:%.*]] = icmp uge i32 [[A:%.*]], 10
+; CHECK-NEXT:    [[C2:%.*]] = icmp ult i32 [[A]], 20
+; CHECK-NEXT:    [[C3:%.*]] = and i1 [[C1]], [[C2]]
+; CHECK-NEXT:    br i1 [[C3]], label [[IF_1:%.*]], label [[EXIT:%.*]]
+; CHECK:       if.1:
+; CHECK-NEXT:    br i1 true, label [[IF_2:%.*]], label [[EXIT]]
+; CHECK:       if.2:
+; CHECK-NEXT:    br i1 true, label [[EXIT]], label [[EXIT]]
+; CHECK:       exit:
+; CHECK-NEXT:    ret void
+;
+  %c1 = icmp uge i32 %a, 10
+  %c2 = icmp ult i32 %a, 20
+  %c3 = and i1 %c1, %c2
+  br i1 %c3, label %if.1, label %exit
+
+if.1:
+  br i1 %c3, label %if.2, label %exit
+
+if.2:
+  br i1 %c3, label %exit, label %exit
+
+exit:
+  ret void
+}
+
 declare void @llvm.assume(i1)


        


More information about the llvm-commits mailing list