diff --git a/tests/filecheck/dialects/llvm/example.mlir b/tests/filecheck/dialects/llvm/example.mlir index 1a8ee0e7a2..0bec0a27c9 100644 --- a/tests/filecheck/dialects/llvm/example.mlir +++ b/tests/filecheck/dialects/llvm/example.mlir @@ -84,4 +84,10 @@ builtin.module { // CHECK-NEXT: func.return // CHECK-NEXT: } + %val = "test.op"() : () -> i32 + + %fval = llvm.bitcast %val : i32 to f32 + +// CHECK: %val = "test.op"() : () -> i32 +// CHECK-NEXT: %fval = llvm.bitcast %val : i32 to f32 } diff --git a/xdsl/dialects/llvm.py b/xdsl/dialects/llvm.py index 3d767ac40e..f1570f057c 100644 --- a/xdsl/dialects/llvm.py +++ b/xdsl/dialects/llvm.py @@ -1710,10 +1710,36 @@ class ZeroOp(IRDLOperation): res = result_def(LLVMTypeConstr) +@irdl_op_definition +class BitcastOp(IRDLOperation): + name = "llvm.bitcast" + + arg = operand_def(Attribute) + """ + LLVM-compatible non-aggregate type + """ + + result = result_def(Attribute) + """ + LLVM-compatible non-aggregate type + """ + + traits = traits_def(NoMemoryEffect()) + + assembly_format = "$arg attr-dict `:` type($arg) `to` type($result)" + + def __init__(self, val: Operation | SSAValue, res_type: Attribute): + super().__init__( + operands=[SSAValue.get(val)], + result_types=[res_type], + ) + + LLVM = Dialect( "llvm", [ AddOp, + BitcastOp, SubOp, MulOp, UDivOp,