|
| 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.noargs = constant [1 x i8] c"\00" |
| 12 | + |
| 13 | +;; No aspects are specified, so no transformation occurs. |
| 14 | +define void @test_basic(i32 %arg) { |
| 15 | +; CHECK-LABEL: @test_basic( |
| 16 | +; CHECK-NEXT: call void (ptr, ...) @basic(ptr nonnull @.str.int, i32 [[ARG:%.*]]) |
| 17 | +; CHECK-NEXT: ret void |
| 18 | +; |
| 19 | + call void (ptr, ...) @basic(ptr @.str.int, i32 %arg) |
| 20 | + ret void |
| 21 | +} |
| 22 | + |
| 23 | +declare void @basic(ptr, ...) #0 |
| 24 | + |
| 25 | +;; The "float" aspect is present and needed, so no transformation occurs. |
| 26 | +define void @test_float_present(double %arg) { |
| 27 | +; CHECK-LABEL: @test_float_present( |
| 28 | +; CHECK-NEXT: call void (ptr, ...) @float_present(ptr nonnull @.str.float, double [[ARG:%.*]]) |
| 29 | +; CHECK-NEXT: ret void |
| 30 | +; |
| 31 | + call void (ptr, ...) @float_present(ptr @.str.float, double %arg) |
| 32 | + ret void |
| 33 | +} |
| 34 | + |
| 35 | +declare void @float_present(ptr, ...) #1 |
| 36 | + |
| 37 | +;; The "float" aspect is present but not needed, so the call is transformed. |
| 38 | +define void @test_float_absent(i32 %arg) { |
| 39 | +; CHECK-LABEL: @test_float_absent( |
| 40 | +; CHECK-NEXT: call void (ptr, ...) @float_present_mod(ptr nonnull @.str.int, i32 [[ARG:%.*]]) |
| 41 | +; CHECK-NEXT: ret void |
| 42 | +; |
| 43 | + call void (ptr, ...) @float_absent(ptr @.str.int, i32 %arg) |
| 44 | + ret void |
| 45 | +} |
| 46 | + |
| 47 | +declare void @float_absent(ptr, ...) #1 |
| 48 | + |
| 49 | +;; Unknown aspects are always considered needed, so no transformation occurs. |
| 50 | +define void @test_unknown_aspects(i32 %arg) { |
| 51 | +; CHECK-LABEL: @test_unknown_aspects( |
| 52 | +; CHECK-NEXT: call void (ptr, ...) @unknown_aspects(ptr nonnull @.str.int, i32 [[ARG:%.*]]) |
| 53 | +; CHECK-NEXT: ret void |
| 54 | +; |
| 55 | + call void (ptr, ...) @unknown_aspects(ptr @.str.int, i32 %arg) |
| 56 | + ret void |
| 57 | +} |
| 58 | + |
| 59 | +declare void @unknown_aspects(ptr, ...) #2 |
| 60 | + |
| 61 | +;; The call has no arguments to check, so the "float" aspect is not needed and |
| 62 | +;; the call is transformed. |
| 63 | +define void @test_no_args_to_check() { |
| 64 | +; CHECK-LABEL: @test_no_args_to_check( |
| 65 | +; CHECK-NEXT: call void (ptr, ...) @float_present_mod(ptr nonnull @.str.noargs) |
| 66 | +; CHECK-NEXT: ret void |
| 67 | +; |
| 68 | + call void (ptr, ...) @no_args_to_check(ptr @.str.noargs) |
| 69 | + ret void |
| 70 | +} |
| 71 | + |
| 72 | +declare void @no_args_to_check(ptr, ...) #1 |
| 73 | + |
| 74 | +;; The first argument index is not 2. The "float" aspect is needed, so no |
| 75 | +;; transformation occurs. |
| 76 | +define void @test_first_arg_idx(i32 %ignored, double %arg) { |
| 77 | +; CHECK-LABEL: @test_first_arg_idx( |
| 78 | +; CHECK-NEXT: call void (i32, ptr, ...) @first_arg_idx(i32 [[IGNORED:%.*]], ptr nonnull @.str.float, double [[ARG:%.*]]) |
| 79 | +; CHECK-NEXT: ret void |
| 80 | +; |
| 81 | + call void (i32, ptr, ...) @first_arg_idx(i32 %ignored, ptr @.str.float, double %arg) |
| 82 | + ret void |
| 83 | +} |
| 84 | + |
| 85 | +declare void @first_arg_idx(i32, ptr, ...) #3 |
| 86 | + |
| 87 | +;; One aspect ("unknown") is needed, but one ("float") is not. The call is |
| 88 | +;; transformed, and a reference to the needed aspect is emitted. |
| 89 | +define void @test_partial_aspects(i32 %arg) { |
| 90 | +; CHECK-LABEL: @test_partial_aspects( |
| 91 | +; CHECK-NEXT: call void (ptr, ...) @multiple_aspects_mod(ptr nonnull @.str.int, i32 [[ARG:%.*]]) |
| 92 | +; CHECK-NEXT: call void @llvm.reloc.none(metadata !"basic_impl_unknown") |
| 93 | +; CHECK-NEXT: ret void |
| 94 | +; |
| 95 | + call void (ptr, ...) @partial_aspects(ptr @.str.int, i32 %arg) |
| 96 | + ret void |
| 97 | +} |
| 98 | + |
| 99 | +declare void @partial_aspects(ptr, ...) #4 |
| 100 | + |
| 101 | +attributes #0 = { "modular-format"="printf,1,2,basic_mod,basic_impl" } |
| 102 | +attributes #1 = { "modular-format"="printf,1,2,float_present_mod,basic_impl,float" } |
| 103 | +attributes #2 = { "modular-format"="printf,1,2,unknown_aspects_mod,basic_impl,unknown1,unknown2" } |
| 104 | +attributes #3 = { "modular-format"="printf,2,3,first_arg_idx_mod,basic_impl,float" } |
| 105 | +attributes #4 = { "modular-format"="printf,1,2,multiple_aspects_mod,basic_impl,float,unknown" } |
0 commit comments