1; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py 2; RUN: opt -disable-output "-passes=print<scalar-evolution>" -S < %s 2>&1 | FileCheck %s 3 4define i16 @test1(i8 %x) { 5; CHECK-LABEL: 'test1' 6; CHECK-NEXT: Classifying expressions for: @test1 7; CHECK-NEXT: %A = zext i8 %x to i12 8; CHECK-NEXT: --> (zext i8 %x to i12) U: [0,256) S: [0,256) 9; CHECK-NEXT: %B = sext i12 %A to i16 10; CHECK-NEXT: --> (zext i8 %x to i16) U: [0,256) S: [0,256) 11; CHECK-NEXT: Determining loop execution counts for: @test1 12; 13 %A = zext i8 %x to i12 14 %B = sext i12 %A to i16 15 ret i16 %B 16} 17 18define i8 @test2(i8 %x) { 19; CHECK-LABEL: 'test2' 20; CHECK-NEXT: Classifying expressions for: @test2 21; CHECK-NEXT: %A = zext i8 %x to i16 22; CHECK-NEXT: --> (zext i8 %x to i16) U: [0,256) S: [0,256) 23; CHECK-NEXT: %B = add i16 %A, 1025 24; CHECK-NEXT: --> (1025 + (zext i8 %x to i16))<nuw><nsw> U: [1025,1281) S: [1025,1281) 25; CHECK-NEXT: %C = trunc i16 %B to i8 26; CHECK-NEXT: --> (1 + %x) U: full-set S: full-set 27; CHECK-NEXT: Determining loop execution counts for: @test2 28; 29 %A = zext i8 %x to i16 30 %B = add i16 %A, 1025 31 %C = trunc i16 %B to i8 32 ret i8 %C 33} 34 35define i8 @test3(i8 %x) { 36; CHECK-LABEL: 'test3' 37; CHECK-NEXT: Classifying expressions for: @test3 38; CHECK-NEXT: %A = zext i8 %x to i16 39; CHECK-NEXT: --> (zext i8 %x to i16) U: [0,256) S: [0,256) 40; CHECK-NEXT: %B = mul i16 %A, 1027 41; CHECK-NEXT: --> (1027 * (zext i8 %x to i16)) U: full-set S: full-set 42; CHECK-NEXT: %C = trunc i16 %B to i8 43; CHECK-NEXT: --> (3 * %x) U: full-set S: full-set 44; CHECK-NEXT: Determining loop execution counts for: @test3 45; 46 %A = zext i8 %x to i16 47 %B = mul i16 %A, 1027 48 %C = trunc i16 %B to i8 49 ret i8 %C 50} 51 52define void @test4(i32 %x, i32 %y) { 53; CHECK-LABEL: 'test4' 54; CHECK-NEXT: Classifying expressions for: @test4 55; CHECK-NEXT: %Y = and i32 %y, 3 56; CHECK-NEXT: --> (zext i2 (trunc i32 %y to i2) to i32) U: [0,4) S: [0,4) 57; CHECK-NEXT: %A = phi i32 [ 0, %entry ], [ %I, %loop ] 58; CHECK-NEXT: --> {0,+,1}<nuw><nsw><%loop> U: [0,21) S: [0,21) Exits: 20 LoopDispositions: { %loop: Computable } 59; CHECK-NEXT: %Z1 = select i1 %rand1, i32 %A, i32 %Y 60; CHECK-NEXT: --> ((zext i2 (trunc i32 %y to i2) to i32) smax {0,+,1}<nuw><nsw><%loop>) U: [0,21) S: [0,21) Exits: 20 LoopDispositions: { %loop: Computable } 61; CHECK-NEXT: %Z2 = select i1 %rand2, i32 %A, i32 %Z1 62; CHECK-NEXT: --> ({0,+,1}<nuw><nsw><%loop> umax ((zext i2 (trunc i32 %y to i2) to i32) smax {0,+,1}<nuw><nsw><%loop>)) U: [0,21) S: [0,21) Exits: 20 LoopDispositions: { %loop: Computable } 63; CHECK-NEXT: %B = trunc i32 %Z2 to i16 64; CHECK-NEXT: --> (trunc i32 ({0,+,1}<nuw><nsw><%loop> umax ((zext i2 (trunc i32 %y to i2) to i32) smax {0,+,1}<nuw><nsw><%loop>)) to i16) U: [0,21) S: [0,21) Exits: 20 LoopDispositions: { %loop: Computable } 65; CHECK-NEXT: %C = sext i16 %B to i30 66; CHECK-NEXT: --> (trunc i32 ({0,+,1}<nuw><nsw><%loop> umax ((zext i2 (trunc i32 %y to i2) to i32) smax {0,+,1}<nuw><nsw><%loop>)) to i30) U: [0,21) S: [0,21) Exits: 20 LoopDispositions: { %loop: Computable } 67; CHECK-NEXT: %D = sext i16 %B to i32 68; CHECK-NEXT: --> ({0,+,1}<nuw><nsw><%loop> umax ((zext i2 (trunc i32 %y to i2) to i32) smax {0,+,1}<nuw><nsw><%loop>)) U: [0,21) S: [0,21) Exits: 20 LoopDispositions: { %loop: Computable } 69; CHECK-NEXT: %E = sext i16 %B to i34 70; CHECK-NEXT: --> ((zext i32 ((zext i2 (trunc i32 %y to i2) to i32) smax {0,+,1}<nuw><nsw><%loop>) to i34) umax {0,+,1}<nuw><nsw><%loop>) U: [0,21) S: [0,21) Exits: 20 LoopDispositions: { %loop: Computable } 71; CHECK-NEXT: %F = zext i16 %B to i30 72; CHECK-NEXT: --> (trunc i32 ({0,+,1}<nuw><nsw><%loop> umax ((zext i2 (trunc i32 %y to i2) to i32) smax {0,+,1}<nuw><nsw><%loop>)) to i30) U: [0,21) S: [0,21) Exits: 20 LoopDispositions: { %loop: Computable } 73; CHECK-NEXT: %G = zext i16 %B to i32 74; CHECK-NEXT: --> ({0,+,1}<nuw><nsw><%loop> umax ((zext i2 (trunc i32 %y to i2) to i32) smax {0,+,1}<nuw><nsw><%loop>)) U: [0,21) S: [0,21) Exits: 20 LoopDispositions: { %loop: Computable } 75; CHECK-NEXT: %H = zext i16 %B to i34 76; CHECK-NEXT: --> ((zext i32 ((zext i2 (trunc i32 %y to i2) to i32) smax {0,+,1}<nuw><nsw><%loop>) to i34) umax {0,+,1}<nuw><nsw><%loop>) U: [0,21) S: [0,21) Exits: 20 LoopDispositions: { %loop: Computable } 77; CHECK-NEXT: %I = add i32 %A, 1 78; CHECK-NEXT: --> {1,+,1}<nuw><nsw><%loop> U: [1,22) S: [1,22) Exits: 21 LoopDispositions: { %loop: Computable } 79; CHECK-NEXT: Determining loop execution counts for: @test4 80; CHECK-NEXT: Loop %loop: backedge-taken count is i32 20 81; CHECK-NEXT: Loop %loop: constant max backedge-taken count is i32 20 82; CHECK-NEXT: Loop %loop: symbolic max backedge-taken count is i32 20 83; CHECK-NEXT: Loop %loop: Trip multiple is 21 84; 85entry: 86 %Y = and i32 %y, 3 87 br label %loop 88loop: 89 %A = phi i32 [0, %entry], [%I, %loop] 90 %rand1 = icmp sgt i32 %A, %Y 91 %Z1 = select i1 %rand1, i32 %A, i32 %Y 92 %rand2 = icmp ugt i32 %A, %Z1 93 %Z2 = select i1 %rand2, i32 %A, i32 %Z1 94 %B = trunc i32 %Z2 to i16 95 %C = sext i16 %B to i30 96 %D = sext i16 %B to i32 97 %E = sext i16 %B to i34 98 %F = zext i16 %B to i30 99 %G = zext i16 %B to i32 100 %H = zext i16 %B to i34 101 %I = add i32 %A, 1 102 %0 = icmp ne i32 %A, 20 103 br i1 %0, label %loop, label %exit 104exit: 105 ret void 106} 107 108define void @test5(i32 %i) { 109; CHECK-LABEL: 'test5' 110; CHECK-NEXT: Classifying expressions for: @test5 111; CHECK-NEXT: %A = and i32 %i, 1 112; CHECK-NEXT: --> (zext i1 (trunc i32 %i to i1) to i32) U: [0,2) S: [0,2) 113; CHECK-NEXT: %B = and i32 %i, 2 114; CHECK-NEXT: --> (2 * (zext i1 (trunc i32 (%i /u 2) to i1) to i32))<nuw><nsw> U: [0,3) S: [0,3) 115; CHECK-NEXT: %C = and i32 %i, 63 116; CHECK-NEXT: --> (zext i6 (trunc i32 %i to i6) to i32) U: [0,64) S: [0,64) 117; CHECK-NEXT: %D = and i32 %i, 126 118; CHECK-NEXT: --> (2 * (zext i6 (trunc i32 (%i /u 2) to i6) to i32))<nuw><nsw> U: [0,127) S: [0,127) 119; CHECK-NEXT: %E = and i32 %i, 64 120; CHECK-NEXT: --> (64 * (zext i1 (trunc i32 (%i /u 64) to i1) to i32))<nuw><nsw> U: [0,65) S: [0,65) 121; CHECK-NEXT: %F = and i32 %i, -2147483648 122; CHECK-NEXT: --> (-2147483648 * (%i /u -2147483648))<nuw><nsw> U: [0,-2147483647) S: [-2147483648,1) 123; CHECK-NEXT: Determining loop execution counts for: @test5 124; 125 %A = and i32 %i, 1 126 %B = and i32 %i, 2 127 %C = and i32 %i, 63 128 %D = and i32 %i, 126 129 %E = and i32 %i, 64 130 %F = and i32 %i, -2147483648 131 ret void 132} 133 134define void @test6(i8 %x) { 135; CHECK-LABEL: 'test6' 136; CHECK-NEXT: Classifying expressions for: @test6 137; CHECK-NEXT: %A = zext i8 %x to i16 138; CHECK-NEXT: --> (zext i8 %x to i16) U: [0,256) S: [0,256) 139; CHECK-NEXT: %B = shl nuw i16 %A, 8 140; CHECK-NEXT: --> (256 * (zext i8 %x to i16))<nuw> U: [0,-255) S: [-32768,32513) 141; CHECK-NEXT: %C = and i16 %B, -2048 142; CHECK-NEXT: --> (2048 * ((zext i8 %x to i16) /u 8))<nuw> U: [0,-2047) S: [-32768,30721) 143; CHECK-NEXT: Determining loop execution counts for: @test6 144; 145 %A = zext i8 %x to i16 146 %B = shl nuw i16 %A, 8 147 %C = and i16 %B, -2048 148 ret void 149} 150 151; PR22960 152define void @test7(i32 %A) { 153; CHECK-LABEL: 'test7' 154; CHECK-NEXT: Classifying expressions for: @test7 155; CHECK-NEXT: %B = sext i32 %A to i64 156; CHECK-NEXT: --> (sext i32 %A to i64) U: [-2147483648,2147483648) S: [-2147483648,2147483648) 157; CHECK-NEXT: %C = zext i32 %A to i64 158; CHECK-NEXT: --> (zext i32 %A to i64) U: [0,4294967296) S: [0,4294967296) 159; CHECK-NEXT: %D = sub i64 %B, %C 160; CHECK-NEXT: --> ((sext i32 %A to i64) + (-1 * (zext i32 %A to i64))<nsw>) U: [-6442450943,2147483648) S: [-6442450943,2147483648) 161; CHECK-NEXT: %E = trunc i64 %D to i16 162; CHECK-NEXT: --> 0 U: [0,1) S: [0,1) 163; CHECK-NEXT: Determining loop execution counts for: @test7 164; 165 %B = sext i32 %A to i64 166 %C = zext i32 %A to i64 167 %D = sub i64 %B, %C 168 %E = trunc i64 %D to i16 169 ret void 170} 171 172define i64 @test8(i64 %a) { 173; CHECK-LABEL: 'test8' 174; CHECK-NEXT: Classifying expressions for: @test8 175; CHECK-NEXT: %t0 = udiv i64 %a, 56 176; CHECK-NEXT: --> (%a /u 56) U: [0,329406144173384851) S: [0,329406144173384851) 177; CHECK-NEXT: %t1 = udiv i64 %t0, 56 178; CHECK-NEXT: --> (%a /u 3136) U: [0,5882252574524730) S: [0,5882252574524730) 179; CHECK-NEXT: Determining loop execution counts for: @test8 180; 181 %t0 = udiv i64 %a, 56 182 %t1 = udiv i64 %t0, 56 183 ret i64 %t1 184} 185 186define i64 @test9(i64 %a) { 187; CHECK-LABEL: 'test9' 188; CHECK-NEXT: Classifying expressions for: @test9 189; CHECK-NEXT: %t0 = udiv i64 %a, 100000000000000 190; CHECK-NEXT: --> (%a /u 100000000000000) U: [0,184468) S: [0,184468) 191; CHECK-NEXT: %t1 = udiv i64 %t0, 100000000000000 192; CHECK-NEXT: --> 0 U: [0,1) S: [0,1) 193; CHECK-NEXT: Determining loop execution counts for: @test9 194; 195 %t0 = udiv i64 %a, 100000000000000 196 %t1 = udiv i64 %t0, 100000000000000 197 ret i64 %t1 198} 199 200define i64 @test10(i64 %a, i64 %b) { 201; CHECK-LABEL: 'test10' 202; CHECK-NEXT: Classifying expressions for: @test10 203; CHECK-NEXT: %t0 = udiv i64 %a, 100000000000000 204; CHECK-NEXT: --> (%a /u 100000000000000) U: [0,184468) S: [0,184468) 205; CHECK-NEXT: %t1 = udiv i64 %t0, 100000000000000 206; CHECK-NEXT: --> 0 U: [0,1) S: [0,1) 207; CHECK-NEXT: %t2 = mul i64 %b, %t1 208; CHECK-NEXT: --> 0 U: [0,1) S: [0,1) 209; CHECK-NEXT: Determining loop execution counts for: @test10 210; 211 %t0 = udiv i64 %a, 100000000000000 212 %t1 = udiv i64 %t0, 100000000000000 213 %t2 = mul i64 %b, %t1 214 ret i64 %t2 215} 216 217define i64 @test11(i64 %a) { 218; CHECK-LABEL: 'test11' 219; CHECK-NEXT: Classifying expressions for: @test11 220; CHECK-NEXT: %t0 = udiv i64 0, %a 221; CHECK-NEXT: --> 0 U: [0,1) S: [0,1) 222; CHECK-NEXT: Determining loop execution counts for: @test11 223; 224 %t0 = udiv i64 0, %a 225 ret i64 %t0 226} 227