[PATCH] D79746: [SCEV] Relax abnormal exit check in isAddRecNeverPoison.

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 11 15:07:42 PDT 2020


fhahn updated this revision to Diff 263283.
fhahn added a comment.

Actually check all instructions between I and the end of the block.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79746

Files:
  llvm/lib/Analysis/ScalarEvolution.cpp
  llvm/test/Transforms/LoopStrengthReduce/X86/2008-08-14-ShadowIV.ll


Index: llvm/test/Transforms/LoopStrengthReduce/X86/2008-08-14-ShadowIV.ll
===================================================================
--- llvm/test/Transforms/LoopStrengthReduce/X86/2008-08-14-ShadowIV.ll
+++ llvm/test/Transforms/LoopStrengthReduce/X86/2008-08-14-ShadowIV.ll
@@ -86,12 +86,13 @@
 	ret void
 }
 
-; Unable to eliminate cast due to overflow.
+; We can eliminate the cast, as all instructions between %indvar.next and the
+; branch are guaranteed to execute and branching on poison is undef. Hence
+; %indvar.next cannot overflow and neither can %i.03.
 define void @foobar4() nounwind {
 
 ; CHECK-LABEL:  foobar4(
-; CHECK-NOT:    phi double
-; CHECK-NOT:    phi float
+; CHECK:    phi double
 
 entry:
 	br label %bb.nph
Index: llvm/lib/Analysis/ScalarEvolution.cpp
===================================================================
--- llvm/lib/Analysis/ScalarEvolution.cpp
+++ llvm/lib/Analysis/ScalarEvolution.cpp
@@ -6173,7 +6173,18 @@
     }
   }
 
-  return LatchControlDependentOnPoison && loopHasNoAbnormalExits(L);
+  if (LatchControlDependentOnPoison) {
+    if (LatchBB == I->getParent())
+      // If I is in the latch and all instructions between I and the end of the
+      // block are guaranteed to execute, I cannot be poison.
+      return all_of(make_range(I->getIterator(), I->getParent()->end()),
+                    [](const Instruction &I) {
+                      return isGuaranteedToTransferExecutionToSuccessor(&I);
+                    });
+    return loopHasNoAbnormalExits(L);
+  }
+
+  return false;
 }
 
 ScalarEvolution::LoopProperties


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79746.263283.patch
Type: text/x-patch
Size: 1596 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200511/1bd321d4/attachment.bin>


More information about the llvm-commits mailing list