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 ; The obvious case. 5 define i32 @div(i32 %val) nounwind { 6 ; CHECK-LABEL: 'div' 7 ; CHECK-NEXT: Classifying expressions for: @div 8 ; CHECK-NEXT: %tmp1 = udiv i32 %val, 16 9 ; CHECK-NEXT: --> (%val /u 16) U: [0,268435456) S: [0,268435456) 10 ; CHECK-NEXT: %tmp2 = mul i32 %tmp1, 16 11 ; CHECK-NEXT: --> (16 * (%val /u 16))<nuw> U: [0,-15) S: [0,-15) 12 ; CHECK-NEXT: Determining loop execution counts for: @div 13 ; 14 %tmp1 = udiv i32 %val, 16 15 %tmp2 = mul i32 %tmp1, 16 16 ret i32 %tmp2 17 } 18 19 define i32 @sdiv(i32 %val) nounwind { 20 ; CHECK-LABEL: 'sdiv' 21 ; CHECK-NEXT: Classifying expressions for: @sdiv 22 ; CHECK-NEXT: %tmp1 = sdiv i32 %val, 16 23 ; CHECK-NEXT: --> %tmp1 U: full-set S: [-134217728,134217728) 24 ; CHECK-NEXT: %tmp2 = mul i32 %tmp1, 16 25 ; CHECK-NEXT: --> (16 * %tmp1)<nsw> U: [0,-15) S: [-2147483648,2147483633) 26 ; CHECK-NEXT: Determining loop execution counts for: @sdiv 27 ; 28 %tmp1 = sdiv i32 %val, 16 29 %tmp2 = mul i32 %tmp1, 16 30 ret i32 %tmp2 31 } 32 33 ; Or, it could be a number of equivalent patterns with mask: 34 ; b) x & (-1 << nbits) 35 ; d) x >> nbits << nbits 36 37 define i32 @mask_b(i32 %val) nounwind { 38 ; CHECK-LABEL: 'mask_b' 39 ; CHECK-NEXT: Classifying expressions for: @mask_b 40 ; CHECK-NEXT: %masked = and i32 %val, -16 41 ; CHECK-NEXT: --> (16 * (%val /u 16))<nuw> U: [0,-15) S: [0,-15) 42 ; CHECK-NEXT: Determining loop execution counts for: @mask_b 43 ; 44 %masked = and i32 %val, -16 45 ret i32 %masked 46 } 47 48 define i32 @mask_d(i32 %val) nounwind { 49 ; CHECK-LABEL: 'mask_d' 50 ; CHECK-NEXT: Classifying expressions for: @mask_d 51 ; CHECK-NEXT: %lowbitscleared = lshr i32 %val, 4 52 ; CHECK-NEXT: --> (%val /u 16) U: [0,268435456) S: [0,268435456) 53 ; CHECK-NEXT: %masked = shl i32 %lowbitscleared, 4 54 ; CHECK-NEXT: --> (16 * (%val /u 16))<nuw> U: [0,-15) S: [0,-15) 55 ; CHECK-NEXT: Determining loop execution counts for: @mask_d 56 ; 57 %lowbitscleared = lshr i32 %val, 4 58 %masked = shl i32 %lowbitscleared, 4 59 ret i32 %masked 60 } 61