1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -indvars %s | FileCheck %s
3 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128-ni:1"
4 target triple = "x86_64-unknown-linux-gnu"
6 define i32 @testDiv(i8* %p, i64* %p1) {
7 ; CHECK-LABEL: @testDiv(
9 ; CHECK-NEXT: br label [[LOOP1:%.*]]
11 ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ [[INDVARS_IV_NEXT:%.*]], [[LOOP2_EXIT:%.*]] ], [ 8, [[ENTRY:%.*]] ]
12 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[INDVARS_IV]], 15
13 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[EXIT:%.*]], label [[GENERAL_CASE24:%.*]]
14 ; CHECK: general_case24:
15 ; CHECK-NEXT: br i1 false, label [[LOOP2_PREHEADER:%.*]], label [[LOOP2_EXIT]]
16 ; CHECK: loop2.preheader:
17 ; CHECK-NEXT: [[TMP0:%.*]] = udiv i64 14, [[INDVARS_IV]]
18 ; CHECK-NEXT: [[TMP1:%.*]] = udiv i64 60392, [[TMP0]]
19 ; CHECK-NEXT: br label [[LOOP2:%.*]]
21 ; CHECK-NEXT: [[INDVARS_IV1:%.*]] = phi i64 [ [[TMP1]], [[LOOP2_PREHEADER]] ], [ [[INDVARS_IV_NEXT2:%.*]], [[LOOP2]] ]
22 ; CHECK-NEXT: [[INDVARS_IV_NEXT2]] = add nuw nsw i64 [[INDVARS_IV1]], -1
23 ; CHECK-NEXT: [[I4:%.*]] = load atomic i64, i64* [[P1:%.*]] unordered, align 8
24 ; CHECK-NEXT: [[I6:%.*]] = sub i64 [[I4]], [[INDVARS_IV_NEXT2]]
25 ; CHECK-NEXT: store atomic i64 [[I6]], i64* [[P1]] unordered, align 8
26 ; CHECK-NEXT: br i1 true, label [[LOOP2_EXIT_LOOPEXIT:%.*]], label [[LOOP2]]
27 ; CHECK: loop2.exit.loopexit:
28 ; CHECK-NEXT: br label [[LOOP2_EXIT]]
30 ; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
31 ; CHECK-NEXT: br i1 false, label [[EXIT]], label [[LOOP1]]
33 ; CHECK-NEXT: ret i32 0
38 loop1: ; preds = %loop2.exit, %entry
39 %local_0_ = phi i32 [ 8, %entry ], [ %i9, %loop2.exit ]
40 %local_2_ = phi i32 [ 63864, %entry ], [ %local_2_43, %loop2.exit ]
41 %local_3_ = phi i32 [ 51, %entry ], [ %local_3_44, %loop2.exit ]
42 %i = udiv i32 14, %local_0_
43 %i1 = icmp ugt i32 %local_0_, 14
44 br i1 %i1, label %exit, label %general_case24
46 general_case24: ; preds = %loop1
47 %i2 = udiv i32 60392, %i
48 br i1 false, label %loop2, label %loop2.exit
50 loop2: ; preds = %loop2, %general_case24
51 %local_1_56 = phi i32 [ %i2, %general_case24 ], [ %i3, %loop2 ]
52 %local_2_57 = phi i32 [ 1, %general_case24 ], [ %i7, %loop2 ]
53 %i3 = add i32 %local_1_56, -1
54 %i4 = load atomic i64, i64* %p1 unordered, align 8
55 %i5 = sext i32 %i3 to i64
56 %i6 = sub i64 %i4, %i5
57 store atomic i64 %i6, i64* %p1 unordered, align 8
58 %i7 = add nuw nsw i32 %local_2_57, 1
59 %i8 = icmp ugt i32 %local_2_57, 7
60 br i1 %i8, label %loop2.exit, label %loop2
62 loop2.exit: ; preds = %loop2, %general_case24
63 %local_2_43 = phi i32 [ %local_2_, %general_case24 ], [ 9, %loop2 ]
64 %local_3_44 = phi i32 [ %local_3_, %general_case24 ], [ %local_1_56, %loop2 ]
65 %i9 = add nuw nsw i32 %local_0_, 1
66 %i10 = icmp ugt i32 %local_0_, 129
67 br i1 %i10, label %exit, label %loop1
69 exit: ; preds = %loop2.exit, %loop1
73 define i32 @testRem(i8* %p, i64* %p1) {
74 ; CHECK-LABEL: @testRem(
76 ; CHECK-NEXT: br label [[LOOP1:%.*]]
78 ; CHECK-NEXT: [[LOCAL_0_:%.*]] = phi i32 [ 8, [[ENTRY:%.*]] ], [ [[I9:%.*]], [[LOOP2_EXIT:%.*]] ]
79 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i32 [[LOCAL_0_]], 15
80 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[EXIT:%.*]], label [[GENERAL_CASE24:%.*]]
81 ; CHECK: general_case24:
82 ; CHECK-NEXT: br i1 false, label [[LOOP2_PREHEADER:%.*]], label [[LOOP2_EXIT]]
83 ; CHECK: loop2.preheader:
84 ; CHECK-NEXT: [[TMP0:%.*]] = udiv i32 14, [[LOCAL_0_]]
85 ; CHECK-NEXT: [[TMP1:%.*]] = udiv i32 60392, [[TMP0]]
86 ; CHECK-NEXT: [[TMP2:%.*]] = mul i32 [[TMP1]], -1
87 ; CHECK-NEXT: [[TMP3:%.*]] = mul i32 [[TMP2]], [[TMP0]]
88 ; CHECK-NEXT: [[TMP4:%.*]] = sext i32 [[TMP3]] to i64
89 ; CHECK-NEXT: [[TMP5:%.*]] = add nsw i64 [[TMP4]], 60392
90 ; CHECK-NEXT: br label [[LOOP2:%.*]]
92 ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ [[TMP5]], [[LOOP2_PREHEADER]] ], [ [[INDVARS_IV_NEXT:%.*]], [[LOOP2]] ]
93 ; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nsw i64 [[INDVARS_IV]], -1
94 ; CHECK-NEXT: [[I4:%.*]] = load atomic i64, i64* [[P1:%.*]] unordered, align 8
95 ; CHECK-NEXT: [[I6:%.*]] = sub i64 [[I4]], [[INDVARS_IV_NEXT]]
96 ; CHECK-NEXT: store atomic i64 [[I6]], i64* [[P1]] unordered, align 8
97 ; CHECK-NEXT: br i1 true, label [[LOOP2_EXIT_LOOPEXIT:%.*]], label [[LOOP2]]
98 ; CHECK: loop2.exit.loopexit:
99 ; CHECK-NEXT: br label [[LOOP2_EXIT]]
101 ; CHECK-NEXT: [[I9]] = add nuw nsw i32 [[LOCAL_0_]], 1
102 ; CHECK-NEXT: br i1 false, label [[EXIT]], label [[LOOP1]]
104 ; CHECK-NEXT: ret i32 0
109 loop1: ; preds = %loop2.exit, %entry
110 %local_0_ = phi i32 [ 8, %entry ], [ %i9, %loop2.exit ]
111 %local_2_ = phi i32 [ 63864, %entry ], [ %local_2_43, %loop2.exit ]
112 %local_3_ = phi i32 [ 51, %entry ], [ %local_3_44, %loop2.exit ]
113 %i = udiv i32 14, %local_0_
114 %i1 = icmp ugt i32 %local_0_, 14
115 br i1 %i1, label %exit, label %general_case24
117 general_case24: ; preds = %loop1
118 %i2 = urem i32 60392, %i
119 br i1 false, label %loop2, label %loop2.exit
121 loop2: ; preds = %loop2, %general_case24
122 %local_1_56 = phi i32 [ %i2, %general_case24 ], [ %i3, %loop2 ]
123 %local_2_57 = phi i32 [ 1, %general_case24 ], [ %i7, %loop2 ]
124 %i3 = add i32 %local_1_56, -1
125 %i4 = load atomic i64, i64* %p1 unordered, align 8
126 %i5 = sext i32 %i3 to i64
127 %i6 = sub i64 %i4, %i5
128 store atomic i64 %i6, i64* %p1 unordered, align 8
129 %i7 = add nuw nsw i32 %local_2_57, 1
130 %i8 = icmp ugt i32 %local_2_57, 7
131 br i1 %i8, label %loop2.exit, label %loop2
133 loop2.exit: ; preds = %loop2, %general_case24
134 %local_2_43 = phi i32 [ %local_2_, %general_case24 ], [ 9, %loop2 ]
135 %local_3_44 = phi i32 [ %local_3_, %general_case24 ], [ %local_1_56, %loop2 ]
136 %i9 = add nuw nsw i32 %local_0_, 1
137 %i10 = icmp ugt i32 %local_0_, 129
138 br i1 %i10, label %exit, label %loop1
140 exit: ; preds = %loop2.exit, %loop1