|
| 1 | +; RUN: opt -irce -S < %s 2>&1 | FileCheck %s |
| 2 | + |
| 3 | +; test that the pre and post loops have loop metadata which disables any further |
| 4 | +; loop optimizations. |
| 5 | + |
| 6 | +; generates a post loop, which should have metadata !llvm.loop !2 |
| 7 | +; Function Attrs: alwaysinline |
| 8 | +define void @inner_loop(i32* %arr, i32* %a_len_ptr, i32 %n) #0 { |
| 9 | +; CHECK-LABEL: inner_loop( |
| 10 | +; CHECK-LABEL: in.bounds.postloop |
| 11 | +; CHECK: br i1 %next.postloop, label %loop.postloop, label %exit.loopexit.loopexit, !llvm.loop !2, !irce.loop.clone !7 |
| 12 | + |
| 13 | +entry: |
| 14 | + %len = load i32, i32* %a_len_ptr, !range !0 |
| 15 | + %first.itr.check = icmp sgt i32 %n, 0 |
| 16 | + br i1 %first.itr.check, label %loop, label %exit |
| 17 | + |
| 18 | +loop: ; preds = %in.bounds, %entry |
| 19 | + %idx = phi i32 [ 0, %entry ], [ %idx.next, %in.bounds ] |
| 20 | + %idx.next = add i32 %idx, 1 |
| 21 | + %abc = icmp slt i32 %idx, %len |
| 22 | + br i1 %abc, label %in.bounds, label %out.of.bounds, !prof !1 |
| 23 | + |
| 24 | +in.bounds: ; preds = %loop |
| 25 | + %addr = getelementptr i32, i32* %arr, i32 %idx |
| 26 | + store i32 0, i32* %addr |
| 27 | + %next = icmp slt i32 %idx.next, %n |
| 28 | + br i1 %next, label %loop, label %exit |
| 29 | + |
| 30 | +out.of.bounds: ; preds = %loop |
| 31 | + ret void |
| 32 | + |
| 33 | +exit: ; preds = %in.bounds, %entry |
| 34 | + ret void |
| 35 | +} |
| 36 | + |
| 37 | +; add loop metadata for pre and post loops |
| 38 | +define void @single_access_with_preloop(i32 *%arr, i32 *%a_len_ptr, i32 %n, i32 %offset) { |
| 39 | +; CHECK-LABEL: @single_access_with_preloop( |
| 40 | +; CHECK-LABEL: in.bounds.preloop |
| 41 | +; CHECK: br i1 %14, label %loop.preloop, label %preloop.exit.selector, !llvm.loop !8, !irce.loop.clone !7 |
| 42 | +; CHECK-LABEL: in.bounds.postloop |
| 43 | +; CHECK: br i1 %next.postloop, label %loop.postloop, label %exit.loopexit.loopexit, !llvm.loop !9, !irce.loop.clone !7 |
| 44 | + entry: |
| 45 | + %len = load i32, i32* %a_len_ptr, !range !0 |
| 46 | + %first.itr.check = icmp sgt i32 %n, 0 |
| 47 | + br i1 %first.itr.check, label %loop, label %exit |
| 48 | + |
| 49 | + loop: |
| 50 | + %idx = phi i32 [ 0, %entry ] , [ %idx.next, %in.bounds ] |
| 51 | + %idx.next = add i32 %idx, 1 |
| 52 | + %array.idx = add i32 %idx, %offset |
| 53 | + %abc.high = icmp slt i32 %array.idx, %len |
| 54 | + %abc.low = icmp sge i32 %array.idx, 0 |
| 55 | + %abc = and i1 %abc.low, %abc.high |
| 56 | + br i1 %abc, label %in.bounds, label %out.of.bounds, !prof !1 |
| 57 | + |
| 58 | + in.bounds: |
| 59 | + %addr = getelementptr i32, i32* %arr, i32 %array.idx |
| 60 | + store i32 0, i32* %addr |
| 61 | + %next = icmp slt i32 %idx.next, %n |
| 62 | + br i1 %next, label %loop, label %exit |
| 63 | + |
| 64 | + out.of.bounds: |
| 65 | + ret void |
| 66 | + |
| 67 | + exit: |
| 68 | + ret void |
| 69 | +} |
| 70 | +attributes #0 = { alwaysinline } |
| 71 | + |
| 72 | +!0 = !{i32 0, i32 2147483647} |
| 73 | +!1 = !{!"branch_weights", i32 64, i32 4} |
| 74 | +!2 = distinct !{!2, !3, !4, !5, !6} |
| 75 | +!3 = !{!"llvm.loop.unroll.disable"} |
| 76 | +!4 = !{!"llvm.loop.vectorize.enable", i1 false} |
| 77 | +!5 = !{!"llvm.loop.licm_versioning.disable"} |
| 78 | +!6 = !{!"llvm.loop.distribute.enable", i1 false} |
| 79 | +!7 = !{} |
| 80 | +!8 = distinct !{!8, !3, !4, !5} |
| 81 | +!9 = distinct !{!9, !3, !4, !5} |
0 commit comments