Eric Christopher | cee313d | 2019-04-17 04:52:47 +0000 | [diff] [blame] | 1 | ; RUN: opt -S -indvars < %s | FileCheck %s |
| 2 | |
| 3 | ; Produced from the test-case: |
| 4 | ; |
| 5 | ; extern void foo(char *, unsigned , unsigned *); |
| 6 | ; extern void bar(int *, long); |
| 7 | ; extern char *processBuf(char *); |
| 8 | ; |
| 9 | ; extern unsigned theSize; |
| 10 | ; |
| 11 | ; void foo(char *buf, unsigned denominator, unsigned *flag) { |
| 12 | ; int incr = (int) (theSize / denominator); |
| 13 | ; int inx = 0; |
| 14 | ; while (*flag) { |
| 15 | ; int itmp = inx + incr; |
| 16 | ; int i = (int) theSize; |
| 17 | ; bar(&i, (long) itmp); |
| 18 | ; buf = processBuf(buf); |
| 19 | ; inx = itmp; |
| 20 | ; } |
| 21 | ; } |
| 22 | |
| 23 | target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" |
| 24 | |
| 25 | @theSize = external local_unnamed_addr global i32, align 4 |
| 26 | |
| 27 | define void @foo(i8* %buf, i32 %denominator, i32* %flag) local_unnamed_addr { |
| 28 | entry: |
| 29 | %i = alloca i32, align 4 |
| 30 | %0 = load i32, i32* @theSize, align 4 |
| 31 | %div = udiv i32 %0, %denominator |
| 32 | %1 = load i32, i32* %flag, align 4 |
| 33 | %tobool5 = icmp eq i32 %1, 0 |
| 34 | br i1 %tobool5, label %while.end, label %while.body.lr.ph |
| 35 | |
| 36 | while.body.lr.ph: ; preds = %entry |
| 37 | %2 = bitcast i32* %i to i8* |
| 38 | br label %while.body |
| 39 | |
| 40 | while.body: ; preds = %while.body.lr.ph, %while.body |
| 41 | ; Check that there are two PHIs followed by a 'sext' in the same block, and that |
| 42 | ; the test does not crash. |
| 43 | ; CHECK: phi |
| 44 | ; CHECK-NEXT: phi |
| 45 | ; CHECK-NEXT: sext |
| 46 | %buf.addr.07 = phi i8* [ %buf, %while.body.lr.ph ], [ %call, %while.body ] |
| 47 | %inx.06 = phi i32 [ 0, %while.body.lr.ph ], [ %add, %while.body ] |
| 48 | %add = add nsw i32 %inx.06, %div |
| 49 | %3 = load i32, i32* @theSize, align 4 |
| 50 | store i32 %3, i32* %i, align 4 |
| 51 | %conv = sext i32 %add to i64 |
| 52 | call void @bar(i32* nonnull %i, i64 %conv) |
| 53 | %call = call i8* @processBuf(i8* %buf.addr.07) |
| 54 | %4 = load i32, i32* %flag, align 4 |
| 55 | %tobool = icmp eq i32 %4, 0 |
| 56 | br i1 %tobool, label %while.end.loopexit, label %while.body |
| 57 | |
| 58 | while.end.loopexit: ; preds = %while.body |
| 59 | br label %while.end |
| 60 | |
| 61 | while.end: ; preds = %while.end.loopexit, %entry |
| 62 | ret void |
| 63 | } |
| 64 | |
| 65 | declare void @bar(i32*, i64) local_unnamed_addr |
| 66 | declare i8* @processBuf(i8*) local_unnamed_addr |