Fix PR9331. Simplified version of a patch by Jakub Staszak.
authorDuncan Sands <baldrick@free.fr>
Tue, 8 Mar 2011 12:39:03 +0000 (12:39 +0000)
committerDuncan Sands <baldrick@free.fr>
Tue, 8 Mar 2011 12:39:03 +0000 (12:39 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127243 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/ValueTracking.cpp
test/Transforms/JumpThreading/pr9331.ll [new file with mode: 0644]

index 231b95b618fdbe6c1bec3de9dd7d7264d0bfcd2a..f05ad66b87d5d334e88a57d0f4d9e64d931e38a9 100644 (file)
@@ -610,6 +610,10 @@ void llvm::ComputeMaskedBits(Value *V, const APInt &Mask,
     // Otherwise take the unions of the known bit sets of the operands,
     // taking conservative care to avoid excessive recursion.
     if (Depth < MaxDepth - 1 && !KnownZero && !KnownOne) {
+      // Skip if every incoming value references to ourself.
+      if (P->hasConstantValue() == P)
+        break;
+
       KnownZero = APInt::getAllOnesValue(BitWidth);
       KnownOne = APInt::getAllOnesValue(BitWidth);
       for (unsigned i = 0, e = P->getNumIncomingValues(); i != e; ++i) {
diff --git a/test/Transforms/JumpThreading/pr9331.ll b/test/Transforms/JumpThreading/pr9331.ll
new file mode 100644 (file)
index 0000000..4c06d52
--- /dev/null
@@ -0,0 +1,50 @@
+; RUN: opt -jump-threading -S < %s
+
+define void @func(i8 zeroext %p_44) nounwind {
+entry:
+  br i1 false, label %for.cond2, label %if.end50
+
+for.cond2:                                        ; preds = %for.inc46, %lor.end, %entry
+  %p_44.addr.1 = phi i8 [ %p_44.addr.1, %lor.end ], [ %p_44, %entry ], [ %p_44.addr.1, %for.inc46 ]
+  br i1 undef, label %for.inc46, label %for.body5
+
+for.body5:                                        ; preds = %for.cond2
+  br i1 undef, label %lbl_465, label %if.then9
+
+if.then9:                                         ; preds = %for.body5
+  br label %return
+
+lbl_465:                                          ; preds = %lbl_465, %for.body5
+  %tobool19 = icmp eq i8 undef, 0
+  br i1 %tobool19, label %if.end21, label %lbl_465
+
+if.end21:                                         ; preds = %lbl_465
+  %conv23 = zext i8 %p_44.addr.1 to i64
+  %xor = xor i64 %conv23, 1
+  %tobool.i = icmp eq i64 %conv23, 0
+  br i1 %tobool.i, label %cond.false.i, label %safe_mod_func_uint64_t_u_u.exit
+
+cond.false.i:                                     ; preds = %if.end21
+  %div.i = udiv i64 %xor, %conv23
+  br label %safe_mod_func_uint64_t_u_u.exit
+
+safe_mod_func_uint64_t_u_u.exit:                  ; preds = %cond.false.i, %if.end21
+  %cond.i = phi i64 [ %div.i, %cond.false.i ], [ %conv23, %if.end21 ]
+  %tobool28 = icmp eq i64 %cond.i, 0
+  br i1 %tobool28, label %lor.rhs, label %lor.end
+
+lor.rhs:                                          ; preds = %safe_mod_func_uint64_t_u_u.exit
+  br label %lor.end
+
+lor.end:                                          ; preds = %lor.rhs, %safe_mod_func_uint64_t_u_u.exit
+  br label %for.cond2
+
+for.inc46:                                        ; preds = %for.cond2
+  br label %for.cond2
+
+if.end50:                                         ; preds = %entry
+  br label %return
+
+return:                                           ; preds = %if.end50, %if.then9
+  ret void
+}