1*0ec421d0SRoman Lebedev; RUN: opt -verify-loop-info -irce-print-changed-loops -passes=irce -S 267904db2SAlina Sbirlea; RUN: opt -verify-loop-info -irce-print-changed-loops -passes='require<branch-prob>,irce' -S 3cee313d2SEric Christopher 4cee313d2SEric Christopher; Make sure that IRCE doesn't apply in case of empty ranges. 5cee313d2SEric Christopher; (i + 30 < 40) if i in [-30, 10). 6cee313d2SEric Christopher; Intersected with iteration space, it is [0, 10). 7cee313d2SEric Christopher; (i - 60 < 40) if i in [60 , 100). 8cee313d2SEric Christopher; The intersection with safe iteration space is the empty range [60, 10). 9cee313d2SEric Christopher; It is better to eliminate one range check than attempt to eliminate both given 10cee313d2SEric Christopher; that we will never go to the main loop in the latter case and basically 11cee313d2SEric Christopher; only duplicate code with no benefits. 12cee313d2SEric Christopher 13631432a3SMatt Arsenaultdefine void @test_01(ptr %arr, ptr %a_len_ptr) #0 { 14cee313d2SEric Christopher 15cee313d2SEric Christopher; CHECK-LABEL: test_01( 16cee313d2SEric Christopher; CHECK-NOT: preloop 17cee313d2SEric Christopher; CHECK: entry: 18cee313d2SEric Christopher; CHECK-NEXT: br i1 true, label %loop.preheader, label %main.pseudo.exit 19cee313d2SEric Christopher; CHECK: in.bounds.1: 20631432a3SMatt Arsenault; CHECK-NEXT: %addr = getelementptr i32, ptr %arr, i32 %idx 21631432a3SMatt Arsenault; CHECK-NEXT: store i32 0, ptr %addr 22cee313d2SEric Christopher; CHECK-NEXT: %off1 = add i32 %idx, 30 23cee313d2SEric Christopher; CHECK-NEXT: %c2 = icmp slt i32 %off1, 40 24cee313d2SEric Christopher; CHECK-NEXT: br i1 true, label %in.bounds.2, label %exit.loopexit2 25cee313d2SEric Christopher; CHECK: in.bounds.2: 26cee313d2SEric Christopher; CHECK-NEXT: %off2 = add i32 %idx, -60 27cee313d2SEric Christopher; CHECK-NEXT: %c3 = icmp slt i32 %off2, 40 28cee313d2SEric Christopher; CHECK-NEXT: br i1 %c3, label %in.bounds.3, label %exit.loopexit2 29cee313d2SEric Christopher; CHECK: in.bounds.3: 30cee313d2SEric Christopher; CHECK-NEXT: %next = icmp ult i32 %idx.next, 100 31cee313d2SEric Christopher; CHECK-NEXT: [[COND1:%[^ ]+]] = icmp ult i32 %idx.next, 10 32cee313d2SEric Christopher; CHECK-NEXT: br i1 [[COND1]], label %loop, label %main.exit.selector 33cee313d2SEric Christopher; CHECK: main.exit.selector: 34cee313d2SEric Christopher; CHECK-NEXT: %idx.next.lcssa = phi i32 [ %idx.next, %in.bounds.3 ] 35cee313d2SEric Christopher; CHECK-NEXT: [[COND2:%[^ ]+]] = icmp ult i32 %idx.next.lcssa, 100 36cee313d2SEric Christopher; CHECK-NEXT: br i1 [[COND2]], label %main.pseudo.exit, label %exit 37cee313d2SEric Christopher; CHECK: postloop: 38cee313d2SEric Christopher 39cee313d2SEric Christopherentry: 40cee313d2SEric Christopher br label %loop 41cee313d2SEric Christopher 42cee313d2SEric Christopherloop: 43cee313d2SEric Christopher %idx = phi i32 [ 0, %entry ], [ %idx.next, %in.bounds.3 ] 44cee313d2SEric Christopher %idx.next = add nsw nuw i32 %idx, 1 45cee313d2SEric Christopher %c1 = icmp slt i32 %idx, 20 46cee313d2SEric Christopher br i1 %c1, label %in.bounds.1, label %out.of.bounds 47cee313d2SEric Christopher 48cee313d2SEric Christopherin.bounds.1: 49631432a3SMatt Arsenault %addr = getelementptr i32, ptr %arr, i32 %idx 50631432a3SMatt Arsenault store i32 0, ptr %addr 51cee313d2SEric Christopher %off1 = add i32 %idx, 30 52cee313d2SEric Christopher %c2 = icmp slt i32 %off1, 40 53cee313d2SEric Christopher br i1 %c2, label %in.bounds.2, label %exit 54cee313d2SEric Christopher 55cee313d2SEric Christopherin.bounds.2: 56cee313d2SEric Christopher %off2 = add i32 %idx, -60 57cee313d2SEric Christopher %c3 = icmp slt i32 %off2, 40 58cee313d2SEric Christopher br i1 %c3, label %in.bounds.3, label %exit 59cee313d2SEric Christopher 60cee313d2SEric Christopherin.bounds.3: 61cee313d2SEric Christopher %next = icmp ult i32 %idx.next, 100 62cee313d2SEric Christopher br i1 %next, label %loop, label %exit 63cee313d2SEric Christopher 64cee313d2SEric Christopherout.of.bounds: 65cee313d2SEric Christopher ret void 66cee313d2SEric Christopher 67cee313d2SEric Christopherexit: 68cee313d2SEric Christopher ret void 69cee313d2SEric Christopher} 70