1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; Test that the isdigit library call simplifier works correctly even for
3 ; targets with 16-bit int.
5 ; RUN: opt < %s -mtriple=avr-linux -passes=instcombine -S | FileCheck %s --check-prefix=AVR
6 ; RUN: opt < %s -mtriple=msp430-freebsd -passes=instcombine -S | FileCheck %s --check-prefix=MSP430
7 ; REQUIRES: avr-registered-target,msp430-registered-target
9 declare i16 @isdigit(i16)
11 declare void @sink(i16)
13 define void @fold_isdigit(i16 %c) {
14 ; AVR-LABEL: @fold_isdigit(
15 ; AVR-NEXT: call addrspace(1) void @sink(i16 0)
16 ; AVR-NEXT: call addrspace(1) void @sink(i16 0)
17 ; AVR-NEXT: call addrspace(1) void @sink(i16 0)
18 ; AVR-NEXT: call addrspace(1) void @sink(i16 1)
19 ; AVR-NEXT: call addrspace(1) void @sink(i16 1)
20 ; AVR-NEXT: call addrspace(1) void @sink(i16 1)
21 ; AVR-NEXT: call addrspace(1) void @sink(i16 0)
22 ; AVR-NEXT: call addrspace(1) void @sink(i16 0)
23 ; AVR-NEXT: call addrspace(1) void @sink(i16 0)
24 ; AVR-NEXT: call addrspace(1) void @sink(i16 0)
25 ; AVR-NEXT: call addrspace(1) void @sink(i16 0)
26 ; AVR-NEXT: call addrspace(1) void @sink(i16 0)
27 ; AVR-NEXT: [[ISDIGITTMP:%.*]] = add i16 [[C:%.*]], -48
28 ; AVR-NEXT: [[ISDIGIT:%.*]] = icmp ult i16 [[ISDIGITTMP]], 10
29 ; AVR-NEXT: [[IC:%.*]] = zext i1 [[ISDIGIT]] to i16
30 ; AVR-NEXT: call addrspace(1) void @sink(i16 [[IC]])
33 ; MSP430-LABEL: @fold_isdigit(
34 ; MSP430-NEXT: call void @sink(i16 0)
35 ; MSP430-NEXT: call void @sink(i16 0)
36 ; MSP430-NEXT: call void @sink(i16 0)
37 ; MSP430-NEXT: call void @sink(i16 1)
38 ; MSP430-NEXT: call void @sink(i16 1)
39 ; MSP430-NEXT: call void @sink(i16 1)
40 ; MSP430-NEXT: call void @sink(i16 0)
41 ; MSP430-NEXT: call void @sink(i16 0)
42 ; MSP430-NEXT: call void @sink(i16 0)
43 ; MSP430-NEXT: call void @sink(i16 0)
44 ; MSP430-NEXT: call void @sink(i16 0)
45 ; MSP430-NEXT: call void @sink(i16 0)
46 ; MSP430-NEXT: [[ISDIGITTMP:%.*]] = add i16 [[C:%.*]], -48
47 ; MSP430-NEXT: [[ISDIGIT:%.*]] = icmp ult i16 [[ISDIGITTMP]], 10
48 ; MSP430-NEXT: [[IC:%.*]] = zext i1 [[ISDIGIT]] to i16
49 ; MSP430-NEXT: call void @sink(i16 [[IC]])
50 ; MSP430-NEXT: ret void
52 %i0 = call i16 @isdigit(i16 0)
53 call void @sink(i16 %i0)
55 %i1 = call i16 @isdigit(i16 1)
56 call void @sink(i16 %i1)
58 ; Fold isdigit('/') to 0.
59 %i47 = call i16 @isdigit(i16 47)
60 call void @sink(i16 %i47)
62 ; Fold isdigit('0') to 1.
63 %i48 = call i16 @isdigit(i16 48)
64 call void @sink(i16 %i48)
66 ; Fold isdigit('1') to 1.
67 %i49 = call i16 @isdigit(i16 49)
68 call void @sink(i16 %i49)
70 ; Fold isdigit('9') to 1.
71 %i57 = call i16 @isdigit(i16 57)
72 call void @sink(i16 %i57)
74 ; Fold isdigit(':') to 0.
75 %i58 = call i16 @isdigit(i16 58)
76 call void @sink(i16 %i58)
78 %i127 = call i16 @isdigit(i16 127)
79 call void @sink(i16 %i127)
81 %i128 = call i16 @isdigit(i16 128)
82 call void @sink(i16 %i128)
84 %i255 = call i16 @isdigit(i16 255)
85 call void @sink(i16 %i255)
87 ; Fold isdigit(256) to 0. The argument is required to be representable
88 ; in unsigned char but it's a common mistake to call the function with
89 ; other arguments and it's arguably safer to fold such calls than to
90 ; let the library call return an arbitrary value or crash.
91 %i256 = call i16 @isdigit(i16 256)
92 call void @sink(i16 %i256)
95 %imax = call i16 @isdigit(i16 32767)
96 call void @sink(i16 %imax)
98 %ic = call i16 @isdigit(i16 %c)
99 call void @sink(i16 %ic)