1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
2 ; RUN: opt -S -passes=indvars < %s | FileCheck %s
4 target datalayout = "n64"
8 define void @or_disjoint() {
9 ; CHECK-LABEL: define void @or_disjoint() {
11 ; CHECK-NEXT: br label [[LOOP:%.*]]
13 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ 2, [[ENTRY:%.*]] ], [ [[IV_DEC:%.*]], [[LOOP]] ]
14 ; CHECK-NEXT: [[OR:%.*]] = or disjoint i64 [[IV]], 1
15 ; CHECK-NEXT: [[ADD:%.*]] = add nuw nsw i64 [[IV]], 1
16 ; CHECK-NEXT: [[SEL:%.*]] = select i1 false, i64 [[OR]], i64 [[ADD]]
17 ; CHECK-NEXT: call void @use(i64 [[SEL]])
18 ; CHECK-NEXT: [[IV_DEC]] = add nsw i64 [[IV]], -1
19 ; CHECK-NEXT: [[EXIT_COND:%.*]] = icmp eq i64 [[IV_DEC]], 0
20 ; CHECK-NEXT: br i1 [[EXIT_COND]], label [[EXIT:%.*]], label [[LOOP]]
22 ; CHECK-NEXT: ret void
28 %iv = phi i64 [ 2, %entry ], [ %iv.dec, %loop ]
29 %or = or disjoint i64 %iv, 1
30 %add = add nsw i64 %iv, 1
31 %sel = select i1 false, i64 %or, i64 %add
32 call void @use(i64 %sel)
34 %iv.dec = add nsw i64 %iv, -1
35 %exit.cond = icmp eq i64 %iv.dec, 0
36 br i1 %exit.cond, label %exit, label %loop
42 define void @add_nowrap_flags(i64 %n) {
43 ; CHECK-LABEL: define void @add_nowrap_flags(
44 ; CHECK-SAME: i64 [[N:%.*]]) {
46 ; CHECK-NEXT: br label [[LOOP:%.*]]
48 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[IV_INC:%.*]], [[LOOP]] ]
49 ; CHECK-NEXT: [[ADD1:%.*]] = add i64 [[IV]], 123
50 ; CHECK-NEXT: call void @use(i64 [[ADD1]])
51 ; CHECK-NEXT: [[IV_INC]] = add i64 [[IV]], 1
52 ; CHECK-NEXT: [[EXIT_COND:%.*]] = icmp eq i64 [[IV_INC]], [[N]]
53 ; CHECK-NEXT: br i1 [[EXIT_COND]], label [[EXIT:%.*]], label [[LOOP]]
55 ; CHECK-NEXT: ret void
61 %iv = phi i64 [ 0, %entry ], [ %iv.inc, %loop ]
62 %add1 = add nuw nsw i64 %iv, 123
63 %add2 = add i64 %iv, 123
64 %sel = select i1 false, i64 %add1, i64 %add2
65 call void @use(i64 %sel)
67 %iv.inc = add i64 %iv, 1
68 %exit.cond = icmp eq i64 %iv.inc, %n
69 br i1 %exit.cond, label %exit, label %loop
76 define void @expander_or_disjoint(i64 %n) {
77 ; CHECK-LABEL: define void @expander_or_disjoint(
78 ; CHECK-SAME: i64 [[N:%.*]]) {
80 ; CHECK-NEXT: [[OR:%.*]] = or disjoint i64 [[N]], 1
81 ; CHECK-NEXT: [[TMP0:%.*]] = add i64 [[N]], 1
82 ; CHECK-NEXT: br label [[LOOP:%.*]]
84 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[IV_INC:%.*]], [[LOOP]] ]
85 ; CHECK-NEXT: [[IV_INC]] = add i64 [[IV]], 1
86 ; CHECK-NEXT: [[ADD:%.*]] = add i64 [[IV]], [[OR]]
87 ; CHECK-NEXT: call void @use(i64 [[ADD]])
88 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne i64 [[IV_INC]], [[TMP0]]
89 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[LOOP]], label [[EXIT:%.*]]
91 ; CHECK-NEXT: ret void
94 %or = or disjoint i64 %n, 1
98 %iv = phi i64 [ 0, %entry ], [ %iv.inc, %loop ]
99 %iv.inc = add i64 %iv, 1
100 %add = add i64 %iv, %or
101 call void @use(i64 %add)
102 %cmp = icmp ult i64 %iv, %n
103 br i1 %cmp, label %loop, label %exit