[llvm] a670505 - [LoopPeel] Clear dispositions after peeling
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 19 01:40:11 PDT 2023
Author: Nikita Popov
Date: 2023-07-19T10:39:59+02:00
New Revision: a6705053c33c7e076d0e35669c69e02dd88881c0
URL: https://github.com/llvm/llvm-project/commit/a6705053c33c7e076d0e35669c69e02dd88881c0
DIFF: https://github.com/llvm/llvm-project/commit/a6705053c33c7e076d0e35669c69e02dd88881c0.diff
LOG: [LoopPeel] Clear dispositions after peeling
Block dispositions of values defined inside the loop may change
during peeling, so clear them. We already do this for other kinds
of unrolling.
Differential Revision: https://reviews.llvm.org/D153762
Added:
llvm/test/Transforms/LoopUnroll/loop-block-disposition-after-loop-peeling.ll
Modified:
llvm/lib/Transforms/Utils/LoopPeel.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/LoopPeel.cpp b/llvm/lib/Transforms/Utils/LoopPeel.cpp
index 1ec46e052a979d..d701cf110154d1 100644
--- a/llvm/lib/Transforms/Utils/LoopPeel.cpp
+++ b/llvm/lib/Transforms/Utils/LoopPeel.cpp
@@ -1042,6 +1042,7 @@ bool llvm::peelLoop(Loop *L, unsigned PeelCount, LoopInfo *LI,
// We modified the loop, update SE.
SE->forgetTopmostLoop(L);
+ SE->forgetBlockAndLoopDispositions();
#ifdef EXPENSIVE_CHECKS
// Finally DomtTree must be correct.
diff --git a/llvm/test/Transforms/LoopUnroll/loop-block-disposition-after-loop-peeling.ll b/llvm/test/Transforms/LoopUnroll/loop-block-disposition-after-loop-peeling.ll
new file mode 100644
index 00000000000000..3bd3b14663ee38
--- /dev/null
+++ b/llvm/test/Transforms/LoopUnroll/loop-block-disposition-after-loop-peeling.ll
@@ -0,0 +1,48 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
+; RUN: opt -S -passes='print<scalar-evolution>,loop(loop-unroll-full)' -verify-scev < %s 2>/dev/null | FileCheck %s
+
+define i32 @test(ptr %arg) {
+; CHECK-LABEL: define i32 @test
+; CHECK-SAME: (ptr [[ARG:%.*]]) {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br label [[LOOP_PEEL_BEGIN:%.*]]
+; CHECK: loop.peel.begin:
+; CHECK-NEXT: br label [[LOOP_PEEL:%.*]]
+; CHECK: loop.peel:
+; CHECK-NEXT: [[LOAD_PEEL:%.*]] = load i32, ptr null, align 4
+; CHECK-NEXT: br i1 false, label [[LOOP_EXIT:%.*]], label [[LOOP_LATCH_PEEL:%.*]]
+; CHECK: loop.latch.peel:
+; CHECK-NEXT: br i1 false, label [[LOOP_EXIT]], label [[LOOP_PEEL_NEXT:%.*]]
+; CHECK: loop.peel.next:
+; CHECK-NEXT: br label [[LOOP_PEEL_NEXT1:%.*]]
+; CHECK: loop.peel.next1:
+; CHECK-NEXT: br label [[ENTRY_PEEL_NEWPH:%.*]]
+; CHECK: entry.peel.newph:
+; CHECK-NEXT: br label [[LOOP:%.*]]
+; CHECK: loop:
+; CHECK-NEXT: [[LOAD:%.*]] = load i32, ptr null, align 4
+; CHECK-NEXT: br i1 false, label [[LOOP_EXIT_LOOPEXIT:%.*]], label [[LOOP_LATCH:%.*]]
+; CHECK: loop.latch:
+; CHECK-NEXT: br i1 false, label [[LOOP_EXIT_LOOPEXIT]], label [[LOOP]], !llvm.loop [[LOOP0:![0-9]+]]
+; CHECK: loop.exit.loopexit:
+; CHECK-NEXT: [[EXITVAL_PH:%.*]] = phi i32 [ [[LOAD]], [[LOOP]] ], [ 0, [[LOOP_LATCH]] ]
+; CHECK-NEXT: br label [[LOOP_EXIT]]
+; CHECK: loop.exit:
+; CHECK-NEXT: [[EXITVAL:%.*]] = phi i32 [ [[LOAD_PEEL]], [[LOOP_PEEL]] ], [ 0, [[LOOP_LATCH_PEEL]] ], [ [[EXITVAL_PH]], [[LOOP_EXIT_LOOPEXIT]] ]
+; CHECK-NEXT: ret i32 [[EXITVAL]]
+;
+entry:
+ br label %loop
+
+loop:
+ %iv = phi ptr [ %arg, %loop.latch ], [ null, %entry ]
+ %load = load i32, ptr null, align 4
+ br i1 false, label %loop.exit, label %loop.latch
+
+loop.latch:
+ br i1 false, label %loop.exit, label %loop
+
+loop.exit:
+ %exitval = phi i32 [ 0, %loop.latch ], [ %load, %loop ]
+ ret i32 %exitval
+}
More information about the llvm-commits
mailing list