1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -passes='loop-mssa(loop-predication),gvn,simplifycfg' -loop-predication-insert-assumes-of-predicated-guards-conditions=true < %s 2>&1 | FileCheck %s
4 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128-ni:1-p2:32:8:8:32-ni:2"
5 target triple = "x86_64-unknown-linux-gnu"
7 define i32 @test0(ptr %p1, ptr %p2, ptr %p3, ptr %p4, ptr %p5, i1 %c, i32 %x) {
10 ; CHECK-NEXT: [[P1_1:%.*]] = getelementptr i32, ptr [[P1:%.*]], i64 1
11 ; CHECK-NEXT: [[P1_2:%.*]] = getelementptr i32, ptr [[P1]], i64 2
12 ; CHECK-NEXT: [[P1_3:%.*]] = getelementptr i32, ptr [[P1]], i64 3
13 ; CHECK-NEXT: [[IV_1_START:%.*]] = load i32, ptr [[P1_1]], align 4, !range [[RNG0:![0-9]+]]
14 ; CHECK-NEXT: [[IV_1_END:%.*]] = load i32, ptr [[P1_2]], align 4, !range [[RNG0]]
15 ; CHECK-NEXT: [[IV_2_END:%.*]] = load i32, ptr [[P1_3]], align 4, !range [[RNG0]]
16 ; CHECK-NEXT: [[LOOP_COND:%.*]] = icmp ult i32 [[IV_2_END]], [[IV_1_END]]
17 ; CHECK-NEXT: br i1 [[LOOP_COND]], label [[LOOP_PREHEADER:%.*]], label [[EXIT:%.*]]
18 ; CHECK: loop.preheader:
19 ; CHECK-NEXT: [[TMP0:%.*]] = add i32 [[IV_1_END]], -1
20 ; CHECK-NEXT: [[TMP1:%.*]] = sub i32 [[TMP0]], [[IV_1_START]]
21 ; CHECK-NEXT: [[TMP2:%.*]] = icmp ule i32 [[IV_2_END]], [[TMP1]]
22 ; CHECK-NEXT: [[TMP3:%.*]] = icmp ult i32 [[IV_1_START]], [[IV_1_END]]
23 ; CHECK-NEXT: [[TMP4:%.*]] = and i1 [[TMP3]], [[TMP2]]
24 ; CHECK-NEXT: [[TMP5:%.*]] = freeze i1 [[TMP4]]
25 ; CHECK-NEXT: br label [[LOOP:%.*]]
27 ; CHECK-NEXT: [[IV_1:%.*]] = phi i32 [ [[IV_1_NEXT:%.*]], [[LOOP_NEXT:%.*]] ], [ [[IV_1_START]], [[LOOP_PREHEADER]] ]
28 ; CHECK-NEXT: [[IV_2:%.*]] = phi i32 [ [[IV_2_NEXT:%.*]], [[LOOP_NEXT]] ], [ 0, [[LOOP_PREHEADER]] ]
29 ; CHECK-NEXT: [[GEP_1:%.*]] = getelementptr i8, ptr [[P2:%.*]], i32 [[IV_1]]
30 ; CHECK-NEXT: [[VALUE:%.*]] = load i8, ptr [[GEP_1]], align 1
31 ; CHECK-NEXT: [[COND_1:%.*]] = icmp ult i32 [[IV_1]], [[IV_1_END]]
32 ; CHECK-NEXT: [[WC:%.*]] = call i1 @llvm.experimental.widenable.condition()
33 ; CHECK-NEXT: [[TMP6:%.*]] = and i1 [[TMP5]], [[WC]]
34 ; CHECK-NEXT: br i1 [[TMP6]], label [[LOOP_NEXT]], label [[DEOPT:%.*]]
36 ; CHECK-NEXT: call void @llvm.assume(i1 [[COND_1]])
37 ; CHECK-NEXT: [[GEP_3:%.*]] = getelementptr i8, ptr [[P4:%.*]], i32 [[IV_1]]
38 ; CHECK-NEXT: store i8 [[VALUE]], ptr [[GEP_3]], align 1
39 ; CHECK-NEXT: [[IV_1_NEXT]] = add nuw nsw i32 [[IV_1]], 1
40 ; CHECK-NEXT: [[IV_2_NEXT]] = add nuw nsw i32 [[IV_2]], 1
41 ; CHECK-NEXT: [[LATCH_COND:%.*]] = icmp ult i32 [[IV_2]], [[IV_2_END]]
42 ; CHECK-NEXT: br i1 [[LATCH_COND]], label [[LOOP]], label [[EXIT]]
44 ; CHECK-NEXT: [[DEOPT_RES:%.*]] = call i32 (...) @llvm.experimental.deoptimize.i32() [ "deopt"() ]
45 ; CHECK-NEXT: ret i32 [[DEOPT_RES]]
47 ; CHECK-NEXT: [[RES:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[IV_2]], [[LOOP_NEXT]] ]
48 ; CHECK-NEXT: ret i32 [[RES]]
51 %p1.1 = getelementptr i32, ptr %p1, i64 1
52 %p1.2 = getelementptr i32, ptr %p1, i64 2
53 %p1.3 = getelementptr i32, ptr %p1, i64 3
54 %iv.1.start = load i32, ptr %p1.1, !range !0
55 %iv.1.end = load i32, ptr %p1.2, !range !0
56 %iv.2.end = load i32, ptr %p1.3, !range !0
57 %loop.cond = icmp ult i32 %iv.2.end, %iv.1.end
58 br i1 %loop.cond, label %loop, label %exit
61 %iv.1 = phi i32 [ %iv.1.start, %entry ], [ %iv.1.next, %latch ]
62 %iv.2 = phi i32 [ 0, %entry ], [ %iv.2.next, %latch ]
63 %gep.1 = getelementptr i8, ptr %p2, i32 %iv.1
64 %value = load i8, ptr %gep.1
65 %cond.1 = icmp ult i32 %iv.1, %iv.1.end
66 %wc = call i1 @llvm.experimental.widenable.condition()
67 %explicit_guard_cond = and i1 %cond.1, %wc
68 br i1 %explicit_guard_cond, label %loop.next, label %deopt
71 br i1 %cond.1, label %if.true, label %if.false
74 %gep.3 = getelementptr i8, ptr %p4, i32 %iv.1
75 store i8 %value, ptr %gep.3
79 %gep.4 = getelementptr i8, ptr %p4, i32 %iv.2
80 store i8 %value, ptr %gep.4
84 %iv.1.next = add nuw nsw i32 %iv.1, 1
85 %iv.2.next = add nuw nsw i32 %iv.2, 1
86 %latch.cond = icmp ult i32 %iv.2, %iv.2.end
87 br i1 %latch.cond, label %loop, label %exit
90 %deopt_res = call i32 (...) @llvm.experimental.deoptimize.i32() [ "deopt"() ]
94 %res = phi i32 [ 0, %entry ], [ %iv.2, %latch ]
98 ; Function Attrs: inaccessiblememonly nocallback nofree nosync nounwind willreturn
99 declare void @llvm.assume(i1) #0
101 ; Function Attrs: inaccessiblememonly nocallback nofree nosync nounwind speculatable willreturn
102 declare i1 @llvm.experimental.widenable.condition() #1
104 declare i32 @llvm.experimental.deoptimize.i32(...)
106 attributes #0 = { inaccessiblememonly nocallback nofree nosync nounwind willreturn }
107 attributes #1 = { inaccessiblememonly nocallback nofree nosync nounwind speculatable willreturn }
109 !0 = !{i32 0, i32 2147483646}