Skip to content

Commit

Permalink
test: Add few more cast conversion tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
xlauko committed Oct 3, 2023
1 parent 470247d commit 7fe04eb
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/vast/Conversion/Common/IRsToLLVM/cast-g.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// RUN: %vast-cc1 -triple x86_64-unknown-linux-gnu -vast-emit-mlir=hl %s -o %t.mlir
// RUN: %file-check --input-file=%t.mlir %s -check-prefix=HL
// RUN: %vast-cc1 -triple x86_64-unknown-linux-gnu -vast-emit-mlir=llvm %s -o %t.mlir
// RUN: %file-check --input-file=%t.mlir %s -check-prefix=MLIR
// RUN: %vast-cc1 -triple x86_64-unknown-linux-gnu -vast-emit-llvm %s -o %t.ll
// RUN: %file-check --input-file=%t.ll %s -check-prefix=LLVM

void bool_to_int() {
_Bool b;
int i = b;
}

// HL: hl.func @bool_to_int ()
// HL: hl.implicit_cast {{.*}} IntegralCast : !hl.bool -> !hl.int
// HL: }

// MLIR: llvm.func @bool_to_int()
// MLIR: llvm.zext {{.*}} : i8 to i32
// MLIR: }

// LLVM: define void @bool_to_int()
// LLVM: zext i8 {{.*}} to i32
// LLVM: }
40 changes: 40 additions & 0 deletions test/vast/Conversion/Common/IRsToLLVM/cast-h.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// RUN: %vast-cc1 -triple x86_64-unknown-linux-gnu -vast-emit-mlir=hl %s -o %t.mlir
// RUN: %file-check --input-file=%t.mlir %s -check-prefix=HL
// RUN: %vast-cc1 -triple x86_64-unknown-linux-gnu -vast-emit-mlir=llvm %s -o %t.mlir
// RUN: %file-check --input-file=%t.mlir %s -check-prefix=MLIR
// RUN: %vast-cc1 -triple x86_64-unknown-linux-gnu -vast-emit-llvm %s -o %t.ll
// RUN: %file-check --input-file=%t.ll %s -check-prefix=LLVM

void float_to_signed() {
float f;
int i = f;
}

void float_to_unsigned() {
float f;
unsigned u = f;
}

// HL: hl.func @float_to_signed ()
// HL: hl.implicit_cast {{.*}} FloatingToIntegral : !hl.float -> !hl.int
// HL: }

// HL: hl.func @float_to_unsigned ()
// HL: hl.implicit_cast {{.*}} FloatingToIntegral : !hl.float -> !hl.int< unsigned >
// HL: }

// MLIR: llvm.func @float_to_signed()
// MLIR: llvm.fptosi {{.*}} : f32 to i32
// MLIR: }

// MLIR: llvm.func @float_to_unsigned()
// MLIR: llvm.fptoui {{.*}} : f32 to i32
// MLIR: }

// LLVM: define void @float_to_signed()
// LLVM: fptosi float {{.*}} to i32
// LLVM: }

// LLVM: define void @float_to_unsigned()
// LLVM: fptoui float {{.*}} to i32
// LLVM: }

0 comments on commit 7fe04eb

Please sign in to comment.