[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 14:03:15 PDT 2020


fhahn created this revision.
fhahn added reviewers: sanjoy.google, nlopes, efriedma, reames.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.

Currently isAddRecNeverPoison fails if there are any abnormal exits in a
loop, like function calls that may throw.

This check can be a bit relaxed however: if the instruction we are
looking at is in the latch block and guaranteed to transfer execution
to the successor, then the instruction can never yield poison (if the
latch is control dependent on it), as the branch is always executed when
the instruction is executed.


Repository:
  rG LLVM Github Monorepo

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,15 @@
     }
   }
 
-  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 isGuaranteedToTransferExecutionToSuccessor(I);
+    return loopHasNoAbnormalExits(L);
+  }
+
+  return false;
 }
 
 ScalarEvolution::LoopProperties


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


More information about the llvm-commits mailing list