[PATCH] D124368: [LoopInstSimplify] Ignore users in unreachable blocks. PR55072

Max Kazantsev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 25 02:13:22 PDT 2022


mkazantsev created this revision.
mkazantsev added reviewers: fhahn, lebedev.ri, asbirlea, efriedma.
Herald added a subscriber: hiraditya.
Herald added a project: All.
mkazantsev requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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.


https://reviews.llvm.org/D124368

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


Index: llvm/test/Transforms/LoopInstSimplify/pr55072.ll
===================================================================
--- llvm/test/Transforms/LoopInstSimplify/pr55072.ll
+++ llvm/test/Transforms/LoopInstSimplify/pr55072.ll
@@ -1,14 +1,35 @@
+; 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
-
 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128-ni:1-p2:32:8:8:32-ni:2"
 target triple = "x86_64-unknown-linux-gnu"
 
 define i32 @test_01() {
-; CHECK-LABEL: test_01
+; CHECK-LABEL: @test_01(
+; CHECK-NEXT:  bb:
+; CHECK-NEXT:    br label [[BB1:%.*]]
+; CHECK:       bb1:
+; CHECK-NEXT:    br label [[BB3:%.*]]
+; CHECK:       bb2:
+; CHECK-NEXT:    br label [[BB2:%.*]]
+; CHECK:       bb3:
+; CHECK-NEXT:    switch i32 undef, label [[BB8:%.*]] [
+; CHECK-NEXT:    i32 0, label [[BB4:%.*]]
+; CHECK-NEXT:    i32 1, label [[BB6:%.*]]
+; CHECK-NEXT:    i32 2, label [[BB5:%.*]]
+; CHECK-NEXT:    ]
+; CHECK:       bb4:
+; CHECK-NEXT:    br label [[BB6]]
+; CHECK:       bb5:
+; CHECK-NEXT:    br label [[BB8]]
+; CHECK:       bb6:
+; CHECK-NEXT:    br label [[BB8]]
+; CHECK:       bb7:
+; CHECK-NEXT:    ret i32 0
+; CHECK:       bb8:
+; CHECK-NEXT:    br label [[BB3]]
+;
 bb:
   br label %bb1
 
@@ -20,9 +41,9 @@
 
 bb3:                                              ; preds = %bb8, %bb1
   switch i32 undef, label %bb8 [
-    i32 0, label %bb4
-    i32 1, label %bb6
-    i32 2, label %bb5
+  i32 0, label %bb4
+  i32 1, label %bb6
+  i32 2, label %bb5
   ]
 
 bb4:                                              ; preds = %bb3
Index: llvm/lib/Transforms/Scalar/LoopInstSimplify.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/LoopInstSimplify.cpp
+++ llvm/lib/Transforms/Scalar/LoopInstSimplify.cpp
@@ -104,6 +104,10 @@
           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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124368.424847.patch
Type: text/x-patch
Size: 2444 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220425/ae9a514f/attachment.bin>


More information about the llvm-commits mailing list