1; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py 2; RUN: opt -S -analyze -enable-new-pm=0 -scalar-evolution < %s | FileCheck %s 3; RUN: opt -S -disable-output "-passes=print<scalar-evolution>" < %s 2>&1 | FileCheck %s 4 5; The obvious case. 6define i32 @mul_biggerShl(i32 %val) nounwind { 7; CHECK-LABEL: 'mul_biggerShl' 8; CHECK-NEXT: Classifying expressions for: @mul_biggerShl 9; CHECK-NEXT: %tmp1 = mul i32 %val, 64 10; CHECK-NEXT: --> (64 * %val) U: [0,-63) S: [-2147483648,2147483585) 11; CHECK-NEXT: %tmp2 = udiv i32 %tmp1, 16 12; CHECK-NEXT: --> ((64 * %val) /u 16) U: [0,268435453) S: [0,268435456) 13; CHECK-NEXT: Determining loop execution counts for: @mul_biggerShl 14; 15 %tmp1 = mul i32 %val, 64 16 %tmp2 = udiv i32 %tmp1, 16 17 ret i32 %tmp2 18} 19 20define i32 @mul_biggerLshl(i32 %val) nounwind { 21; CHECK-LABEL: 'mul_biggerLshl' 22; CHECK-NEXT: Classifying expressions for: @mul_biggerLshl 23; CHECK-NEXT: %tmp1 = mul i32 %val, 16 24; CHECK-NEXT: --> (16 * %val) U: [0,-15) S: [-2147483648,2147483633) 25; CHECK-NEXT: %tmp2 = udiv i32 %tmp1, 64 26; CHECK-NEXT: --> ((16 * %val) /u 64) U: [0,67108864) S: [0,67108864) 27; CHECK-NEXT: Determining loop execution counts for: @mul_biggerLshl 28; 29 %tmp1 = mul i32 %val, 16 30 %tmp2 = udiv i32 %tmp1, 64 31 ret i32 %tmp2 32} 33 34; Or, it could have been transformed to shifts 35 36define i32 @shifty_biggerShl(i32 %val) { 37; CHECK-LABEL: 'shifty_biggerShl' 38; CHECK-NEXT: Classifying expressions for: @shifty_biggerShl 39; CHECK-NEXT: %tmp1 = shl i32 %val, 6 40; CHECK-NEXT: --> (64 * %val) U: [0,-63) S: [-2147483648,2147483585) 41; CHECK-NEXT: %tmp2 = lshr i32 %tmp1, 4 42; CHECK-NEXT: --> ((64 * %val) /u 16) U: [0,268435453) S: [0,268435456) 43; CHECK-NEXT: Determining loop execution counts for: @shifty_biggerShl 44; 45 %tmp1 = shl i32 %val, 6 46 %tmp2 = lshr i32 %tmp1, 4 47 ret i32 %tmp2 48} 49 50define i32 @shifty_biggerShl_shlnuw(i32 %val) { 51; CHECK-LABEL: 'shifty_biggerShl_shlnuw' 52; CHECK-NEXT: Classifying expressions for: @shifty_biggerShl_shlnuw 53; CHECK-NEXT: %tmp1 = shl nuw i32 %val, 6 54; CHECK-NEXT: --> (64 * %val) U: [0,-63) S: [-2147483648,2147483585) 55; CHECK-NEXT: %tmp2 = lshr i32 %tmp1, 4 56; CHECK-NEXT: --> ((64 * %val) /u 16) U: [0,268435453) S: [0,268435456) 57; CHECK-NEXT: Determining loop execution counts for: @shifty_biggerShl_shlnuw 58; 59 %tmp1 = shl nuw i32 %val, 6 60 %tmp2 = lshr i32 %tmp1, 4 61 ret i32 %tmp2 62} 63 64define i32 @shifty_biggerLshr(i32 %val) { 65; CHECK-LABEL: 'shifty_biggerLshr' 66; CHECK-NEXT: Classifying expressions for: @shifty_biggerLshr 67; CHECK-NEXT: %tmp1 = shl i32 %val, 4 68; CHECK-NEXT: --> (16 * %val) U: [0,-15) S: [-2147483648,2147483633) 69; CHECK-NEXT: %tmp2 = lshr i32 %tmp1, 6 70; CHECK-NEXT: --> ((16 * %val) /u 64) U: [0,67108864) S: [0,67108864) 71; CHECK-NEXT: Determining loop execution counts for: @shifty_biggerLshr 72; 73 %tmp1 = shl i32 %val, 4 74 %tmp2 = lshr i32 %tmp1, 6 75 ret i32 %tmp2 76} 77 78define i32 @shifty_biggerLshr_shlnuw(i32 %val) { 79; CHECK-LABEL: 'shifty_biggerLshr_shlnuw' 80; CHECK-NEXT: Classifying expressions for: @shifty_biggerLshr_shlnuw 81; CHECK-NEXT: %tmp1 = shl nuw i32 %val, 4 82; CHECK-NEXT: --> (16 * %val) U: [0,-15) S: [-2147483648,2147483633) 83; CHECK-NEXT: %tmp2 = lshr i32 %tmp1, 6 84; CHECK-NEXT: --> ((16 * %val) /u 64) U: [0,67108864) S: [0,67108864) 85; CHECK-NEXT: Determining loop execution counts for: @shifty_biggerLshr_shlnuw 86; 87 %tmp1 = shl nuw i32 %val, 4 88 %tmp2 = lshr i32 %tmp1, 6 89 ret i32 %tmp2 90} 91 92; Or, further folded into mask variant. 93 94define i32 @masky_biggerShl(i32 %val) { 95; CHECK-LABEL: 'masky_biggerShl' 96; CHECK-NEXT: Classifying expressions for: @masky_biggerShl 97; CHECK-NEXT: %tmp1 = shl i32 %val, 2 98; CHECK-NEXT: --> (4 * %val) U: [0,-3) S: [-2147483648,2147483645) 99; CHECK-NEXT: %tmp2 = and i32 %tmp1, 268435452 100; CHECK-NEXT: --> (4 * (zext i26 (trunc i32 %val to i26) to i32))<nuw><nsw> U: [0,268435453) S: [0,268435453) 101; CHECK-NEXT: Determining loop execution counts for: @masky_biggerShl 102; 103 %tmp1 = shl i32 %val, 2 104 %tmp2 = and i32 %tmp1, 268435452 105 ret i32 %tmp2 106} 107 108define i32 @masky_biggerShl_shlnuw(i32 %val) { 109; CHECK-LABEL: 'masky_biggerShl_shlnuw' 110; CHECK-NEXT: Classifying expressions for: @masky_biggerShl_shlnuw 111; CHECK-NEXT: %tmp1 = shl nuw i32 %val, 2 112; CHECK-NEXT: --> (4 * %val) U: [0,-3) S: [-2147483648,2147483645) 113; CHECK-NEXT: Determining loop execution counts for: @masky_biggerShl_shlnuw 114; 115 %tmp1 = shl nuw i32 %val, 2 116 ret i32 %tmp1 117} 118 119define i32 @masky_biggerLshr(i32 %val) { 120; CHECK-LABEL: 'masky_biggerLshr' 121; CHECK-NEXT: Classifying expressions for: @masky_biggerLshr 122; CHECK-NEXT: %tmp1 = lshr i32 %val, 2 123; CHECK-NEXT: --> (%val /u 4) U: [0,1073741824) S: [0,1073741824) 124; CHECK-NEXT: %tmp2 = and i32 %tmp1, 67108863 125; CHECK-NEXT: --> (zext i26 (trunc i32 (%val /u 4) to i26) to i32) U: [0,67108864) S: [0,67108864) 126; CHECK-NEXT: Determining loop execution counts for: @masky_biggerLshr 127; 128 %tmp1 = lshr i32 %val, 2 129 %tmp2 = and i32 %tmp1, 67108863 130 ret i32 %tmp2 131} 132 133define i32 @masky_biggerLshr_shlnuw(i32 %val) { 134; CHECK-LABEL: 'masky_biggerLshr_shlnuw' 135; CHECK-NEXT: Classifying expressions for: @masky_biggerLshr_shlnuw 136; CHECK-NEXT: %tmp1 = lshr i32 %val, 2 137; CHECK-NEXT: --> (%val /u 4) U: [0,1073741824) S: [0,1073741824) 138; CHECK-NEXT: Determining loop execution counts for: @masky_biggerLshr_shlnuw 139; 140 %tmp1 = lshr i32 %val, 2 141 ret i32 %tmp1 142} 143