|
| 1 | +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py |
| 2 | +; Test that the modular format string library call simplifier works correctly. |
| 3 | +; |
| 4 | +; RUN: opt < %s -passes=instcombine -S | FileCheck %s |
| 5 | + |
| 6 | +target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128" |
| 7 | + |
| 8 | +@.str.int = constant [3 x i8] c"%d\00" |
| 9 | +@.str.float = constant [3 x i8] c"%f\00" |
| 10 | +@.str.multi = constant [6 x i8] c"%f %d\00" |
| 11 | +@.str.multifp = constant [6 x i8] c"%f %f\00" |
| 12 | +@.str.noargs = constant [1 x i8] c"\00" |
| 13 | + |
| 14 | +; Basic Transformation |
| 15 | +define void @test_basic(i32 %arg) { |
| 16 | +; CHECK-LABEL: @test_basic( |
| 17 | +; CHECK-NEXT: call void (ptr, ...) @basic_mod(ptr nonnull @.str.int, i32 [[ARG:%.*]]) |
| 18 | +; CHECK-NEXT: ret void |
| 19 | +; |
| 20 | + call void (ptr, ...) @basic(ptr @.str.int, i32 %arg) |
| 21 | + ret void |
| 22 | +} |
| 23 | + |
| 24 | +declare void @basic(ptr, ...) "modular-format"="printf,1,2,basic_mod,basic_impl" |
| 25 | +; "float" Aspect - Present |
| 26 | +define void @test_float_present(double %arg) { |
| 27 | +; CHECK-LABEL: @test_float_present( |
| 28 | +; CHECK-NEXT: call void (ptr, ...) @float_present_mod(ptr nonnull @.str.float, double [[ARG:%.*]]) |
| 29 | +; CHECK-NEXT: call void @llvm.reloc.none(ptr nonnull @basic_impl_float) |
| 30 | +; CHECK-NEXT: ret void |
| 31 | +; |
| 32 | + call void (ptr, ...) @float_present(ptr @.str.float, double %arg) |
| 33 | + ret void |
| 34 | +} |
| 35 | + |
| 36 | +declare void @float_present(ptr, ...) #0 |
| 37 | + |
| 38 | +; Unknown Aspects |
| 39 | +define void @test_unknown_aspects(i32 %arg) { |
| 40 | +; CHECK-LABEL: @test_unknown_aspects( |
| 41 | +; CHECK-NEXT: call void (ptr, ...) @unknown_aspects_mod(ptr nonnull @.str.int, i32 [[ARG:%.*]]) |
| 42 | +; CHECK-NEXT: call void @llvm.reloc.none(ptr nonnull @basic_impl_unknown1) |
| 43 | +; CHECK-NEXT: call void @llvm.reloc.none(ptr nonnull @basic_impl_unknown2) |
| 44 | +; CHECK-NEXT: ret void |
| 45 | +; |
| 46 | + call void (ptr, ...) @unknown_aspects(ptr @.str.int, i32 %arg) |
| 47 | + ret void |
| 48 | +} |
| 49 | + |
| 50 | +declare void @unknown_aspects(ptr, ...) "modular-format"="printf,1,2,unknown_aspects_mod,basic_impl,unknown1,unknown2" |
| 51 | + |
| 52 | +; Multiple Aspects |
| 53 | +define void @test_multiple_aspects(double %arg1, i32 %arg2) { |
| 54 | +; CHECK-LABEL: @test_multiple_aspects( |
| 55 | +; CHECK-NEXT: call void (ptr, ...) @multiple_aspects_mod(ptr nonnull @.str.multi, double [[ARG1:%.*]], i32 [[ARG2:%.*]]) |
| 56 | +; CHECK-NEXT: call void @llvm.reloc.none(ptr nonnull @basic_impl_float) |
| 57 | +; CHECK-NEXT: call void @llvm.reloc.none(ptr nonnull @basic_impl_unknown) |
| 58 | +; CHECK-NEXT: ret void |
| 59 | +; |
| 60 | + call void (ptr, ...) @multiple_aspects(ptr @.str.multi, double %arg1, i32 %arg2) |
| 61 | + ret void |
| 62 | +} |
| 63 | + |
| 64 | +declare void @multiple_aspects(ptr, ...) "modular-format"="printf,1,2,multiple_aspects_mod,basic_impl,float,unknown" |
| 65 | + |
| 66 | +; Multiple Floating-Point Arguments |
| 67 | +define void @test_multiple_fp_args(double %arg1, float %arg2) { |
| 68 | +; CHECK-LABEL: @test_multiple_fp_args( |
| 69 | +; CHECK-NEXT: call void (ptr, ...) @float_present_mod(ptr nonnull @.str.multifp, double [[ARG1:%.*]], float [[ARG2:%.*]]) |
| 70 | +; CHECK-NEXT: call void @llvm.reloc.none(ptr nonnull @basic_impl_float) |
| 71 | +; CHECK-NEXT: ret void |
| 72 | +; |
| 73 | + call void (ptr, ...) @multiple_fp_args(ptr @.str.multifp, double %arg1, float %arg2) |
| 74 | + ret void |
| 75 | +} |
| 76 | + |
| 77 | +declare void @multiple_fp_args(ptr, ...) #0 |
| 78 | + |
| 79 | +; No Arguments to Check |
| 80 | +define void @test_no_args_to_check() { |
| 81 | +; CHECK-LABEL: @test_no_args_to_check( |
| 82 | +; CHECK-NEXT: call void (ptr, ...) @float_present_mod(ptr nonnull @.str.noargs) |
| 83 | +; CHECK-NEXT: ret void |
| 84 | +; |
| 85 | + call void (ptr, ...) @no_args_to_check(ptr @.str.noargs) |
| 86 | + ret void |
| 87 | +} |
| 88 | + |
| 89 | +declare void @no_args_to_check(ptr, ...) #0 |
| 90 | + |
| 91 | +; First argument index != 2 |
| 92 | +define void @test_first_arg_idx(i32 %ignored, double %arg) { |
| 93 | +; CHECK-LABEL: @test_first_arg_idx( |
| 94 | +; CHECK-NEXT: call void (i32, ptr, ...) @first_arg_idx_mod(i32 [[IGNORED:%.*]], ptr nonnull @.str.float, double [[ARG:%.*]]) |
| 95 | +; CHECK-NEXT: call void @llvm.reloc.none(ptr nonnull @basic_impl_float) |
| 96 | +; CHECK-NEXT: ret void |
| 97 | +; |
| 98 | + call void (i32, ptr, ...) @first_arg_idx(i32 %ignored, ptr @.str.float, double %arg) |
| 99 | + ret void |
| 100 | +} |
| 101 | + |
| 102 | +declare void @first_arg_idx(i32, ptr, ...) "modular-format"="printf,2,3,first_arg_idx_mod,basic_impl,float" |
| 103 | + |
| 104 | +attributes #0 = { "modular-format"="printf,1,2,float_present_mod,basic_impl,float" } |
0 commit comments