Files
TheRock/compiler/amd-llvm/clang/test/CIR/Lowering/cast.cir
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

107 lines
4.9 KiB
Plaintext

// RUN: cir-opt %s -cir-to-llvm -o %t.cir
// RUN: FileCheck %s --input-file=%t.cir
!s16i = !cir.int<s, 16>
!s32i = !cir.int<s, 32>
!s64i = !cir.int<s, 64>
!s8i = !cir.int<s, 8>
!u32i = !cir.int<u, 32>
!u8i = !cir.int<u, 8>
!u64i = !cir.int<u, 64>
module {
cir.func @cStyleCasts(%arg0: !u32i, %arg1: !s32i, %arg2: !cir.float, %arg3: !cir.double) -> !s32i {
// CHECK: llvm.func @cStyleCasts
%0 = cir.alloca !u32i, !cir.ptr<!u32i>, ["x1", init] {alignment = 4 : i64}
%1 = cir.alloca !s32i, !cir.ptr<!s32i>, ["x2", init] {alignment = 4 : i64}
%20 = cir.alloca !s16i, !cir.ptr<!s16i>, ["x4", init] {alignment = 2 : i64}
%2 = cir.alloca !s32i, !cir.ptr<!s32i>, ["__retval"] {alignment = 4 : i64}
%3 = cir.alloca !s8i, !cir.ptr<!s8i>, ["a", init] {alignment = 1 : i64}
%4 = cir.alloca !s16i, !cir.ptr<!s16i>, ["b", init] {alignment = 2 : i64}
%5 = cir.alloca !s64i, !cir.ptr<!s64i>, ["c", init] {alignment = 8 : i64}
%6 = cir.alloca !s64i, !cir.ptr<!s64i>, ["d", init] {alignment = 8 : i64}
%8 = cir.alloca !cir.ptr<!s32i>, !cir.ptr<!cir.ptr<!s32i>>, ["e", init] {alignment = 8 : i64}
cir.store %arg0, %0 : !u32i, !cir.ptr<!u32i>
cir.store %arg1, %1 : !s32i, !cir.ptr<!s32i>
// Integer casts.
%9 = cir.load %0 : !cir.ptr<!u32i>, !u32i
%10 = cir.cast integral %9 : !u32i -> !s8i
// CHECK: %{{[0-9]+}} = llvm.trunc %{{[0-9]+}} : i32 to i8
cir.store %10, %3 : !s8i, !cir.ptr<!s8i>
%11 = cir.load %1 : !cir.ptr<!s32i>, !s32i
%12 = cir.cast integral %11 : !s32i -> !s16i
// CHECK: %{{[0-9]+}} = llvm.trunc %{{[0-9]+}} : i32 to i16
cir.store %12, %4 : !s16i, !cir.ptr<!s16i>
%13 = cir.load %0 : !cir.ptr<!u32i>, !u32i
%14 = cir.cast integral %13 : !u32i -> !s64i
// CHECK: %{{[0-9]+}} = llvm.zext %{{[0-9]+}} : i32 to i64
cir.store %14, %5 : !s64i, !cir.ptr<!s64i>
%15 = cir.load %1 : !cir.ptr<!s32i>, !s32i
%16 = cir.cast integral %15 : !s32i -> !s64i
// CHECK: %{{[0-9]+}} = llvm.sext %{{[0-9]+}} : i32 to i64
%30 = cir.cast integral %arg1 : !s32i -> !u32i
// Should not produce a cast.
%32 = cir.cast integral %arg0 : !u32i -> !s32i
// Should not produce a cast.
%21 = cir.load %20 : !cir.ptr<!s16i>, !s16i
%22 = cir.cast integral %21 : !s16i -> !u64i
// CHECK: %[[TMP:[0-9]+]] = llvm.sext %{{[0-9]+}} : i16 to i64
%33 = cir.cast int_to_bool %arg1 : !s32i -> !cir.bool
// CHECK: %[[#ZERO:]] = llvm.mlir.constant(0 : i32) : i32
// CHECK: %[[#CMP:]] = llvm.icmp "ne" %arg1, %[[#ZERO]] : i32
// Pointer casts.
cir.store %16, %6 : !s64i, !cir.ptr<!s64i>
%23 = cir.cast int_to_ptr %22 : !u64i -> !cir.ptr<!u8i>
// CHECK: %[[TMP2:[0-9]+]] = llvm.inttoptr %[[TMP]] : i64 to !llvm.ptr
%24 = cir.cast ptr_to_int %23 : !cir.ptr<!u8i> -> !s32i
// CHECK: %{{[0-9]+}} = llvm.ptrtoint %[[TMP2]] : !llvm.ptr to i32
%29 = cir.cast ptr_to_bool %23 : !cir.ptr<!u8i> -> !cir.bool
// Floating point casts.
%25 = cir.cast int_to_float %arg1 : !s32i -> !cir.float
// CHECK: %{{.+}} = llvm.sitofp %{{.+}} : i32 to f32
%26 = cir.cast int_to_float %arg0 : !u32i -> !cir.float
// CHECK: %{{.+}} = llvm.uitofp %{{.+}} : i32 to f32
%27 = cir.cast float_to_int %arg2 : !cir.float -> !s32i
// CHECK: %{{.+}} = llvm.fptosi %{{.+}} : f32 to i32
%28 = cir.cast float_to_int %arg2 : !cir.float -> !u32i
// CHECK: %{{.+}} = llvm.fptoui %{{.+}} : f32 to i32
%18 = cir.const #cir.int<0> : !s32i
// CHECK: %{{.+}} = llvm.fptrunc %{{.+}} : f64 to f32
%34 = cir.cast floating %arg3 : !cir.double -> !cir.float
cir.store %18, %2 : !s32i, !cir.ptr<!s32i>
%19 = cir.load %2 : !cir.ptr<!s32i>, !s32i
cir.return %19 : !s32i
}
cir.func @testBoolToIntCast(%arg0: !cir.bool) {
// CHECK: llvm.func @testBoolToIntCast
%0 = cir.alloca !cir.bool, !cir.ptr<!cir.bool>, ["bl", init] {alignment = 1 : i64}
%1 = cir.alloca !u8i, !cir.ptr<!u8i>, ["y", init] {alignment = 1 : i64}
cir.store %arg0, %0 : !cir.bool, !cir.ptr<!cir.bool>
%2 = cir.load %0 : !cir.ptr<!cir.bool>, !cir.bool
%3 = cir.cast bool_to_int %2 : !cir.bool -> !u8i
// CHECK: %[[LOAD_BOOL:.*]] = llvm.load %{{.*}} : !llvm.ptr -> i8
// CHECK: %[[TRUNC:.*]] = llvm.trunc %[[LOAD_BOOL]] : i8 to i1
// CHECK: %[[EXT:.*]] = llvm.zext %[[TRUNC]] : i1 to i8
cir.store %3, %1 : !u8i, !cir.ptr<!u8i>
cir.return
}
cir.func @vectorCasts(%arg0: !cir.vector<2 x !s32i>, %arg1: !cir.vector<4 x !cir.float>) {
%i_2_f = cir.cast int_to_float %arg0 : !cir.vector<2 x !s32i> -> !cir.vector<2 x !cir.float>
// CHECK: %{{.+}} = llvm.sitofp %{{.+}} : vector<2xi32> to vector<2xf32>
%f_2_1 = cir.cast float_to_int %arg1 : !cir.vector<4 x !cir.float> -> !cir.vector<4 x !s32i>
// CHECK: %{{.+}} = llvm.fptosi %{{.+}} : vector<4xf32> to vector<4xi32>
%bitcast = cir.cast bitcast %arg0 : !cir.vector<2 x !s32i> -> !cir.vector<1 x !cir.double>
// CHECK: %{{.+}} = llvm.bitcast %{{.+}} : vector<2xi32> to vector<1xf64>
cir.return
}
}