[llvm] 606a000 - [LoopInstSimplify] Ignore users in unreachable blocks. PR55072

Max Kazantsev via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 25 03:36:07 PDT 2022


Author: Max Kazantsev
Date: 2022-04-25T17:35:28+07:00
New Revision: 606a000d1a1369e3a49e41d29b3987f87c498ed3

URL: https://github.com/llvm/llvm-project/commit/606a000d1a1369e3a49e41d29b3987f87c498ed3
DIFF: https://github.com/llvm/llvm-project/commit/606a000d1a1369e3a49e41d29b3987f87c498ed3.diff

LOG: [LoopInstSimplify] Ignore users in unreachable blocks. PR55072

Logic in this pass assumes that all users of loop instructions are
either in the same loop or are LCSSA Phis. In fact, there can also
be users in unreachable blocks that currently break assertions.
Such users don't need to go to the next round of simplifications.

Reviewed By: fhahn
Differential Revision: https://reviews.llvm.org/D124368

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/LoopInstSimplify.cpp
    llvm/test/Transforms/LoopInstSimplify/pr55072.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/LoopInstSimplify.cpp b/llvm/lib/Transforms/Scalar/LoopInstSimplify.cpp
index a53bea51893a5..6b178d1316188 100644
--- a/llvm/lib/Transforms/Scalar/LoopInstSimplify.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopInstSimplify.cpp
@@ -104,6 +104,10 @@ static bool simplifyLoopInst(Loop &L, DominatorTree &DT, LoopInfo &LI,
           auto *UserI = cast<Instruction>(U.getUser());
           U.set(V);
 
+          // Do not bother dealing with unreachable code.
+          if (!DT.isReachableFromEntry(UserI->getParent()))
+            continue;
+
           // If the instruction is used by a PHI node we have already processed
           // we'll need to iterate on the loop body to converge, so add it to
           // the next set.

diff  --git a/llvm/test/Transforms/LoopInstSimplify/pr55072.ll b/llvm/test/Transforms/LoopInstSimplify/pr55072.ll
index dfdbfefde2f39..e7de21a01aa4c 100644
--- a/llvm/test/Transforms/LoopInstSimplify/pr55072.ll
+++ b/llvm/test/Transforms/LoopInstSimplify/pr55072.ll
@@ -1,11 +1,16 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
 ; RUN: opt -S %s -passes=loop-instsimplify | FileCheck %s
 ; RUN: opt -S %s -passes='loop-mssa(loop-instsimplify)' -verify-memoryssa | FileCheck %s
 
-; XFAIL: *
-; REQUIRES: asserts
-
 define i32 @test_01() {
-; CHECK-LABEL: test_01
+; CHECK-LABEL: @test_01(
+; CHECK-NEXT:  bb:
+; CHECK-NEXT:    br label [[LOOP:%.*]]
+; CHECK:       loop:
+; CHECK-NEXT:    br label [[LOOP]]
+; CHECK:       unreached:
+; CHECK-NEXT:    ret i32 0
+;
 bb:
   br label %loop
 


        


More information about the llvm-commits mailing list