1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
4 @.str = private unnamed_addr constant [3 x i8] c"12\00", align 1
5 @.str.1 = private unnamed_addr constant [2 x i8] c"0\00", align 1
6 @.str.2 = private unnamed_addr constant [11 x i8] c"4294967296\00", align 1
7 @.str.3 = private unnamed_addr constant [24 x i8] c"10000000000000000000000\00", align 1
8 @.str.4 = private unnamed_addr constant [20 x i8] c"9923372036854775807\00", align 1
9 @.str.5 = private unnamed_addr constant [11 x i8] c"4994967295\00", align 1
10 @.str.6 = private unnamed_addr constant [10 x i8] c"499496729\00", align 1
11 @.str.7 = private unnamed_addr constant [11 x i8] c"4994967295\00", align 1
13 declare i64 @strtol(ptr, ptr, i32)
14 declare i32 @atoi(ptr)
15 declare i64 @atol(ptr)
16 declare i64 @atoll(ptr)
17 declare i64 @strtoll(ptr, ptr, i32)
19 define i64 @strtol_dec() #0 {
20 ; CHECK-LABEL: @strtol_dec(
21 ; CHECK-NEXT: ret i64 12
23 %call = call i64 @strtol(ptr @.str, ptr null, i32 10) #2
27 define i64 @strtol_base_zero() #0 {
28 ; CHECK-LABEL: @strtol_base_zero(
29 ; CHECK-NEXT: ret i64 12
31 %call = call i64 @strtol(ptr @.str, ptr null, i32 0) #2
35 define i64 @strtol_hex() #0 {
36 ; CHECK-LABEL: @strtol_hex(
37 ; CHECK-NEXT: ret i64 18
39 %call = call i64 @strtol(ptr @.str, ptr null, i32 16) #2
43 ; Fold a call to strtol with an endptr known to be nonnull.
45 define i64 @strtol_endptr_not_null(ptr nonnull %pend) {
46 ; CHECK-LABEL: @strtol_endptr_not_null(
47 ; CHECK-NEXT: store ptr getelementptr inbounds (i8, ptr @.str, i64 2), ptr [[PEND:%.*]], align 8
48 ; CHECK-NEXT: ret i64 12
50 %call = call i64 @strtol(ptr @.str, ptr %pend, i32 10)
54 ; Don't fold a call to strtol with an endptr that's not known to be nonnull.
56 define i64 @strtol_endptr_maybe_null(ptr %end) {
57 ; CHECK-LABEL: @strtol_endptr_maybe_null(
58 ; CHECK-NEXT: [[CALL:%.*]] = call i64 @strtol(ptr nonnull @.str.1, ptr [[END:%.*]], i32 10)
59 ; CHECK-NEXT: ret i64 [[CALL]]
61 %call = call i64 @strtol(ptr @.str.1, ptr %end, i32 10)
65 define i32 @atoi_test() #0 {
66 ; CHECK-LABEL: @atoi_test(
67 ; CHECK-NEXT: ret i32 12
69 %call = call i32 @atoi(ptr @.str) #4
73 define i64 @strtol_not_const_str(ptr %s) #0 {
74 ; CHECK-LABEL: @strtol_not_const_str(
75 ; CHECK-NEXT: [[CALL:%.*]] = call i64 @strtol(ptr nocapture [[S:%.*]], ptr null, i32 10)
76 ; CHECK-NEXT: ret i64 [[CALL]]
78 %call = call i64 @strtol(ptr %s, ptr null, i32 10) #3
82 define i32 @atoi_not_const_str(ptr %s) #0 {
83 ; CHECK-LABEL: @atoi_not_const_str(
84 ; CHECK-NEXT: [[CALL:%.*]] = call i32 @atoi(ptr nocapture [[S:%.*]])
85 ; CHECK-NEXT: ret i32 [[CALL]]
87 %call = call i32 @atoi(ptr %s) #4
91 define i64 @strtol_not_const_base(i32 %b) #0 {
92 ; CHECK-LABEL: @strtol_not_const_base(
93 ; CHECK-NEXT: [[CALL:%.*]] = call i64 @strtol(ptr nocapture nonnull @.str, ptr null, i32 [[B:%.*]])
94 ; CHECK-NEXT: ret i64 [[CALL]]
96 %call = call i64 @strtol(ptr @.str, ptr null, i32 %b) #2
100 define i64 @strtol_long_int() #0 {
101 ; CHECK-LABEL: @strtol_long_int(
102 ; CHECK-NEXT: ret i64 4294967296
104 %call = call i64 @strtol(ptr @.str.2, ptr null, i32 10) #3
109 define i64 @strtol_big_overflow() #0 {
110 ; CHECK-LABEL: @strtol_big_overflow(
111 ; CHECK-NEXT: [[CALL:%.*]] = call i64 @strtol(ptr nocapture nonnull @.str.3, ptr null, i32 10)
112 ; CHECK-NEXT: ret i64 [[CALL]]
114 %call = call i64 @strtol(ptr nocapture @.str.3, ptr null, i32 10) #2
118 define i64 @atol_test() #0 {
119 ; CHECK-LABEL: @atol_test(
120 ; CHECK-NEXT: ret i64 499496729
123 %call = call i64 @atol(ptr @.str.6) #4
127 define i64 @atoll_test() #0 {
128 ; CHECK-LABEL: @atoll_test(
129 ; CHECK-NEXT: ret i64 4994967295
131 %call = call i64 @atoll(ptr @.str.5) #3
135 define i64 @strtoll_test() #0 {
136 ; CHECK-LABEL: @strtoll_test(
137 ; CHECK-NEXT: ret i64 4994967295
140 %call = call i64 @strtoll(ptr @.str.7, ptr null, i32 10) #5