blob: 86f128debdb31dac71ed75dcd9a5862e0e2de5e1 [file] [edit]
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
; RUN: opt -mtriple=riscv64 -mattr=+v -passes='default<O3>' -S %s | FileCheck %s
; Rewriting the comparison from its operands' exit values allows the loop to be
; deleted instead of vectorizing the induction and extracting its final result.
define i1 @rewrite_loop_exit_compare(i32 %length, i64 %limit) vscale_range(2, 1024) {
; CHECK-LABEL: define i1 @rewrite_loop_exit_compare(
; CHECK-SAME: i32 [[LENGTH:%.*]], i64 [[LIMIT:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
; CHECK-NEXT: [[ENTRY:.*]]:
; CHECK-NEXT: [[LIMIT_FR:%.*]] = freeze i64 [[LIMIT]]
; CHECK-NEXT: [[NONZERO1:%.*]] = icmp ne i32 [[LENGTH]], 0
; CHECK-NEXT: [[INRANGE2:%.*]] = icmp ne i64 [[LIMIT_FR]], 0
; CHECK-NEXT: [[CONTINUE3:%.*]] = and i1 [[NONZERO1]], [[INRANGE2]]
; CHECK-NEXT: br i1 [[CONTINUE3]], label %[[BODY_PREHEADER:.*]], label %[[EXIT:.*]]
; CHECK: [[BODY_PREHEADER]]:
; CHECK-NEXT: [[TMP0:%.*]] = add i32 [[LENGTH]], -1
; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[LIMIT_FR]], -1
; CHECK-NEXT: [[TMP2:%.*]] = zext i32 [[TMP0]] to i64
; CHECK-NEXT: [[UMIN:%.*]] = tail call i64 @llvm.umin.i64(i64 [[TMP1]], i64 [[TMP2]])
; CHECK-NEXT: [[TMP3:%.*]] = trunc nuw i64 [[UMIN]] to i32
; CHECK-NEXT: [[NONZERO_EXIT:%.*]] = icmp ne i32 [[TMP0]], [[TMP3]]
; CHECK-NEXT: br label %[[EXIT]]
; CHECK: [[EXIT]]:
; CHECK-NEXT: [[NONZERO_LCSSA:%.*]] = phi i1 [ [[NONZERO1]], %[[ENTRY]] ], [ [[NONZERO_EXIT]], %[[BODY_PREHEADER]] ]
; CHECK-NEXT: ret i1 [[NONZERO_LCSSA]]
;
entry:
br label %loop
loop:
%length.addr = phi i32 [ %length, %entry ], [ %dec, %body ]
%index = phi i64 [ 0, %entry ], [ %index.next, %body ]
%nonzero = icmp ne i32 %length.addr, 0
%inrange = icmp ult i64 %index, %limit
%continue = select i1 %nonzero, i1 %inrange, i1 false
br i1 %continue, label %body, label %exit
body:
%dec = add nsw i32 %length.addr, -1
%index.next = add nuw i64 %index, 1
br label %loop
exit:
ret i1 %nonzero
}