1 ; We run nvvm-reflect (and then optimize) this module twice, once with metadata
2 ; that enables FTZ, and again with metadata that disables it.
4 ; RUN: cat %s > %t.noftz
5 ; RUN: echo '!0 = !{i32 4, !"nvvm-reflect-ftz", i32 0}' >> %t.noftz
6 ; RUN: opt %t.noftz -S -mtriple=nvptx-nvidia-cuda -passes='default<O2>' \
7 ; RUN: | FileCheck %s --check-prefix=USE_FTZ_0 --check-prefix=CHECK
10 ; RUN: echo '!0 = !{i32 4, !"nvvm-reflect-ftz", i32 1}' >> %t.ftz
11 ; RUN: opt %t.ftz -S -mtriple=nvptx-nvidia-cuda -passes='default<O2>' \
12 ; RUN: | FileCheck %s --check-prefix=USE_FTZ_1 --check-prefix=CHECK
14 @str = private unnamed_addr addrspace(4) constant [11 x i8] c"__CUDA_FTZ\00"
16 declare i32 @__nvvm_reflect(ptr)
17 declare ptr @llvm.nvvm.ptr.constant.to.gen.p0.p4(ptr addrspace(4))
20 define float @foo(float %a, float %b) {
21 ; CHECK-NOT: call i32 @__nvvm_reflect
22 %ptr = tail call ptr @llvm.nvvm.ptr.constant.to.gen.p0.p4(ptr addrspace(4) @str)
23 %reflect = tail call i32 @__nvvm_reflect(ptr %ptr)
24 %cmp = icmp ugt i32 %reflect, 0
25 br i1 %cmp, label %use_mul, label %use_add
28 ; USE_FTZ_1: fmul float %a, %b
29 ; USE_FTZ_0-NOT: fadd float %a, %b
30 %ret1 = fmul float %a, %b
34 ; USE_FTZ_0: fadd float %a, %b
35 ; USE_FTZ_1-NOT: fmul float %a, %b
36 %ret2 = fadd float %a, %b
40 %ret = phi float [%ret1, %use_mul], [%ret2, %use_add]
44 declare i32 @llvm.nvvm.reflect(ptr)
46 ; CHECK-LABEL: define noundef i32 @intrinsic
47 define i32 @intrinsic() {
48 ; CHECK-NOT: call i32 @llvm.nvvm.reflect
49 ; USE_FTZ_0: ret i32 0
50 ; USE_FTZ_1: ret i32 1
51 %ptr = tail call ptr @llvm.nvvm.ptr.constant.to.gen.p0.p4(ptr addrspace(4) @str)
52 %reflect = tail call i32 @llvm.nvvm.reflect(ptr %ptr)
56 ; CUDA-7.0 passes __nvvm_reflect argument slightly differently.
57 ; Verify that it works, too
59 @"$str" = private addrspace(1) constant [11 x i8] c"__CUDA_FTZ\00"
62 define float @bar(float %a, float %b) {
63 ; CHECK-NOT: call i32 @__nvvm_reflect
64 %reflect = call i32 @__nvvm_reflect(ptr addrspacecast (ptr addrspace(1) @"$str" to ptr))
65 %cmp = icmp ne i32 %reflect, 0
66 br i1 %cmp, label %use_mul, label %use_add
69 ; USE_FTZ_1: fmul float %a, %b
70 ; USE_FTZ_0-NOT: fadd float %a, %b
71 %ret1 = fmul float %a, %b
75 ; USE_FTZ_0: fadd float %a, %b
76 ; USE_FTZ_1-NOT: fmul float %a, %b
77 %ret2 = fadd float %a, %b
81 %ret = phi float [%ret1, %use_mul], [%ret2, %use_add]
85 !llvm.module.flags = !{!0}
86 ; A module flag is added to the end of this file by the RUN lines at the top.