1 ; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py 2 ; RUN: opt -S -analyze -scalar-evolution < %s | FileCheck %s 3 4 ; These testcases aren't *identical* but they have the same/similar meaning. 5 6 ; The obvious case. 7 define i32 @mul(i32 %val, i32 %num) nounwind { 8 ; CHECK-LABEL: 'mul' 9 ; CHECK-NEXT: Classifying expressions for: @mul 10 ; CHECK-NEXT: %tmp1 = mul i32 %val, %num 11 ; CHECK-NEXT: --> (%val * %num) U: full-set S: full-set 12 ; CHECK-NEXT: %tmp2 = udiv i32 %tmp1, %num 13 ; CHECK-NEXT: --> ((%val * %num) /u %num) U: full-set S: full-set 14 ; CHECK-NEXT: Determining loop execution counts for: @mul 15 ; 16 %tmp1 = mul i32 %val, %num 17 %tmp2 = udiv i32 %tmp1, %num 18 ret i32 %tmp2 19 } 20 21 ; Or, it could be any number of equivalent patterns with mask: 22 ; a) x & (1 << nbits) - 1 23 ; b) x & ~(-1 << nbits) 24 ; c) x & (-1 >> (32 - y)) 25 ; d) x << (32 - y) >> (32 - y) 26 27 define i32 @mask_a(i32 %val, i32 %numlowbits) nounwind { 28 ; CHECK-LABEL: 'mask_a' 29 ; CHECK-NEXT: Classifying expressions for: @mask_a 30 ; CHECK-NEXT: %onebit = shl i32 1, %numlowbits 31 ; CHECK-NEXT: --> %onebit U: full-set S: full-set 32 ; CHECK-NEXT: %mask = add nsw i32 %onebit, -1 33 ; CHECK-NEXT: --> (-1 + %onebit) U: full-set S: full-set 34 ; CHECK-NEXT: %masked = and i32 %mask, %val 35 ; CHECK-NEXT: --> %masked U: full-set S: full-set 36 ; CHECK-NEXT: Determining loop execution counts for: @mask_a 37 ; 38 %onebit = shl i32 1, %numlowbits 39 %mask = add nsw i32 %onebit, -1 40 %masked = and i32 %mask, %val 41 ret i32 %masked 42 } 43 44 define i32 @mask_b(i32 %val, i32 %numlowbits) nounwind { 45 ; CHECK-LABEL: 'mask_b' 46 ; CHECK-NEXT: Classifying expressions for: @mask_b 47 ; CHECK-NEXT: %notmask = shl i32 -1, %numlowbits 48 ; CHECK-NEXT: --> %notmask U: full-set S: full-set 49 ; CHECK-NEXT: %mask = xor i32 %notmask, -1 50 ; CHECK-NEXT: --> (-1 + (-1 * %notmask)) U: full-set S: full-set 51 ; CHECK-NEXT: %masked = and i32 %mask, %val 52 ; CHECK-NEXT: --> %masked U: full-set S: full-set 53 ; CHECK-NEXT: Determining loop execution counts for: @mask_b 54 ; 55 %notmask = shl i32 -1, %numlowbits 56 %mask = xor i32 %notmask, -1 57 %masked = and i32 %mask, %val 58 ret i32 %masked 59 } 60 61 define i32 @mask_c(i32 %val, i32 %numlowbits) nounwind { 62 ; CHECK-LABEL: 'mask_c' 63 ; CHECK-NEXT: Classifying expressions for: @mask_c 64 ; CHECK-NEXT: %numhighbits = sub i32 32, %numlowbits 65 ; CHECK-NEXT: --> (32 + (-1 * %numlowbits)) U: full-set S: full-set 66 ; CHECK-NEXT: %mask = lshr i32 -1, %numhighbits 67 ; CHECK-NEXT: --> %mask U: full-set S: full-set 68 ; CHECK-NEXT: %masked = and i32 %mask, %val 69 ; CHECK-NEXT: --> %masked U: full-set S: full-set 70 ; CHECK-NEXT: Determining loop execution counts for: @mask_c 71 ; 72 %numhighbits = sub i32 32, %numlowbits 73 %mask = lshr i32 -1, %numhighbits 74 %masked = and i32 %mask, %val 75 ret i32 %masked 76 } 77 78 define i32 @mask_d(i32 %val, i32 %numlowbits) nounwind { 79 ; CHECK-LABEL: 'mask_d' 80 ; CHECK-NEXT: Classifying expressions for: @mask_d 81 ; CHECK-NEXT: %numhighbits = sub i32 32, %numlowbits 82 ; CHECK-NEXT: --> (32 + (-1 * %numlowbits)) U: full-set S: full-set 83 ; CHECK-NEXT: %highbitscleared = shl i32 %val, %numhighbits 84 ; CHECK-NEXT: --> %highbitscleared U: full-set S: full-set 85 ; CHECK-NEXT: %masked = lshr i32 %highbitscleared, %numhighbits 86 ; CHECK-NEXT: --> %masked U: full-set S: full-set 87 ; CHECK-NEXT: Determining loop execution counts for: @mask_d 88 ; 89 %numhighbits = sub i32 32, %numlowbits 90 %highbitscleared = shl i32 %val, %numhighbits 91 %masked = lshr i32 %highbitscleared, %numhighbits 92 ret i32 %masked 93 } 94