| 1 |
; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s |
| 2 |
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %} |
| 3 |
|
| 4 |
;; Support of doubles is required. |
| 5 |
; CHECK: OpCapability Float64 |
| 6 |
; CHECK: "fun01" |
| 7 |
define spir_kernel void @fun01(ptr addrspace(1) noalias %a, ptr addrspace(1) %b, i32 %c) { |
| 8 |
entry: |
| 9 |
%a.addr = alloca ptr addrspace(1), align 8 |
| 10 |
%b.addr = alloca ptr addrspace(1), align 8 |
| 11 |
%c.addr = alloca i32, align 4 |
| 12 |
store ptr addrspace(1) %a, ptr %a.addr, align 8 |
| 13 |
store ptr addrspace(1) %b, ptr %b.addr, align 8 |
| 14 |
store i32 %c, ptr %c.addr, align 4 |
| 15 |
%0 = load ptr addrspace(1), ptr %b.addr, align 8 |
| 16 |
%arrayidx = getelementptr inbounds i32, ptr addrspace(1) %0, i64 0 |
| 17 |
%1 = load i32, ptr addrspace(1) %arrayidx, align 4 |
| 18 |
%2 = load ptr addrspace(1), ptr %a.addr, align 8 |
| 19 |
%arrayidx1 = getelementptr inbounds i32, ptr addrspace(1) %2, i64 0 |
| 20 |
store i32 %1, ptr addrspace(1) %arrayidx1, align 4 |
| 21 |
%3 = load ptr addrspace(1), ptr %b.addr, align 8 |
| 22 |
%cmp = icmp ugt ptr addrspace(1) %3, null |
| 23 |
br i1 %cmp, label %if.then, label %if.end |
| 24 |
|
| 25 |
if.then: ; preds = %entry |
| 26 |
%4 = load ptr addrspace(1), ptr %a.addr, align 8 |
| 27 |
%arrayidx2 = getelementptr inbounds i32, ptr addrspace(1) %4, i64 0 |
| 28 |
store i32 2, ptr addrspace(1) %arrayidx2, align 4 |
| 29 |
br label %if.end |
| 30 |
|
| 31 |
if.end: ; preds = %if.then, %entry |
| 32 |
ret void |
| 33 |
} |
| 34 |
|
| 35 |
; CHECK: "fun02" |
| 36 |
define spir_kernel void @fun02(ptr addrspace(1) %a, ptr addrspace(1) %b, i32 %c) { |
| 37 |
entry: |
| 38 |
%a.addr = alloca ptr addrspace(1), align 8 |
| 39 |
%b.addr = alloca ptr addrspace(1), align 8 |
| 40 |
%c.addr = alloca i32, align 4 |
| 41 |
store ptr addrspace(1) %a, ptr %a.addr, align 8 |
| 42 |
store ptr addrspace(1) %b, ptr %b.addr, align 8 |
| 43 |
store i32 %c, ptr %c.addr, align 4 |
| 44 |
%0 = load i32, ptr %c.addr, align 4 |
| 45 |
%idxprom = sext i32 %0 to i64 |
| 46 |
%1 = load ptr addrspace(1), ptr %b.addr, align 8 |
| 47 |
%arrayidx = getelementptr inbounds double, ptr addrspace(1) %1, i64 %idxprom |
| 48 |
%2 = load double, ptr addrspace(1) %arrayidx, align 8 |
| 49 |
%3 = load i32, ptr %c.addr, align 4 |
| 50 |
%idxprom1 = sext i32 %3 to i64 |
| 51 |
%4 = load ptr addrspace(1), ptr %a.addr, align 8 |
| 52 |
%arrayidx2 = getelementptr inbounds double, ptr addrspace(1) %4, i64 %idxprom1 |
| 53 |
store double %2, ptr addrspace(1) %arrayidx2, align 8 |
| 54 |
ret void |
| 55 |
} |
| 56 |
|
| 57 |
; CHECK: "test_builtin" |
| 58 |
define spir_func void @test_builtin(ptr addrspace(1) %in, ptr addrspace(1) %out) { |
| 59 |
entry: |
| 60 |
%in.addr = alloca ptr addrspace(1), align 8 |
| 61 |
%out.addr = alloca ptr addrspace(1), align 8 |
| 62 |
%n = alloca i32, align 4 |
| 63 |
store ptr addrspace(1) %in, ptr %in.addr, align 8 |
| 64 |
store ptr addrspace(1) %out, ptr %out.addr, align 8 |
| 65 |
%call = call spir_func i64 @_Z13get_global_idj(i32 0) |
| 66 |
%conv = trunc i64 %call to i32 |
| 67 |
store i32 %conv, ptr %n, align 4 |
| 68 |
%0 = load i32, ptr %n, align 4 |
| 69 |
%idxprom = sext i32 %0 to i64 |
| 70 |
%1 = load ptr addrspace(1), ptr %in.addr, align 8 |
| 71 |
%arrayidx = getelementptr inbounds i32, ptr addrspace(1) %1, i64 %idxprom |
| 72 |
%2 = load i32, ptr addrspace(1) %arrayidx, align 4 |
| 73 |
%call1 = call spir_func i32 @_Z3absi(i32 %2) |
| 74 |
%3 = load i32, ptr %n, align 4 |
| 75 |
%idxprom2 = sext i32 %3 to i64 |
| 76 |
%4 = load ptr addrspace(1), ptr %out.addr, align 8 |
| 77 |
%arrayidx3 = getelementptr inbounds i32, ptr addrspace(1) %4, i64 %idxprom2 |
| 78 |
store i32 %call1, ptr addrspace(1) %arrayidx3, align 4 |
| 79 |
ret void |
| 80 |
} |
| 81 |
|
| 82 |
; CHECK-NOT: "_Z13get_global_idj" |
| 83 |
declare spir_func i64 @_Z13get_global_idj(i32) |
| 84 |
|
| 85 |
; CHECK-NOT: "_Z3absi" |
| 86 |
declare spir_func i32 @_Z3absi(i32) |
| 87 |
|
| 88 |
; CHECK: "myabs" |
| 89 |
define spir_func i32 @myabs(i32 %x) { |
| 90 |
entry: |
| 91 |
%x.addr = alloca i32, align 4 |
| 92 |
store i32 %x, ptr %x.addr, align 4 |
| 93 |
%0 = load i32, ptr %x.addr, align 4 |
| 94 |
%call = call spir_func i32 @_Z3absi(i32 %0) |
| 95 |
ret i32 %call |
| 96 |
} |
| 97 |
|
| 98 |
; CHECK: "test_function_call" |
| 99 |
define spir_func void @test_function_call(ptr addrspace(1) %in, ptr addrspace(1) %out) { |
| 100 |
entry: |
| 101 |
%in.addr = alloca ptr addrspace(1), align 8 |
| 102 |
%out.addr = alloca ptr addrspace(1), align 8 |
| 103 |
%n = alloca i32, align 4 |
| 104 |
store ptr addrspace(1) %in, ptr %in.addr, align 8 |
| 105 |
store ptr addrspace(1) %out, ptr %out.addr, align 8 |
| 106 |
%call = call spir_func i64 @_Z13get_global_idj(i32 0) |
| 107 |
%conv = trunc i64 %call to i32 |
| 108 |
store i32 %conv, ptr %n, align 4 |
| 109 |
%0 = load i32, ptr %n, align 4 |
| 110 |
%idxprom = sext i32 %0 to i64 |
| 111 |
%1 = load ptr addrspace(1), ptr %in.addr, align 8 |
| 112 |
%arrayidx = getelementptr inbounds i32, ptr addrspace(1) %1, i64 %idxprom |
| 113 |
%2 = load i32, ptr addrspace(1) %arrayidx, align 4 |
| 114 |
%call1 = call spir_func i32 @myabs(i32 %2) |
| 115 |
%3 = load i32, ptr %n, align 4 |
| 116 |
%idxprom2 = sext i32 %3 to i64 |
| 117 |
%4 = load ptr addrspace(1), ptr %out.addr, align 8 |
| 118 |
%arrayidx3 = getelementptr inbounds i32, ptr addrspace(1) %4, i64 %idxprom2 |
| 119 |
store i32 %call1, ptr addrspace(1) %arrayidx3, align 4 |
| 120 |
ret void |
| 121 |
} |