[PATCH] D108910: [IndVars] Break backedge and replace PHIs if loop exits on 1st iteration
Max Kazantsev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 12 22:31:11 PDT 2021
mkazantsev added a comment.
> ! In D108910#2996649 <https://reviews.llvm.org/D108910#2996649>, @mkazantsev wrote:
> Not sure if IndVars already does it, let me try to wright a simple example...
...Yes it does.
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -indvars -S < %s | FileCheck %s
; RUN: opt -passes=indvars -S < %s | FileCheck %s
declare void @never_called()
declare void @will_be_called()
define void @test_01(i32 %a, i32 %b) {
; CHECK-LABEL: @test_01(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[GUARD_COND:%.*]] = icmp ugt i32 [[A:%.*]], [[B:%.*]]
; CHECK-NEXT: br i1 [[GUARD_COND]], label [[LOOP_PREHEADER:%.*]], label [[FAILURE:%.*]]
; CHECK: loop.preheader:
; CHECK-NEXT: br label [[LOOP:%.*]]
; CHECK: loop:
; CHECK-NEXT: [[IV:%.*]] = phi i32 [ [[IV_NEXT:%.*]], [[BACKEDGE:%.*]] ], [ 0, [[LOOP_PREHEADER]] ]
; CHECK-NEXT: br i1 false, label [[NEVER_CALLED:%.*]], label [[BACKEDGE]]
; CHECK: backedge:
; CHECK-NEXT: [[IV_NEXT]] = add i32 [[IV]], 1
; CHECK-NEXT: [[COND_2:%.*]] = icmp eq i32 [[IV]], [[B]]
; CHECK-NEXT: br i1 [[COND_2]], label [[WILL_BE_CALLED:%.*]], label [[LOOP]]
; CHECK: never_called:
; CHECK-NEXT: call void @never_called()
; CHECK-NEXT: ret void
; CHECK: will_be_called:
; CHECK-NEXT: call void @will_be_called()
; CHECK-NEXT: ret void
; CHECK: failure:
; CHECK-NEXT: ret void
;
entry:
%guard_cond = icmp ugt i32 %a, %b
br i1 %guard_cond, label %loop, label %failure
loop:
%iv = phi i32 [0, %entry], [%iv.next, %backedge]
%cond_1 = icmp eq i32 %iv, %a
br i1 %cond_1, label %never_called, label %backedge
backedge:
%iv.next = add i32 %iv, 1
%cond_2 = icmp eq i32 %iv, %b
br i1 %cond_2, label %will_be_called, label %loop
never_called:
call void @never_called()
ret void
will_be_called:
call void @will_be_called()
ret void
failure:
ret void
}
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D108910/new/
https://reviews.llvm.org/D108910
More information about the llvm-commits
mailing list