| 1 |
; RUN: llvm-as < %s -o %t.bc |
| 2 |
; RUN: llvm-spirv %t.bc -o %t.spv |
| 3 |
; RUN: llvm-spirv -r -emit-opaque-pointers %t.spv |
| 4 |
|
| 5 |
; This is a regression test for reported issue https://github.com/KhronosGroup/SPIRV-LLVM-Translator/issues/524. |
| 6 |
; Test checks that reverse translation will not fail with assertion. |
| 7 |
|
| 8 |
; Build from the following source with clang -c -emit-llvm -O0 -target spir64 -gline-tables-only |
| 9 |
; float bar(int x); |
| 10 |
|
| 11 |
; __kernel void foo(__global float* outPtr, int i) { |
| 12 |
; #pragma clang loop unroll(enable) |
| 13 |
; for (int j = 0; j < i; ++j) { |
| 14 |
; outPtr[j] = bar(j); |
| 15 |
; } |
| 16 |
; } |
| 17 |
|
| 18 |
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024" |
| 19 |
target triple = "spir64" |
| 20 |
|
| 21 |
; Function Attrs: convergent noinline norecurse nounwind optnone |
| 22 |
define dso_local spir_kernel void @foo(float addrspace(1)* %outPtr, i32 %i) #0 !dbg !9 !kernel_arg_addr_space !6 !kernel_arg_access_qual !11 !kernel_arg_type !12 !kernel_arg_base_type !12 !kernel_arg_type_qual !13 { |
| 23 |
entry: |
| 24 |
%outPtr.addr = alloca float addrspace(1)*, align 8 |
| 25 |
%i.addr = alloca i32, align 4 |
| 26 |
%j = alloca i32, align 4 |
| 27 |
store float addrspace(1)* %outPtr, float addrspace(1)** %outPtr.addr, align 8 |
| 28 |
store i32 %i, i32* %i.addr, align 4 |
| 29 |
store i32 0, i32* %j, align 4, !dbg !14 |
| 30 |
br label %for.cond, !dbg !15 |
| 31 |
|
| 32 |
for.cond: ; preds = %for.inc, %entry |
| 33 |
%0 = load i32, i32* %j, align 4, !dbg !16 |
| 34 |
%1 = load i32, i32* %i.addr, align 4, !dbg !17 |
| 35 |
%cmp = icmp slt i32 %0, %1, !dbg !18 |
| 36 |
br i1 %cmp, label %for.body, label %for.end, !dbg !19 |
| 37 |
|
| 38 |
for.body: ; preds = %for.cond |
| 39 |
%2 = load i32, i32* %j, align 4, !dbg !20 |
| 40 |
%call = call spir_func float @bar(i32 %2) #2, !dbg !21 |
| 41 |
%3 = load float addrspace(1)*, float addrspace(1)** %outPtr.addr, align 8, !dbg !22 |
| 42 |
%4 = load i32, i32* %j, align 4, !dbg !23 |
| 43 |
%idxprom = sext i32 %4 to i64, !dbg !22 |
| 44 |
%arrayidx = getelementptr inbounds float, float addrspace(1)* %3, i64 %idxprom, !dbg !22 |
| 45 |
store float %call, float addrspace(1)* %arrayidx, align 4, !dbg !24 |
| 46 |
br label %for.inc, !dbg !25 |
| 47 |
|
| 48 |
for.inc: ; preds = %for.body |
| 49 |
%5 = load i32, i32* %j, align 4, !dbg !26 |
| 50 |
%inc = add nsw i32 %5, 1, !dbg !26 |
| 51 |
store i32 %inc, i32* %j, align 4, !dbg !26 |
| 52 |
br label %for.cond, !dbg !19, !llvm.loop !27 |
| 53 |
|
| 54 |
for.end: ; preds = %for.cond |
| 55 |
ret void, !dbg !29 |
| 56 |
} |
| 57 |
|
| 58 |
; Function Attrs: convergent |
| 59 |
declare dso_local spir_func float @bar(i32) #1 |
| 60 |
|
| 61 |
attributes #0 = { convergent noinline norecurse nounwind optnone "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "uniform-work-group-size"="true" "unsafe-fp-math"="false" "use-soft-float"="false" } |
| 62 |
attributes #1 = { convergent "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } |
| 63 |
attributes #2 = { convergent } |
| 64 |
|
| 65 |
!llvm.dbg.cu = !{!0} |
| 66 |
!llvm.module.flags = !{!3, !4, !5} |
| 67 |
!opencl.ocl.version = !{!6} |
| 68 |
!opencl.spir.version = !{!7} |
| 69 |
!llvm.ident = !{!8} |
| 70 |
|
| 71 |
!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 11.0.0 (https://github.com/llvm/llvm-project.git 6671a81bc71cc2635c5a10d6f688fea46ca4e5d6)", isOptimized: false, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !2, splitDebugInlining: false, nameTableKind: None) |
| 72 |
!1 = !DIFile(filename: "loop.cl", directory: "/export/users/work/khr_spirv/llvm/build/bin") |
| 73 |
!2 = !{} |
| 74 |
!3 = !{i32 7, !"Dwarf Version", i32 4} |
| 75 |
!4 = !{i32 2, !"Debug Info Version", i32 3} |
| 76 |
!5 = !{i32 1, !"wchar_size", i32 4} |
| 77 |
!6 = !{i32 1, i32 0} |
| 78 |
!7 = !{i32 1, i32 2} |
| 79 |
!8 = !{!"clang version 11.0.0"} |
| 80 |
!9 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 3, type: !10, scopeLine: 3, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2) |
| 81 |
!10 = !DISubroutineType(types: !2) |
| 82 |
!11 = !{!"none", !"none"} |
| 83 |
!12 = !{!"float*", !"int"} |
| 84 |
!13 = !{!"", !""} |
| 85 |
!14 = !DILocation(line: 5, column: 12, scope: !9) |
| 86 |
!15 = !DILocation(line: 5, column: 8, scope: !9) |
| 87 |
!16 = !DILocation(line: 5, column: 19, scope: !9) |
| 88 |
!17 = !DILocation(line: 5, column: 23, scope: !9) |
| 89 |
!18 = !DILocation(line: 5, column: 21, scope: !9) |
| 90 |
!19 = !DILocation(line: 5, column: 3, scope: !9) |
| 91 |
!20 = !DILocation(line: 6, column: 21, scope: !9) |
| 92 |
!21 = !DILocation(line: 6, column: 17, scope: !9) |
| 93 |
!22 = !DILocation(line: 6, column: 5, scope: !9) |
| 94 |
!23 = !DILocation(line: 6, column: 12, scope: !9) |
| 95 |
!24 = !DILocation(line: 6, column: 15, scope: !9) |
| 96 |
!25 = !DILocation(line: 7, column: 3, scope: !9) |
| 97 |
!26 = !DILocation(line: 5, column: 26, scope: !9) |
| 98 |
!27 = distinct !{!27, !19, !25, !28} |
| 99 |
!28 = !{!"llvm.loop.unroll.enable"} |
| 100 |
!29 = !DILocation(line: 8, column: 1, scope: !9) |