| 1 |
; This test shows how value attributes are being passed during different translation steps. |
| 2 |
; See also test/CodeGen/SPIRV/optimizations/add-check-overflow.ll. |
| 3 |
|
| 4 |
; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -print-after=prepare-functions 2>&1 | FileCheck %s --check-prefix=CHECK-PREPARE |
| 5 |
; Intrinsics with aggregate return type are not substituted/removed. |
| 6 |
; CHECK-PREPARE: @llvm.uadd.with.overflow.i32 |
| 7 |
|
| 8 |
; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -print-after=emit-intrinsics 2>&1 | FileCheck %s --check-prefix=CHECK-IR |
| 9 |
; Aggregate data are wrapped into @llvm.fake.use(), |
| 10 |
; and their attributes are packed into a metadata for @llvm.spv.value.md(). |
| 11 |
; CHECK-IR: %[[R1:.*]] = call { i32, i1 } @llvm.uadd.with.overflow.i32 |
| 12 |
; CHECK-IR: call void @llvm.spv.value.md(metadata ![[#MD1:]]) |
| 13 |
; CHECK-IR: call void (...) @llvm.fake.use({ i32, i1 } %[[R1]]) |
| 14 |
; CHECK-IR: %math = extractvalue { i32, i1 } %[[R1]], 0 |
| 15 |
; CHECK-IR: %ov = extractvalue { i32, i1 } %[[R1]], 1 |
| 16 |
; Type/Name attributes of the value. |
| 17 |
; CHECK-IR: ![[#MD1]] = !{{[{]}}![[#MD2:]], !""{{[}]}} |
| 18 |
; Origin data type of the value. |
| 19 |
; CHECK-IR: ![[#MD2]] = !{{[{]}}{{[{]}} i32, i1 {{[}]}} poison{{[}]}} |
| 20 |
|
| 21 |
; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -print-after=irtranslator 2>&1 | FileCheck %s --check-prefix=CHECK-GMIR |
| 22 |
; Required info succeeded to get through IRTranslator. |
| 23 |
; CHECK-GMIR: %[[phires:.*]]:_(s32) = G_PHI |
| 24 |
; CHECK-GMIR: %[[math:.*]]:id(s32), %[[ov:.*]]:_(s1) = G_UADDO %[[phires]]:_, %[[#]]:_ |
| 25 |
; CHECK-GMIR: G_INTRINSIC_W_SIDE_EFFECTS intrinsic(@llvm.spv.value.md), ![[MD1:]] |
| 26 |
; CHECK-GMIR: FAKE_USE %[[math]]:id(s32), %[[ov]]:_(s1) |
| 27 |
|
| 28 |
; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -print-after=spirv-prelegalizer 2>&1 | FileCheck %s --check-prefix=CHECK-PRE |
| 29 |
; Internal service instructions are consumed. |
| 30 |
; CHECK-PRE: G_UADDO |
| 31 |
; CHECK-PRE-NO: llvm.spv.value.md |
| 32 |
; CHECK-PRE-NO: FAKE_USE |
| 33 |
|
| 34 |
; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -print-after=instruction-select 2>&1 | FileCheck %s --check-prefix=CHECK-ISEL |
| 35 |
; Names and types are restored and correctly encoded. Correct instruction selection is completed. |
| 36 |
; CHECK-ISEL-DAG: %[[int32:.*]]:type = OpTypeInt 32, 0 |
| 37 |
; CHECK-ISEL-DAG: %[[struct:.*]]:type = OpTypeStruct %[[int32]]:type, %[[int32]]:type |
| 38 |
; CHECK-ISEL-DAG: %[[bool:.*]]:type = OpTypeBool |
| 39 |
; CHECK-ISEL-DAG: %[[zero32:.*]]:iid = OpConstantNull %[[int32]]:type |
| 40 |
; CHECK-ISEL-DAG: %[[res:.*]]:iid = OpIAddCarryS %[[struct]]:type |
| 41 |
; CHECK-ISEL-DAG: %[[math:.*]]:id = OpCompositeExtract %[[int32]]:type, %[[res]]:iid, 0 |
| 42 |
; CHECK-ISEL-DAG: %[[ov32:.*]]:iid = OpCompositeExtract %[[int32]]:type, %[[res]]:iid, 1 |
| 43 |
; CHECK-ISEL-DAG: %[[ov:.*]]:iid = OpINotEqual %[[bool]]:type, %[[ov32]]:iid, %[[zero32:.*]]:iid |
| 44 |
|
| 45 |
define spir_func i32 @foo(i32 %a, ptr addrspace(4) %p) { |
| 46 |
entry: |
| 47 |
br label %l1 |
| 48 |
|
| 49 |
l1: ; preds = %body, %entry |
| 50 |
%e = phi i32 [ %a, %entry ], [ %math, %body ] |
| 51 |
%0 = call { i32, i1 } @llvm.uadd.with.overflow.i32(i32 %e, i32 1) |
| 52 |
%math = extractvalue { i32, i1 } %0, 0 |
| 53 |
%ov = extractvalue { i32, i1 } %0, 1 |
| 54 |
br i1 %ov, label %exit, label %body |
| 55 |
|
| 56 |
body: ; preds = %l1 |
| 57 |
store i8 42, ptr addrspace(4) %p, align 1 |
| 58 |
br label %l1 |
| 59 |
|
| 60 |
exit: ; preds = %l1 |
| 61 |
ret i32 %math |
| 62 |
} |