David Bolvansky | cb8ca5f3 | 2018-04-25 18:58:53 +0000 | [diff] [blame] | 1 | ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py |
| 2 | ; RUN: opt < %s -instcombine -S | FileCheck %s |
| 3 | |
| 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 |
| 12 | |
| 13 | declare i32 @strtol(i8*, i8**, i32) |
| 14 | declare i32 @atoi(i8*) |
| 15 | declare i32 @atol(i8*) |
| 16 | declare i32 @atoll(i8*) |
| 17 | declare i32 @strtoll(i8*, i8**, i32) |
| 18 | |
| 19 | define i32 @strtol_dec() #0 { |
| 20 | ; CHECK-LABEL: @strtol_dec( |
| 21 | ; CHECK-NEXT: ret i32 12 |
| 22 | ; |
| 23 | %call = call i32 @strtol(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i32 0, i32 0), i8** null, i32 10) #2 |
| 24 | ret i32 %call |
| 25 | } |
| 26 | |
| 27 | define i32 @strtol_base_zero() #0 { |
| 28 | ; CHECK-LABEL: @strtol_base_zero( |
| 29 | ; CHECK-NEXT: ret i32 12 |
| 30 | ; |
| 31 | %call = call i32 @strtol(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i32 0, i32 0), i8** null, i32 0) #2 |
| 32 | ret i32 %call |
| 33 | } |
| 34 | |
| 35 | define i32 @strtol_hex() #0 { |
| 36 | ; CHECK-LABEL: @strtol_hex( |
| 37 | ; CHECK-NEXT: ret i32 18 |
| 38 | ; |
| 39 | %call = call i32 @strtol(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i32 0, i32 0), i8** null, i32 16) #2 |
| 40 | ret i32 %call |
| 41 | } |
| 42 | |
| 43 | define i32 @strtol_endptr_not_null() #0 { |
| 44 | ; CHECK-LABEL: @strtol_endptr_not_null( |
| 45 | ; CHECK-NEXT: [[END:%.*]] = alloca i8*, align 4 |
| 46 | ; CHECK-NEXT: [[CALL:%.*]] = call i32 @strtol(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** nonnull [[END]], i32 10) |
| 47 | ; CHECK-NEXT: ret i32 [[CALL]] |
| 48 | ; |
| 49 | %end = alloca i8*, align 4 |
| 50 | %call = call i32 @strtol(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i32 0, i32 0), i8** %end, i32 10) #2 |
| 51 | ret i32 %call |
| 52 | } |
| 53 | |
| 54 | define i32 @atoi_test() #0 { |
| 55 | ; CHECK-LABEL: @atoi_test( |
| 56 | ; CHECK-NEXT: ret i32 12 |
| 57 | ; |
| 58 | %call = call i32 @atoi(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i32 0, i32 0)) #4 |
| 59 | ret i32 %call |
| 60 | } |
| 61 | |
| 62 | define i32 @strtol_not_const_str(i8* %s) #0 { |
| 63 | ; CHECK-LABEL: @strtol_not_const_str( |
| 64 | ; CHECK-NEXT: [[CALL:%.*]] = call i32 @strtol(i8* nocapture [[S:%.*]], i8** null, i32 10) |
| 65 | ; CHECK-NEXT: ret i32 [[CALL]] |
| 66 | ; |
| 67 | %call = call i32 @strtol(i8* %s, i8** null, i32 10) #3 |
| 68 | ret i32 %call |
| 69 | } |
| 70 | |
| 71 | define i32 @atoi_not_const_str(i8* %s) #0 { |
| 72 | ; CHECK-LABEL: @atoi_not_const_str( |
| 73 | ; CHECK-NEXT: [[CALL:%.*]] = call i32 @atoi(i8* [[S:%.*]]) |
| 74 | ; CHECK-NEXT: ret i32 [[CALL]] |
| 75 | ; |
| 76 | %call = call i32 @atoi(i8* %s) #4 |
| 77 | ret i32 %call |
| 78 | } |
| 79 | |
| 80 | define i32 @strtol_not_const_base(i32 %b) #0 { |
| 81 | ; CHECK-LABEL: @strtol_not_const_base( |
| 82 | ; CHECK-NEXT: [[CALL:%.*]] = call i32 @strtol(i8* nocapture getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** null, i32 [[B:%.*]]) |
| 83 | ; CHECK-NEXT: ret i32 [[CALL]] |
| 84 | ; |
| 85 | %call = call i32 @strtol(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i32 0, i32 0), i8** null, i32 %b) #2 |
| 86 | ret i32 %call |
| 87 | } |
| 88 | |
| 89 | define i32 @strtol_long_int() #0 { |
| 90 | ; CHECK-LABEL: @strtol_long_int( |
| 91 | ; CHECK-NEXT: [[CALL:%.*]] = call i32 @strtol(i8* nocapture getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8** null, i32 10) |
| 92 | ; CHECK-NEXT: ret i32 [[CALL]] |
| 93 | ; |
| 94 | %call = call i32 @strtol(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i32 0, i32 0), i8** null, i32 10) #3 |
| 95 | ret i32 %call |
| 96 | } |
| 97 | |
| 98 | |
| 99 | define i32 @strtol_big_overflow() #0 { |
| 100 | ; CHECK-LABEL: @strtol_big_overflow( |
| 101 | ; CHECK-NEXT: [[CALL:%.*]] = call i32 @strtol(i8* nocapture getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8** null, i32 10) |
| 102 | ; CHECK-NEXT: ret i32 [[CALL]] |
| 103 | ; |
| 104 | %call = call i32 @strtol(i8* nocapture getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i32 0, i32 0), i8** null, i32 10) #2 |
| 105 | ret i32 %call |
| 106 | } |
| 107 | |
| 108 | define i32 @atol_test() #0 { |
| 109 | ; CHECK-LABEL: @atol_test( |
| 110 | ; CHECK-NEXT: ret i32 499496729 |
| 111 | ; |
| 112 | ; CHECK-NEXT |
| 113 | %call = call i32 @atol(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i32 0, i32 0)) #4 |
| 114 | ret i32 %call |
| 115 | } |
| 116 | |
| 117 | define i32 @atoll_test() #0 { |
| 118 | ; CHECK-LABEL: @atoll_test( |
| 119 | ; CHECK-NEXT: [[CALL:%.*]] = call i32 @atoll(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0)) |
| 120 | ; CHECK-NEXT: ret i32 [[CALL]] |
| 121 | ; |
| 122 | %call = call i32 @atoll(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i32 0, i32 0)) #3 |
| 123 | ret i32 %call |
| 124 | } |
| 125 | |
| 126 | define i32 @strtoll_test() #0 { |
| 127 | ; CHECK-LABEL: @strtoll_test( |
| 128 | ; CHECK-NEXT: [[CALL:%.*]] = call i32 @strtoll(i8* nocapture getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i8** null, i32 10) |
| 129 | ; CHECK-NEXT: ret i32 [[CALL]] |
| 130 | ; |
| 131 | ; CHECK-NEXT |
| 132 | %call = call i32 @strtoll(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i32 0, i32 0), i8** null, i32 10) #5 |
| 133 | ret i32 %call |
| 134 | } |