<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div><blockquote type="cite" class=""><div class="">On May 1, 2018, at 7:47 AM, Wei Mi via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" class="">llvm-commits@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">Author: wmi<br class="">Date: Tue May  1 07:47:24 2018<br class="">New Revision: 331266<br class=""><br class="">URL: <a href="http://llvm.org/viewvc/llvm-project?rev=331266&view=rev" class="">http://llvm.org/viewvc/llvm-project?rev=331266&view=rev</a><br class="">Log:<br class="">Fix the issue that ComputeValueKnownInPredecessors only handles the case when<br class="">phi is on lhs of a comparison op.<br class=""><br class="">For the following testcase,<br class="">L1:<br class=""><br class="">  %t0 = add i32 %m, 7<br class="">  %t3 = icmp eq i32* %t2, null<br class="">  br i1 %t3, label %L3, label %L2<br class=""><br class="">L2:<br class=""><br class="">  %t4 = load i32, i32* %t2, align 4<br class="">  br label %L3<br class=""><br class="">L3:<br class=""><br class="">  %t5 = phi i32 [ %t0, %L1 ], [ %t4, %L2 ]<br class="">  %t6 = icmp eq i32 %t0, %t5<br class="">  br i1 %t6, label %L4, label %L5<br class=""><br class="">We know if we go through the path L1 --> L3, %t6 should always be true. However<br class="">currently, if the rhs of the eq comparison is phi, JumpThreading fails to<br class="">evaluate %t6 to true. And we know that Instcombine cannot guarantee always<br class="">canonicalizing phi to the left hand side of the comparison operation according<br class="">to the operand priority comparison mechanism in instcombine. The patch handles<br class="">the case when rhs of the comparison op is a phi.<br class=""><br class="">Differential Revision: <a href="https://reviews.llvm.org/D46275" class="">https://reviews.llvm.org/D46275</a><br class=""><br class=""><br class="">Modified:<br class="">    llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp<br class="">    llvm/trunk/test/Other/pr32085.ll<br class="">    llvm/trunk/test/Transforms/JumpThreading/phi-known.ll<br class=""><br class="">Modified: llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp<br class="">URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp?rev=331266&r1=331265&r2=331266&view=diff" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp?rev=331266&r1=331265&r2=331266&view=diff</a><br class="">==============================================================================<br class="">--- llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp (original)<br class="">+++ llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp Tue May  1 07:47:24 2018<br class="">@@ -752,6 +752,8 @@ bool JumpThreadingPass::ComputeValueKnow<br class="">     CmpInst::Predicate Pred = Cmp->getPredicate();<br class=""><br class="">     PHINode *PN = dyn_cast<PHINode>(CmpLHS);<br class="">+    if (!PN)<br class="">+      PN = dyn_cast<PHINode>(CmpRHS);<br class="">     if (PN && PN->getParent() == BB) {<br class="">       const DataLayout &DL = PN->getModule()->getDataLayout();<br class="">       // We can do this simplification if any comparisons fold to true or false.<br class="">@@ -762,14 +764,24 @@ bool JumpThreadingPass::ComputeValueKnow<br class="">         LVI->enableDT();<br class="">       for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) {<br class="">         BasicBlock *PredBB = PN->getIncomingBlock(i);<br class="">-        Value *LHS = PN->getIncomingValue(i);<br class="">-        Value *RHS = CmpRHS->DoPHITranslation(BB, PredBB);<br class="">-<br class="">+        Value *LHS, *RHS;<br class="">+        if (PN == CmpLHS) {<br class="">+          LHS = PN->getIncomingValue(i);<br class="">+          RHS = CmpRHS->DoPHITranslation(BB, PredBB);<br class="">+        } else {<br class="">+          LHS = CmpLHS->DoPHITranslation(BB, PredBB);<br class="">+          RHS = PN->getIncomingValue(i);<br class="">+        }<br class="">         Value *Res = SimplifyCmpInst(Pred, LHS, RHS, {DL});<br class="">         if (!Res) {<br class="">           if (!isa<Constant>(RHS))<br class="">             continue;<br class=""><br class="">+          // getPredicateOnEdge call will make no sense if LHS is defined in BB.<br class="">+          auto LHSInst = dyn_cast<Instruction>(LHS);<br class="">+          if (LHSInst && LHSInst->getParent() == BB)<br class="">+            continue;<br class="">+<br class="">           LazyValueInfo::Tristate<br class="">             ResT = LVI->getPredicateOnEdge(Pred, LHS,<br class="">                                            cast<Constant>(RHS), PredBB, BB,<br class=""><br class="">Modified: llvm/trunk/test/Other/pr32085.ll<br class="">URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Other/pr32085.ll?rev=331266&r1=331265&r2=331266&view=diff" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Other/pr32085.ll?rev=331266&r1=331265&r2=331266&view=diff</a><br class="">==============================================================================<br class="">--- llvm/trunk/test/Other/pr32085.ll (original)<br class="">+++ llvm/trunk/test/Other/pr32085.ll Tue May  1 07:47:24 2018<br class="">@@ -1,6 +1,7 @@<br class=""> ; RUN: opt -S -O1 < %s -o %t1.ll<br class=""> ;; Show that there's no difference after running another simplify CFG<br class="">-; RUN: opt -S -simplifycfg < %t1.ll -o %t2.ll<br class="">+; RUN: opt -S -simplifycfg < %t1.ll -o %t2.ll <br class="">+; RUN: sed -i 's/; preds = .*//g' %t1.ll %t2.ll<br class=""></div></div></blockquote><div><br class=""></div><div>It looks like this doesn't play well with BSD sed</div><div><br class=""></div><div><a href="http://green.lab.llvm.org/green/job/clang-stage1-cmake-RA-incremental/48381/consoleFull#17914833858254eaf0-7326-4999-85b0-388101f2d404" class="">http://green.lab.llvm.org/green/job/clang-stage1-cmake-RA-incremental/48381/consoleFull#17914833858254eaf0-7326-4999-85b0-388101f2d404</a></div><div><br class=""></div><div>Also, I would be surprised if this test worked on Windows?</div><div><br class=""></div><div>-- adrian</div><br class=""><blockquote type="cite" class=""><div class=""><div class=""> ; RUN: diff %t1.ll %t2.ll<br class=""><br class=""> ; Test from LoopSink pass, leaves some single-entry single-exit basic blocks.<br class=""><br class="">Modified: llvm/trunk/test/Transforms/JumpThreading/phi-known.ll<br class="">URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/JumpThreading/phi-known.ll?rev=331266&r1=331265&r2=331266&view=diff" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/JumpThreading/phi-known.ll?rev=331266&r1=331265&r2=331266&view=diff</a><br class="">==============================================================================<br class="">--- llvm/trunk/test/Transforms/JumpThreading/phi-known.ll (original)<br class="">+++ llvm/trunk/test/Transforms/JumpThreading/phi-known.ll Tue May  1 07:47:24 2018<br class="">@@ -64,3 +64,41 @@ exit:<br class="">   ret void<br class=""> }<br class=""><br class="">+; The eq predicate is always true if we go through the path from<br class="">+; L1 to L3, no matter the phi result %t5 is on the lhs or rhs of<br class="">+; the predicate.<br class="">+declare void @goo()<br class="">+declare void @hoo()<br class="">+<br class="">+define void @test3(i32 %m, i32** %t1) {<br class="">+L1:<br class="">+  %t0 = add i32 %m, 7<br class="">+  %t2 = load i32*, i32** %t1, align 8<br class="">+; CHECK-LABEL: @test3<br class="">+; CHECK: %t3 = icmp eq i32* %t2, null<br class="">+; CHECK: br i1 %t3, label %[[LABEL2:.*]], label %[[LABEL1:.*]]<br class="">+<br class="">+  %t3 = icmp eq i32* %t2, null<br class="">+  br i1 %t3, label %L3, label %L2<br class="">+<br class="">+; CHECK: [[LABEL1]]:<br class="">+; CHECK-NEXT: %t4 = load i32, i32* %t2, align 4<br class="">+L2:<br class="">+  %t4 = load i32, i32* %t2, align 4<br class="">+  br label %L3<br class="">+<br class="">+L3:<br class="">+  %t5 = phi i32 [ %t0, %L1 ], [ %t4, %L2 ]<br class="">+  %t6 = icmp eq i32 %t0, %t5<br class="">+  br i1 %t6, label %L4, label %L5<br class="">+<br class="">+; CHECK: [[LABEL2]]:<br class="">+; CHECK-NEXT: call void @goo()<br class="">+L4:<br class="">+  call void @goo()<br class="">+  ret void<br class="">+<br class="">+L5:<br class="">+  call void @hoo()<br class="">+  ret void<br class="">+}<br class=""><br class=""><br class="">_______________________________________________<br class="">llvm-commits mailing list<br class=""><a href="mailto:llvm-commits@lists.llvm.org" class="">llvm-commits@lists.llvm.org</a><br class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits<br class=""></div></div></blockquote></div><br class=""></body></html>