[PATCH] D137249: [SimpleLoopUnswitch] Skip trivial selects when adding guards conditions to unswitch candidates

Dmitry Makogon via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 7 23:05:38 PST 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rGebac59999f92: [SimpleLoopUnswitch] Skip trivial selects in guards conditions unswitch… (authored by dmakogon).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D137249

Files:
  llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
  llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-skip-selects-in-guards.ll


Index: llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-skip-selects-in-guards.ll
===================================================================
--- llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-skip-selects-in-guards.ll
+++ llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-skip-selects-in-guards.ll
@@ -1,3 +1,4 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
 ; RUN: opt -passes='loop(simple-loop-unswitch<nontrivial>),verify<loops>' -S < %s | FileCheck %s
 ; RUN: opt -passes='loop-mssa(simple-loop-unswitch<nontrivial>),verify<loops>' -S < %s | FileCheck %s
 ; RUN: opt -simple-loop-unswitch -enable-nontrivial-unswitch -verify-memoryssa -S < %s | FileCheck %s
@@ -7,9 +8,40 @@
 declare void @widget()
 
 ; REQUIRES: asserts
-; XFAIL: *
 
 define void @foo(ptr addrspace(1) %arg, i64 %arg1) personality ptr @pluto {
+; CHECK-LABEL: @foo(
+; CHECK-NEXT:  bb:
+; CHECK-NEXT:    [[TMP:%.*]] = icmp slt i32 poison, 570
+; CHECK-NEXT:    [[TMP2:%.*]] = select i1 [[TMP]], i1 true, i1 false
+; CHECK-NEXT:    br i1 [[TMP]], label [[BB_SPLIT_US:%.*]], label [[BB_SPLIT:%.*]]
+; CHECK:       bb.split.us:
+; CHECK-NEXT:    br label [[BB3_US:%.*]]
+; CHECK:       bb3.us:
+; CHECK-NEXT:    br label [[GUARDED_US:%.*]]
+; CHECK:       bb4.us:
+; CHECK-NEXT:    invoke void @widget()
+; CHECK-NEXT:    to label [[BB6_US:%.*]] unwind label [[BB7_SPLIT_US:%.*]]
+; CHECK:       bb6.us:
+; CHECK-NEXT:    invoke void @widget()
+; CHECK-NEXT:    to label [[BB3_US]] unwind label [[BB7_SPLIT_US]]
+; CHECK:       guarded.us:
+; CHECK-NEXT:    invoke void @widget()
+; CHECK-NEXT:    to label [[BB4_US:%.*]] unwind label [[BB7_SPLIT_US]]
+; CHECK:       bb7.split.us:
+; CHECK-NEXT:    [[TMP8_US:%.*]] = landingpad { ptr, i32 }
+; CHECK-NEXT:    cleanup
+; CHECK-NEXT:    br label [[BB7:%.*]]
+; CHECK:       bb.split:
+; CHECK-NEXT:    br label [[BB3:%.*]]
+; CHECK:       bb3:
+; CHECK-NEXT:    br label [[DEOPT:%.*]]
+; CHECK:       deopt:
+; CHECK-NEXT:    call void (i1, ...) @llvm.experimental.guard(i1 false, i32 7) [ "deopt"() ]
+; CHECK-NEXT:    unreachable
+; CHECK:       bb7:
+; CHECK-NEXT:    ret void
+;
 bb:
   %tmp = icmp slt i32 poison, 570
   %tmp2 = select i1 %tmp, i1 true, i1 false
@@ -18,19 +50,19 @@
 bb3:                                              ; preds = %bb6, %bb
   call void (i1, ...) @llvm.experimental.guard(i1 %tmp2, i32 7) [ "deopt"() ]
   invoke void @widget()
-          to label %bb4 unwind label %bb7
+  to label %bb4 unwind label %bb7
 
 bb4:                                              ; preds = %bb3
   invoke void @widget()
-          to label %bb6 unwind label %bb7
+  to label %bb6 unwind label %bb7
 
 bb6:                                              ; preds = %bb4
   invoke void @widget()
-          to label %bb3 unwind label %bb7
+  to label %bb3 unwind label %bb7
 
 bb7:                                              ; preds = %bb6, %bb4, %bb3
   %tmp8 = landingpad { ptr, i32 }
-          cleanup
+  cleanup
   ret void
 }
 
Index: llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
+++ llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
@@ -2767,7 +2767,8 @@
     if (CollectGuards)
       for (auto &I : *BB)
         if (isGuard(&I)) {
-          auto *Cond = cast<IntrinsicInst>(&I)->getArgOperand(0);
+          auto *Cond =
+              skipTrivialSelect(cast<IntrinsicInst>(&I)->getArgOperand(0));
           // TODO: Support AND, OR conditions and partial unswitching.
           if (!isa<Constant>(Cond) && L.isLoopInvariant(Cond))
             UnswitchCandidates.push_back({&I, {Cond}});


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137249.473883.patch
Type: text/x-patch
Size: 3733 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221108/ed4854a9/attachment.bin>


More information about the llvm-commits mailing list