[PATCH] D72169: [CVP] Simplify cmp of local phi node

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 3 09:56:14 PST 2020


nikic created this revision.
nikic added reviewers: lebedev.ri, reames.
Herald added subscribers: llvm-commits, JDevlieghere, hiraditya.
Herald added a project: LLVM.

CVP currently does not simplify cmps with instructions in the same block, because LVI getPredicateAt() currently does not really provide any useful information for that case (D69686 <https://reviews.llvm.org/D69686>...) However, if the instruction is a Phi node, then LVI can compute the result of the predicate by threading it into the predecessor blocks, which allows it simplify some conditions that nothing else can handle.

The example in the test case is reduced from a Rust test case that otherwise sees a major perf regression in LLVM 10 (for unrelated reasons).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72169

Files:
  llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
  llvm/test/Transforms/CorrelatedValuePropagation/icmp.ll


Index: llvm/test/Transforms/CorrelatedValuePropagation/icmp.ll
===================================================================
--- llvm/test/Transforms/CorrelatedValuePropagation/icmp.ll
+++ llvm/test/Transforms/CorrelatedValuePropagation/icmp.ll
@@ -627,11 +627,9 @@
 ; CHECK:       loop:
 ; CHECK-NEXT:    [[P:%.*]] = phi i8 [ [[A]], [[ENTRY:%.*]] ], [ [[B:%.*]], [[LOOP]] ]
 ; CHECK-NEXT:    [[C1:%.*]] = icmp ne i8 [[P]], 0
-; CHECK-NEXT:    [[C2:%.*]] = icmp ne i8 [[P]], 2
-; CHECK-NEXT:    [[C3:%.*]] = and i1 [[C1]], [[C2]]
 ; CHECK-NEXT:    [[C4:%.*]] = call i1 @get_bool()
 ; CHECK-NEXT:    [[B]] = zext i1 [[C4]] to i8
-; CHECK-NEXT:    br i1 [[C3]], label [[LOOP]], label [[EXIT]]
+; CHECK-NEXT:    br i1 [[C1]], label [[LOOP]], label [[EXIT]]
 ; CHECK:       exit:
 ; CHECK-NEXT:    ret void
 ;
Index: llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
+++ llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
@@ -310,9 +310,10 @@
   // the comparison is testing local values.  While LVI can sometimes reason
   // about such cases, it's not its primary purpose.  We do make sure to do
   // the block local query for uses from terminator instructions, but that's
-  // handled in the code for each terminator.
+  // handled in the code for each terminator. As an exception, we allow phi
+  // nodes, for which LVI can thread the condition into predecessors.
   auto *I = dyn_cast<Instruction>(Op0);
-  if (I && I->getParent() == Cmp->getParent())
+  if (I && I->getParent() == Cmp->getParent() && !isa<PHINode>(I))
     return false;
 
   LazyValueInfo::Tristate Result =


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72169.236083.patch
Type: text/x-patch
Size: 1732 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200103/b694a2f2/attachment.bin>


More information about the llvm-commits mailing list