xref: /llvm-project/llvm/test/CodeGen/AMDGPU/printf_builtin.ll (revision 8a206124675aae7e5afc9577f651f8e88468ce43)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
2; RUN: opt -mtriple=amdgcn-- -passes=amdgpu-printf-runtime-binding -mcpu=gfx90a -S < %s | FileCheck --check-prefix=GCN %s
3
4@str = private unnamed_addr constant [10 x i8] c"string %d\00", align 1
5
6define void @caller(i32 %n) {
7; GCN-LABEL: define void @caller
8; GCN-SAME: (i32 [[N:%.*]]) #[[ATTR0:[0-9]+]] {
9; GCN-NEXT:  entry:
10; GCN-NEXT:    [[CALL:%.*]] = call i32 (ptr, ...) @printf(ptr @str, i32 [[N]])
11; GCN-NEXT:    ret void
12;
13entry:
14  %call = call i32 (ptr, ...) @printf(ptr @str, i32 %n)
15  ret void
16}
17
18define void @caller_builtin(i32 %n) {
19; GCN-LABEL: define void @caller_builtin
20; GCN-SAME: (i32 [[N:%.*]]) #[[ATTR0]] {
21; GCN-NEXT:  entry:
22; GCN-NEXT:    [[PRINTF_ALLOC_FN:%.*]] = call ptr addrspace(1) @__printf_alloc(i32 8)
23; GCN-NEXT:    br label [[ENTRY_SPLIT:%.*]]
24; GCN:       entry.split:
25; GCN-NEXT:    [[TMP0:%.*]] = icmp ne ptr addrspace(1) [[PRINTF_ALLOC_FN]], null
26; GCN-NEXT:    br i1 [[TMP0]], label [[TMP1:%.*]], label [[TMP2:%.*]]
27; GCN:       1:
28; GCN-NEXT:    [[PRINTBUFFID:%.*]] = getelementptr i8, ptr addrspace(1) [[PRINTF_ALLOC_FN]], i32 0
29; GCN-NEXT:    [[PRINTBUFFIDCAST:%.*]] = bitcast ptr addrspace(1) [[PRINTBUFFID]] to ptr addrspace(1)
30; GCN-NEXT:    store i32 1, ptr addrspace(1) [[PRINTBUFFIDCAST]], align 4
31; GCN-NEXT:    [[PRINTBUFFGEP:%.*]] = getelementptr i8, ptr addrspace(1) [[PRINTF_ALLOC_FN]], i32 4
32; GCN-NEXT:    store i32 [[N]], ptr addrspace(1) [[PRINTBUFFGEP]], align 4
33; GCN-NEXT:    br label [[TMP2]]
34; GCN:       2:
35; GCN-NEXT:    ret void
36;
37entry:
38  %call = call i32 (ptr, ...) @printf(ptr @str, i32 %n) #0
39  ret void
40}
41
42declare i32 @printf(ptr, ...) #1
43
44attributes #0 = { builtin }
45attributes #1 = { nobuiltin }
46