1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
2 ; RUN: opt -S -passes=indvars < %s | FileCheck %s
4 ; Produced from the test-case:
6 ; extern void foo(char *, unsigned , unsigned *);
7 ; extern void bar(int *, long);
8 ; extern char *processBuf(char *);
10 ; extern unsigned theSize;
12 ; void foo(char *buf, unsigned denominator, unsigned *flag) {
13 ; int incr = (int) (theSize / denominator);
16 ; int itmp = inx + incr;
17 ; int i = (int) theSize;
18 ; bar(&i, (long) itmp);
19 ; buf = processBuf(buf);
24 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
26 @theSize = external local_unnamed_addr global i32, align 4
28 ; Check that there are two PHIs followed by a 'sext' in the same block, and that
29 ; the test does not crash.
30 define void @foo(ptr %buf, i32 %denominator, ptr %flag) local_unnamed_addr {
31 ; CHECK-LABEL: define void @foo
32 ; CHECK-SAME: (ptr [[BUF:%.*]], i32 [[DENOMINATOR:%.*]], ptr [[FLAG:%.*]]) local_unnamed_addr {
34 ; CHECK-NEXT: [[I:%.*]] = alloca i32, align 4
35 ; CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr @theSize, align 4
36 ; CHECK-NEXT: [[DIV:%.*]] = udiv i32 [[TMP0]], [[DENOMINATOR]]
37 ; CHECK-NEXT: [[TMP1:%.*]] = load i32, ptr [[FLAG]], align 4
38 ; CHECK-NEXT: [[TOBOOL5:%.*]] = icmp eq i32 [[TMP1]], 0
39 ; CHECK-NEXT: br i1 [[TOBOOL5]], label [[WHILE_END:%.*]], label [[WHILE_BODY_LR_PH:%.*]]
40 ; CHECK: while.body.lr.ph:
41 ; CHECK-NEXT: br label [[WHILE_BODY:%.*]]
43 ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ [[INDVARS_IV_NEXT:%.*]], [[WHILE_BODY]] ], [ 0, [[WHILE_BODY_LR_PH]] ]
44 ; CHECK-NEXT: [[BUF_ADDR_07:%.*]] = phi ptr [ [[BUF]], [[WHILE_BODY_LR_PH]] ], [ [[CALL:%.*]], [[WHILE_BODY]] ]
45 ; CHECK-NEXT: [[TMP2:%.*]] = sext i32 [[DIV]] to i64
46 ; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add i64 [[INDVARS_IV]], [[TMP2]]
47 ; CHECK-NEXT: [[TMP3:%.*]] = load i32, ptr @theSize, align 4
48 ; CHECK-NEXT: store i32 [[TMP3]], ptr [[I]], align 4
49 ; CHECK-NEXT: call void @bar(ptr nonnull [[I]], i64 [[INDVARS_IV_NEXT]])
50 ; CHECK-NEXT: [[CALL]] = call ptr @processBuf(ptr [[BUF_ADDR_07]])
51 ; CHECK-NEXT: [[TMP4:%.*]] = load i32, ptr [[FLAG]], align 4
52 ; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[TMP4]], 0
53 ; CHECK-NEXT: br i1 [[TOBOOL]], label [[WHILE_END_LOOPEXIT:%.*]], label [[WHILE_BODY]]
54 ; CHECK: while.end.loopexit:
55 ; CHECK-NEXT: br label [[WHILE_END]]
57 ; CHECK-NEXT: ret void
60 %i = alloca i32, align 4
61 %0 = load i32, ptr @theSize, align 4
62 %div = udiv i32 %0, %denominator
63 %1 = load i32, ptr %flag, align 4
64 %tobool5 = icmp eq i32 %1, 0
65 br i1 %tobool5, label %while.end, label %while.body.lr.ph
67 while.body.lr.ph: ; preds = %entry
70 while.body: ; preds = %while.body.lr.ph, %while.body
71 %buf.addr.07 = phi ptr [ %buf, %while.body.lr.ph ], [ %call, %while.body ]
72 %inx.06 = phi i32 [ 0, %while.body.lr.ph ], [ %add, %while.body ]
73 %add = add nsw i32 %inx.06, %div
74 %2 = load i32, ptr @theSize, align 4
75 store i32 %2, ptr %i, align 4
76 %conv = sext i32 %add to i64
77 call void @bar(ptr nonnull %i, i64 %conv)
78 %call = call ptr @processBuf(ptr %buf.addr.07)
79 %3 = load i32, ptr %flag, align 4
80 %tobool = icmp eq i32 %3, 0
81 br i1 %tobool, label %while.end.loopexit, label %while.body
83 while.end.loopexit: ; preds = %while.body
86 while.end: ; preds = %while.end.loopexit, %entry
90 declare void @bar(ptr, i64) local_unnamed_addr
91 declare ptr @processBuf(ptr) local_unnamed_addr