Address https://github.com/llvm/llvm-project/pull/184529#issuecomment-4074393657 by checking the loop's metadata prior to unrolling.
55 lines
2.0 KiB
LLVM
55 lines
2.0 KiB
LLVM
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
|
|
; RUN: opt < %s -passes=loop-unroll -S | FileCheck %s
|
|
|
|
; Verify that llvm.loop.unroll.disable is added after partial unrolling
|
|
; with a pragma unroll count, even when the last latch's exit branch is
|
|
; folded into an unconditional branch by UnrollLoop.
|
|
;
|
|
; The loop has trip count 5 and unroll count 2. After unrolling, the
|
|
; second copy's exit is folded (since iteration 2,4,... cannot be the
|
|
; last), and the conditional branch is replaced with an unconditional
|
|
; one that does not carry !llvm.loop metadata. setLoopAlreadyUnrolled
|
|
; must still mark the loop to prevent further unrolling.
|
|
|
|
define void @count(ptr %p) {
|
|
; CHECK-LABEL: define void @count(
|
|
; CHECK-SAME: ptr [[P:%.*]]) {
|
|
; CHECK-NEXT: [[ENTRY:.*]]:
|
|
; CHECK-NEXT: br label %[[LOOP:.*]]
|
|
; CHECK: [[LOOP]]:
|
|
; CHECK-NEXT: [[IV:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ [[IV_NEXT_1:%.*]], %[[LOOP_1:.*]] ]
|
|
; CHECK-NEXT: [[PTR:%.*]] = getelementptr i32, ptr [[P]], i64 [[IV]]
|
|
; CHECK-NEXT: store i32 0, ptr [[PTR]], align 4
|
|
; CHECK-NEXT: [[IV_NEXT:%.*]] = add nuw nsw i64 [[IV]], 1
|
|
; CHECK-NEXT: [[CMP:%.*]] = icmp ne i64 [[IV_NEXT]], 5
|
|
; CHECK-NEXT: br i1 [[CMP]], label %[[LOOP_1]], label %[[EXIT:.*]]
|
|
; CHECK: [[LOOP_1]]:
|
|
; CHECK-NEXT: [[PTR_1:%.*]] = getelementptr i32, ptr [[P]], i64 [[IV_NEXT]]
|
|
; CHECK-NEXT: store i32 0, ptr [[PTR_1]], align 4
|
|
; CHECK-NEXT: [[IV_NEXT_1]] = add nuw nsw i64 [[IV]], 2
|
|
; CHECK-NEXT: br label %[[LOOP]], !llvm.loop [[LOOP0:![0-9]+]]
|
|
; CHECK: [[EXIT]]:
|
|
; CHECK-NEXT: ret void
|
|
;
|
|
entry:
|
|
br label %loop
|
|
|
|
loop:
|
|
%iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
|
|
%ptr = getelementptr i32, ptr %p, i64 %iv
|
|
store i32 0, ptr %ptr
|
|
%iv.next = add nuw nsw i64 %iv, 1
|
|
%cmp = icmp ne i64 %iv.next, 5
|
|
br i1 %cmp, label %loop, label %exit, !llvm.loop !0
|
|
|
|
exit:
|
|
ret void
|
|
}
|
|
|
|
!0 = distinct !{!0, !1}
|
|
!1 = !{!"llvm.loop.unroll.count", i32 2}
|
|
;.
|
|
; CHECK: [[LOOP0]] = distinct !{[[LOOP0]], [[META1:![0-9]+]]}
|
|
; CHECK: [[META1]] = !{!"llvm.loop.unroll.disable"}
|
|
;.
|