[PATCH] D90456: [IndVars] Use more precise context when eliminating narrowing

Max Kazantsev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 19 01:30:19 PST 2020


mkazantsev updated this revision to Diff 306337.
mkazantsev added a comment.

Done


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90456/new/

https://reviews.llvm.org/D90456

Files:
  llvm/lib/Transforms/Utils/SimplifyIndVar.cpp


Index: llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
===================================================================
--- llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
+++ llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
@@ -1556,10 +1556,15 @@
       return false;
     ExtUsers.push_back(User);
   }
+  // We'll prove some facts that should be true in the context of ext users. IF
+  // there is no users, we are done now. If there are some, pick their common
+  // dominator as context.
   if (ExtUsers.empty()) {
     DeadInsts.emplace_back(NarrowUse);
     return true;
   }
+  const Instruction *Context = DT->findNearestCommonDominatorInst(ExtUsers);
+  assert(Context && "No common dominator?");
 
   if (!CanSignExtend && !CanZeroExtend) {
     // Because InstCombine turns 'sub nuw' to 'add' losing the no-wrap flag, we
@@ -1573,7 +1578,7 @@
     if (!SE->isKnownNegative(RHS))
       return false;
     bool ProvedSubNUW = SE->isKnownPredicateAt(
-        ICmpInst::ICMP_UGE, LHS, SE->getNegativeSCEV(RHS), NarrowUse);
+        ICmpInst::ICMP_UGE, LHS, SE->getNegativeSCEV(RHS), Context);
     if (!ProvedSubNUW)
       return false;
     // In fact, our 'add' is 'sub nuw'. We will need to widen the 2nd operand as


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D90456.306337.patch
Type: text/x-patch
Size: 1224 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201119/e646dc53/attachment.bin>


More information about the llvm-commits mailing list