1 ; RUN: opt < %s -S -nvvm-reflect -nvvm-reflect-list USE_MUL=0 -O2 | FileCheck %s --check-prefix=USE_MUL_0 2 ; RUN: opt < %s -S -nvvm-reflect -nvvm-reflect-list USE_MUL=1 -O2 | FileCheck %s --check-prefix=USE_MUL_1 3 4 @str = private unnamed_addr addrspace(4) constant [8 x i8] c"USE_MUL\00" 5 6 declare i32 @__nvvm_reflect(i8*) 7 declare i8* @llvm.nvvm.ptr.constant.to.gen.p0i8.p4i8(i8 addrspace(4)*) 8 9 define float @foo(float %a, float %b) { 10 ; USE_MUL_0: define float @foo 11 ; USE_MUL_0-NOT: call i32 @__nvvm_reflect 12 ; USE_MUL_1: define float @foo 13 ; USE_MUL_1-NOT: call i32 @__nvvm_reflect 14 %ptr = tail call i8* @llvm.nvvm.ptr.constant.to.gen.p0i8.p4i8(i8 addrspace(4)* getelementptr inbounds ([8 x i8], [8 x i8] addrspace(4)* @str, i32 0, i32 0)) 15 %reflect = tail call i32 @__nvvm_reflect(i8* %ptr) 16 %cmp = icmp ugt i32 %reflect, 0 17 br i1 %cmp, label %use_mul, label %use_add 18 19 use_mul: 20 ; USE_MUL_1: fmul float %a, %b 21 ; USE_MUL_0-NOT: fadd float %a, %b 22 %ret1 = fmul float %a, %b 23 br label %exit 24 25 use_add: 26 ; USE_MUL_0: fadd float %a, %b 27 ; USE_MUL_1-NOT: fmul float %a, %b 28 %ret2 = fadd float %a, %b 29 br label %exit 30 31 exit: 32 %ret = phi float [%ret1, %use_mul], [%ret2, %use_add] 33 ret float %ret 34 } 35 36 declare i32 @llvm.nvvm.reflect.p0i8(i8*) 37 38 ; USE_MUL_0: define i32 @intrinsic 39 ; USE_MUL_1: define i32 @intrinsic 40 define i32 @intrinsic() { 41 ; USE_MUL_0-NOT: call i32 @llvm.nvvm.reflect 42 ; USE_MUL_0: ret i32 0 43 ; USE_MUL_1-NOT: call i32 @llvm.nvvm.reflect 44 ; USE_MUL_1: ret i32 1 45 %ptr = tail call i8* @llvm.nvvm.ptr.constant.to.gen.p0i8.p4i8(i8 addrspace(4)* getelementptr inbounds ([8 x i8], [8 x i8] addrspace(4)* @str, i32 0, i32 0)) 46 %reflect = tail call i32 @llvm.nvvm.reflect.p0i8(i8* %ptr) 47 ret i32 %reflect 48 } 49 50 ; CUDA-7.0 passes __nvvm_reflect argument slightly differently. 51 ; Verify that it works, too 52 53 @"$str" = private addrspace(1) constant [8 x i8] c"USE_MUL\00" 54 55 define float @bar(float %a, float %b) { 56 ; USE_MUL_0: define float @bar 57 ; USE_MUL_0-NOT: call i32 @__nvvm_reflect 58 ; USE_MUL_1: define float @bar 59 ; USE_MUL_1-NOT: call i32 @__nvvm_reflect 60 %reflect = call i32 @__nvvm_reflect(i8* addrspacecast (i8 addrspace(1)* getelementptr inbounds ([8 x i8], [8 x i8] addrspace(1)* @"$str", i32 0, i32 0) to i8*)) 61 %cmp = icmp ne i32 %reflect, 0 62 br i1 %cmp, label %use_mul, label %use_add 63 64 use_mul: 65 ; USE_MUL_1: fmul float %a, %b 66 ; USE_MUL_0-NOT: fadd float %a, %b 67 %ret1 = fmul float %a, %b 68 br label %exit 69 70 use_add: 71 ; USE_MUL_0: fadd float %a, %b 72 ; USE_MUL_1-NOT: fmul float %a, %b 73 %ret2 = fadd float %a, %b 74 br label %exit 75 76 exit: 77 %ret = phi float [%ret1, %use_mul], [%ret2, %use_add] 78 ret float %ret 79 } 80