1 ; RUN: opt -analyze -scalar-evolution < %s | FileCheck %s 2 3 ; An example run where SCEV(%postinc)->getStart() may overflow: 4 ; 5 ; %start = INT_SMAX 6 ; %low.limit = INT_SMIN 7 ; %high.limit = < not used > 8 ; 9 ; >> entry: 10 ; %postinc.start = INT_SMIN 11 ; 12 ; >> loop: 13 ; %idx = %start 14 ; %postinc = INT_SMIN 15 ; %postinc.inc = INT_SMIN + 1 16 ; %postinc.sext = sext(INT_SMIN) = i64 INT32_SMIN 17 ; %break.early = INT_SMIN `slt` INT_SMIN = false 18 ; br i1 false, ___, %early.exit 19 ; 20 ; >> early.exit: 21 ; ret i64 INT32_SMIN 22 23 24 define i64 @bad.0(i32 %start, i32 %low.limit, i32 %high.limit) { 25 ; CHECK-LABEL: Classifying expressions for: @bad.0 26 entry: 27 %postinc.start = add i32 %start, 1 28 br label %loop 29 30 loop: 31 %idx = phi i32 [ %start, %entry ], [ %idx.inc, %continue ] 32 %postinc = phi i32 [ %postinc.start, %entry ], [ %postinc.inc, %continue ] 33 %postinc.inc = add nsw i32 %postinc, 1 34 %postinc.sext = sext i32 %postinc to i64 35 ; CHECK: %postinc.sext = sext i32 %postinc to i64 36 ; CHECK-NEXT: --> {(sext i32 (1 + %start) to i64),+,1}<nsw><%loop> 37 %break.early = icmp slt i32 %postinc, %low.limit 38 br i1 %break.early, label %continue, label %early.exit 39 40 continue: 41 %idx.inc = add nsw i32 %idx, 1 42 %cmp = icmp slt i32 %idx.inc, %high.limit 43 br i1 %cmp, label %loop, label %exit 44 45 exit: 46 ret i64 0 47 48 early.exit: 49 ret i64 %postinc.sext 50 } 51 52 define i64 @bad.1(i32 %start, i32 %low.limit, i32 %high.limit, i1* %unknown) { 53 ; CHECK-LABEL: Classifying expressions for: @bad.1 54 entry: 55 %postinc.start = add i32 %start, 1 56 br label %loop 57 58 loop: 59 %idx = phi i32 [ %start, %entry ], [ %idx.inc, %continue ], [ %idx.inc, %continue.1 ] 60 %postinc = phi i32 [ %postinc.start, %entry ], [ %postinc.inc, %continue ], [ %postinc.inc, %continue.1 ] 61 %postinc.inc = add nsw i32 %postinc, 1 62 %postinc.sext = sext i32 %postinc to i64 63 ; CHECK: %postinc.sext = sext i32 %postinc to i64 64 ; CHECK-NEXT: --> {(sext i32 (1 + %start) to i64),+,1}<nsw><%loop> 65 %break.early = icmp slt i32 %postinc, %low.limit 66 br i1 %break.early, label %continue.1, label %early.exit 67 68 continue.1: 69 %cond = load volatile i1, i1* %unknown 70 %idx.inc = add nsw i32 %idx, 1 71 br i1 %cond, label %loop, label %continue 72 73 continue: 74 %cmp = icmp slt i32 %idx.inc, %high.limit 75 br i1 %cmp, label %loop, label %exit 76 77 exit: 78 ret i64 0 79 80 early.exit: 81 ret i64 %postinc.sext 82 } 83