From a6705053c33c7e076d0e35669c69e02dd88881c0 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Mon, 26 Jun 2023 15:33:09 +0200 Subject: [PATCH] [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 --- llvm/lib/Transforms/Utils/LoopPeel.cpp | 1 + .../loop-block-disposition-after-loop-peeling.ll | 48 ++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 llvm/test/Transforms/LoopUnroll/loop-block-disposition-after-loop-peeling.ll diff --git a/llvm/lib/Transforms/Utils/LoopPeel.cpp b/llvm/lib/Transforms/Utils/LoopPeel.cpp index 1ec46e0..d701cf1 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 0000000..3bd3b14 --- /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,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 +} -- 2.7.4