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 i32 @strtol(ptr, ptr, i32)
14 declare i32 @atoi(ptr)
15 declare i32 @atol(ptr)
16 declare i64 @atoll(ptr)
17 declare i64 @strtoll(ptr, ptr, i32)
19 define i32 @strtol_dec() #0 {
20 ; CHECK-LABEL: @strtol_dec(
21 ; CHECK-NEXT: ret i32 12
23 %call = call i32 @strtol(ptr @.str, ptr null, i32 10) #2
27 define i32 @strtol_base_zero() #0 {
28 ; CHECK-LABEL: @strtol_base_zero(
29 ; CHECK-NEXT: ret i32 12
31 %call = call i32 @strtol(ptr @.str, ptr null, i32 0) #2
35 define i32 @strtol_hex() #0 {
36 ; CHECK-LABEL: @strtol_hex(
37 ; CHECK-NEXT: ret i32 18
39 %call = call i32 @strtol(ptr @.str, ptr null, i32 16) #2
43 ; Fold a call to strtol with an endptr known to be nonnull (the result
44 ; of pointer increment).
46 define i32 @strtol_endptr_not_null(ptr %pend) {
47 ; CHECK-LABEL: @strtol_endptr_not_null(
48 ; CHECK-NEXT: [[ENDP1:%.*]] = getelementptr inbounds ptr, ptr [[PEND:%.*]], i64 1
49 ; CHECK-NEXT: store ptr getelementptr inbounds ([3 x i8], ptr @.str, i64 0, i64 2), ptr [[ENDP1]], align 8
50 ; CHECK-NEXT: ret i32 12
52 %endp1 = getelementptr inbounds ptr, ptr %pend, i32 1
53 %call = call i32 @strtol(ptr @.str, ptr %endp1, i32 10)
57 ; Don't fold a call to strtol with an endptr that's not known to be nonnull.
59 define i32 @strtol_endptr_maybe_null(ptr %end) {
60 ; CHECK-LABEL: @strtol_endptr_maybe_null(
61 ; CHECK-NEXT: [[CALL:%.*]] = call i32 @strtol(ptr nonnull @.str.1, ptr [[END:%.*]], i32 10)
62 ; CHECK-NEXT: ret i32 [[CALL]]
64 %call = call i32 @strtol(ptr @.str.1, ptr %end, i32 10)
68 define i32 @atoi_test() #0 {
69 ; CHECK-LABEL: @atoi_test(
70 ; CHECK-NEXT: ret i32 12
72 %call = call i32 @atoi(ptr @.str) #4
76 define i32 @strtol_not_const_str(ptr %s) #0 {
77 ; CHECK-LABEL: @strtol_not_const_str(
78 ; CHECK-NEXT: [[CALL:%.*]] = call i32 @strtol(ptr nocapture [[S:%.*]], ptr null, i32 10)
79 ; CHECK-NEXT: ret i32 [[CALL]]
81 %call = call i32 @strtol(ptr %s, ptr null, i32 10) #3
85 define i32 @atoi_not_const_str(ptr %s) #0 {
86 ; CHECK-LABEL: @atoi_not_const_str(
87 ; CHECK-NEXT: [[CALL:%.*]] = call i32 @atoi(ptr nocapture [[S:%.*]])
88 ; CHECK-NEXT: ret i32 [[CALL]]
90 %call = call i32 @atoi(ptr %s) #4
94 define i32 @strtol_not_const_base(i32 %b) #0 {
95 ; CHECK-LABEL: @strtol_not_const_base(
96 ; CHECK-NEXT: [[CALL:%.*]] = call i32 @strtol(ptr nocapture nonnull @.str, ptr null, i32 [[B:%.*]])
97 ; CHECK-NEXT: ret i32 [[CALL]]
99 %call = call i32 @strtol(ptr @.str, ptr null, i32 %b) #2
103 define i32 @strtol_long_int() #0 {
104 ; CHECK-LABEL: @strtol_long_int(
105 ; CHECK-NEXT: [[CALL:%.*]] = call i32 @strtol(ptr nocapture nonnull @.str.2, ptr null, i32 10)
106 ; CHECK-NEXT: ret i32 [[CALL]]
108 %call = call i32 @strtol(ptr @.str.2, ptr null, i32 10) #3
113 define i32 @strtol_big_overflow() #0 {
114 ; CHECK-LABEL: @strtol_big_overflow(
115 ; CHECK-NEXT: [[CALL:%.*]] = call i32 @strtol(ptr nocapture nonnull @.str.3, ptr null, i32 10)
116 ; CHECK-NEXT: ret i32 [[CALL]]
118 %call = call i32 @strtol(ptr nocapture @.str.3, ptr null, i32 10) #2
122 define i32 @atol_test() #0 {
123 ; CHECK-LABEL: @atol_test(
124 ; CHECK-NEXT: ret i32 499496729
127 %call = call i32 @atol(ptr @.str.6) #4
131 define i64 @atoll_test() #0 {
132 ; CHECK-LABEL: @atoll_test(
133 ; CHECK-NEXT: ret i64 4994967295
135 %call = call i64 @atoll(ptr @.str.5) #3
139 define i64 @strtoll_test() #0 {
140 ; CHECK-LABEL: @strtoll_test(
141 ; CHECK-NEXT: ret i64 4994967295
144 %call = call i64 @strtoll(ptr @.str.7, ptr null, i32 10) #5