From 20e78b8755f57903e4ee76da14a10cb2be0752cf Mon Sep 17 00:00:00 2001 From: Eric Schweitz Date: Sat, 20 Jul 2024 15:34:16 -0700 Subject: [PATCH] [C++ bridge] Switch from using arith ops to cc.cast (#1978) * [C++ bridge] Switch from using arith ops to cc.cast The arith dialect provides a big menu of casting/conversion operations that we can use but which have their own rules and semantics. For example, the generation of a quantum circuit can involve aggressive constant propagation. By using an operation in a dialect we control (CC), we can implement folding and combing these operations in ways that are suitable to our domain and do not rely on decisions in the MLIR code that may be too conservative or too aggressive for our needs. [core] Add constant folding of cc.cast operations. These constant folding operations will eliminate cc.cast operations when they are converting the type of a constant input op. Update the tests. Add pattern to eliminate integer casts into an integer comparison. Add constant folding of complex.create. Apparently MLIR doesn't do this. Add cast complex to complex and various constant foldings. Add a new test. Add codegen expansion pattern. * Convert test to work with ARM. --- include/cudaq/Optimizer/Builder/Factory.h | 1 + lib/Frontend/nvqpp/ConvertDecl.cpp | 8 +- lib/Frontend/nvqpp/ConvertExpr.cpp | 97 +++++------ lib/Optimizer/CodeGen/QuakeToCodegen.cpp | 25 ++- lib/Optimizer/Dialect/CC/CCOps.cpp | 156 +++++++++++++++++- lib/Optimizer/Dialect/CC/CMakeLists.txt | 13 +- test/AST-Quake/adjoint-3.cpp | 10 +- test/AST-Quake/array.cpp | 2 +- test/AST-Quake/cast.cpp | 2 +- test/AST-Quake/compute_action-2.cpp | 2 +- test/AST-Quake/custom_operations.cpp | 8 +- test/AST-Quake/empty_step.cpp | 10 +- test/AST-Quake/loop_normal.cpp | 6 +- test/AST-Quake/mz.cpp | 4 +- test/AST-Quake/operators.cpp | 14 +- test/AST-Quake/postfix_ops.cpp | 12 +- test/AST-Quake/qalloc_initialization.cpp | 172 ++++++++++---------- test/AST-Quake/qpe.cpp | 28 ++-- test/AST-Quake/ranged_for.cpp | 2 +- test/AST-Quake/simple.cpp | 6 +- test/AST-Quake/simple_qarray.cpp | 4 +- test/AST-Quake/struct-1.cpp | 4 +- test/AST-Quake/tuple-0.cpp | 16 +- test/AST-Quake/vector_ctor_initlist_int.cpp | 12 +- test/AST-Quake/vector_vector.cpp | 2 +- test/AST-Quake/veq_size_init_state.cpp | 42 +++-- test/AST-Quake/while-1.cpp | 40 ++--- test/Quake/cast_fold.qke | 108 ++++++++++++ test/Quake/complex.qke | 46 ++++++ 29 files changed, 587 insertions(+), 265 deletions(-) create mode 100644 test/Quake/cast_fold.qke create mode 100644 test/Quake/complex.qke diff --git a/include/cudaq/Optimizer/Builder/Factory.h b/include/cudaq/Optimizer/Builder/Factory.h index 42c2d306b8..53d79fdff7 100644 --- a/include/cudaq/Optimizer/Builder/Factory.h +++ b/include/cudaq/Optimizer/Builder/Factory.h @@ -252,6 +252,7 @@ bool isAArch64(mlir::ModuleOp); bool structUsesTwoArguments(mlir::Type ty); std::optional getIntIfConstant(mlir::Value value); +std::optional getDoubleIfConstant(mlir::Value value); /// Create a `cc.cast` operation, if it is needed. mlir::Value createCast(mlir::OpBuilder &builder, mlir::Location loc, diff --git a/lib/Frontend/nvqpp/ConvertDecl.cpp b/lib/Frontend/nvqpp/ConvertDecl.cpp index 50de32b768..b8816e164b 100644 --- a/lib/Frontend/nvqpp/ConvertDecl.cpp +++ b/lib/Frontend/nvqpp/ConvertDecl.cpp @@ -749,14 +749,16 @@ bool QuakeBridgeVisitor::VisitVarDecl(clang::VarDecl *x) { if (initValue.getType().getIntOrFloatBitWidth() < type.getIntOrFloatBitWidth()) { // FIXME: Use zero-extend if this is unsigned! - initValue = builder.create(loc, type, initValue); + initValue = builder.create( + loc, type, initValue, cudaq::cc::CastOpMode::Signed); } else if (initValue.getType().getIntOrFloatBitWidth() > type.getIntOrFloatBitWidth()) { - initValue = builder.create(loc, type, initValue); + initValue = builder.create(loc, type, initValue); } } else if (isa(initValue.getType()) && isa(type)) { // FIXME: Use UIToFP if this is unsigned! - initValue = builder.create(loc, type, initValue); + initValue = builder.create( + loc, type, initValue, cudaq::cc::CastOpMode::Signed); } if (auto initObject = initValue.getDefiningOp()) { diff --git a/lib/Frontend/nvqpp/ConvertExpr.cpp b/lib/Frontend/nvqpp/ConvertExpr.cpp index 8ea2f97dfe..55599a018d 100644 --- a/lib/Frontend/nvqpp/ConvertExpr.cpp +++ b/lib/Frontend/nvqpp/ConvertExpr.cpp @@ -295,8 +295,9 @@ static Value toIntegerImpl(OpBuilder &builder, Location loc, Value bitVec) { Value bitElement = builder.create(loc, eleAddr); // -bits[k] - bitElement = builder.create(loc, builder.getI32Type(), - bitElement); + bitElement = builder.create( + loc, builder.getI32Type(), bitElement, + cudaq::cc::CastOpMode::Unsigned); bitElement = builder.create(loc, negOne, bitElement); // -bits[k] ^ i @@ -326,38 +327,38 @@ static void castToSameType(OpBuilder builder, Location loc, auto rhsTy = rhs.getType(); if (lhsTy.isa() && rhsTy.isa()) { if (lhsTy.getIntOrFloatBitWidth() < rhsTy.getIntOrFloatBitWidth()) { - if (lhsType && lhsType->isUnsignedIntegerOrEnumerationType()) - lhs = builder.create(loc, rhs.getType(), lhs); - else - lhs = builder.create(loc, rhs.getType(), lhs); + auto mode = (lhsType && lhsType->isUnsignedIntegerOrEnumerationType()) + ? cudaq::cc::CastOpMode::Unsigned + : cudaq::cc::CastOpMode::Signed; + lhs = builder.create(loc, rhs.getType(), lhs, mode); return; } - if (rhsType && rhsType->isUnsignedIntegerOrEnumerationType()) - rhs = builder.create(loc, lhs.getType(), rhs); - else - rhs = builder.create(loc, lhs.getType(), rhs); + auto mode = (rhsType && rhsType->isUnsignedIntegerOrEnumerationType()) + ? cudaq::cc::CastOpMode::Unsigned + : cudaq::cc::CastOpMode::Signed; + rhs = builder.create(loc, lhs.getType(), rhs, mode); return; } if (lhsTy.isa() && rhsTy.isa()) { if (lhsTy.getIntOrFloatBitWidth() < rhsTy.getIntOrFloatBitWidth()) { - lhs = builder.create(loc, rhs.getType(), lhs); + lhs = builder.create(loc, rhs.getType(), lhs); return; } - rhs = builder.create(loc, lhs.getType(), rhs); + rhs = builder.create(loc, lhs.getType(), rhs); return; } if (lhsTy.isa() && rhsTy.isa()) { - if (rhsType && rhsType->isUnsignedIntegerOrEnumerationType()) - rhs = builder.create(loc, lhs.getType(), rhs); - else - rhs = builder.create(loc, lhs.getType(), rhs); + auto mode = (rhsType && rhsType->isUnsignedIntegerOrEnumerationType()) + ? cudaq::cc::CastOpMode::Unsigned + : cudaq::cc::CastOpMode::Signed; + rhs = builder.create(loc, lhs.getType(), rhs, mode); return; } if (lhsTy.isa() && rhsTy.isa()) { - if (lhsType && lhsType->isUnsignedIntegerOrEnumerationType()) - lhs = builder.create(loc, rhs.getType(), lhs); - else - lhs = builder.create(loc, rhs.getType(), lhs); + auto mode = (lhsType && lhsType->isUnsignedIntegerOrEnumerationType()) + ? cudaq::cc::CastOpMode::Unsigned + : cudaq::cc::CastOpMode::Signed; + lhs = builder.create(loc, rhs.getType(), lhs, mode); return; } TODO_loc(loc, "conversion of operands in binary expression"); @@ -579,14 +580,8 @@ Value QuakeBridgeVisitor::floatingPointCoercion(Location loc, Type toType, auto fromType = value.getType(); if (toType == fromType) return value; - if (fromType.isa() && toType.isa()) { - if (fromType.getIntOrFloatBitWidth() < toType.getIntOrFloatBitWidth()) - return builder.create(loc, toType, value); - if (fromType.getIntOrFloatBitWidth() > toType.getIntOrFloatBitWidth()) - return builder.create(loc, toType, value); - TODO_loc(loc, "floating point types are distinct and same size"); - } - TODO_loc(loc, "Float conversion but not floating point types"); + assert(fromType.isa() && toType.isa()); + return builder.create(loc, toType, value); } Value QuakeBridgeVisitor::integerCoercion(Location loc, @@ -596,17 +591,15 @@ Value QuakeBridgeVisitor::integerCoercion(Location loc, if (dstTy == fromTy) return srcVal; - if (fromTy.isa() && dstTy.isa()) { - if (fromTy.getIntOrFloatBitWidth() < dstTy.getIntOrFloatBitWidth()) { - if (clangTy->isUnsignedIntegerOrEnumerationType()) - return builder.create(loc, dstTy, srcVal); - return builder.create(loc, dstTy, srcVal); - } - if (fromTy.getIntOrFloatBitWidth() > dstTy.getIntOrFloatBitWidth()) - return builder.create(loc, dstTy, srcVal); - TODO_loc(loc, "Types are not the same but have the same length"); + assert(fromTy.isa() && dstTy.isa()); + if (fromTy.getIntOrFloatBitWidth() < dstTy.getIntOrFloatBitWidth()) { + auto mode = (clangTy->isUnsignedIntegerOrEnumerationType()) + ? cudaq::cc::CastOpMode::Unsigned + : cudaq::cc::CastOpMode::Signed; + return builder.create(loc, dstTy, srcVal, mode); } - TODO_loc(loc, "Integer conversion but not integer types"); + assert(fromTy.getIntOrFloatBitWidth() > dstTy.getIntOrFloatBitWidth()); + return builder.create(loc, dstTy, srcVal); } bool QuakeBridgeVisitor::TraverseCastExpr(clang::CastExpr *x, @@ -654,9 +647,7 @@ bool QuakeBridgeVisitor::VisitCastExpr(clang::CastExpr *x) { assert(toType && fromType); if (toType == fromType) return pushValue(value); - if (fromType.getIntOrFloatBitWidth() < toType.getIntOrFloatBitWidth()) - return pushValue(builder.create(loc, toType, value)); - return pushValue(builder.create(loc, toType, value)); + return pushValue(builder.create(loc, toType, value)); } case clang::CastKind::CK_IntegralCast: { auto locSub = toLocation(x->getSubExpr()); @@ -672,18 +663,19 @@ bool QuakeBridgeVisitor::VisitCastExpr(clang::CastExpr *x) { return true; case clang::CastKind::CK_FloatingToIntegral: { auto qualTy = x->getType(); - if (qualTy->isUnsignedIntegerOrEnumerationType()) - return pushValue( - builder.create(loc, castToTy, popValue())); + auto mode = qualTy->isUnsignedIntegerOrEnumerationType() + ? cudaq::cc::CastOpMode::Unsigned + : cudaq::cc::CastOpMode::Signed; return pushValue( - builder.create(loc, castToTy, popValue())); + builder.create(loc, castToTy, popValue(), mode)); } case clang::CastKind::CK_IntegralToFloating: { - if (x->getSubExpr()->getType()->isUnsignedIntegerOrEnumerationType()) - return pushValue( - builder.create(loc, castToTy, popValue())); + auto mode = + (x->getSubExpr()->getType()->isUnsignedIntegerOrEnumerationType()) + ? cudaq::cc::CastOpMode::Unsigned + : cudaq::cc::CastOpMode::Signed; return pushValue( - builder.create(loc, castToTy, popValue())); + builder.create(loc, castToTy, popValue(), mode)); } case clang::CastKind::CK_IntegralToBoolean: { auto last = popValue(); @@ -1153,7 +1145,7 @@ bool QuakeBridgeVisitor::VisitCallExpr(clang::CallExpr *x) { // Get the values involved auto peelIntToFloat = [&](Value v) { - if (auto op = v.getDefiningOp()) + if (auto op = v.getDefiningOp()) return op.getOperand(); return v; }; @@ -1171,7 +1163,8 @@ bool QuakeBridgeVisitor::VisitCallExpr(clang::CallExpr *x) { base, x->getArg(1)->getType().getTypePtrOrNull(), power); auto ipow = builder.create(loc, base, power); if (isa(resTy)) - return pushValue(builder.create(loc, resTy, ipow)); + return pushValue(builder.create( + loc, resTy, ipow, cudaq::cc::CastOpMode::Signed)); assert(resTy == ipow.getType()); return pushValue(ipow); } @@ -2228,7 +2221,7 @@ bool QuakeBridgeVisitor::VisitCXXOperatorCallExpr( auto eleAddr = builder.create(loc, elePtrTy, vecPtr, ValueRange{indexVar}); auto i1PtrTy = cc::PointerType::get(builder.getI1Type()); - auto i1Cast = builder.create(loc, i1PtrTy, eleAddr); + auto i1Cast = builder.create(loc, i1PtrTy, eleAddr); return replaceTOSValue(i1Cast); } TODO_loc(loc, "unhandled operator call for quake conversion"); diff --git a/lib/Optimizer/CodeGen/QuakeToCodegen.cpp b/lib/Optimizer/CodeGen/QuakeToCodegen.cpp index ce305263e4..e9e56f8f5f 100644 --- a/lib/Optimizer/CodeGen/QuakeToCodegen.cpp +++ b/lib/Optimizer/CodeGen/QuakeToCodegen.cpp @@ -12,6 +12,7 @@ #include "cudaq/Optimizer/Dialect/Quake/QuakeOps.h" #include "mlir/Conversion/LLVMCommon/ConversionTarget.h" #include "mlir/Conversion/LLVMCommon/Pattern.h" +#include "mlir/Dialect/Complex/IR/Complex.h" using namespace mlir; @@ -39,10 +40,32 @@ class CodeGenRAIIPattern : public OpRewritePattern { return success(); } }; + +class ExpandComplexCast : public OpRewritePattern { +public: + using OpRewritePattern::OpRewritePattern; + + LogicalResult matchAndRewrite(cudaq::cc::CastOp castOp, + PatternRewriter &rewriter) const override { + auto complexTy = dyn_cast(castOp.getType()); + if (!complexTy) + return failure(); + auto loc = castOp.getLoc(); + auto ty = cast(castOp.getValue().getType()).getElementType(); + Value rePart = rewriter.create(loc, ty, castOp.getValue()); + Value imPart = rewriter.create(loc, ty, castOp.getValue()); + auto eleTy = complexTy.getElementType(); + auto reCast = rewriter.create(loc, eleTy, rePart); + auto imCast = rewriter.create(loc, eleTy, imPart); + rewriter.replaceOpWithNewOp(castOp, complexTy, reCast, + imCast); + return success(); + } +}; } // namespace void cudaq::codegen::populateQuakeToCodegenPatterns( mlir::RewritePatternSet &patterns) { auto *ctx = patterns.getContext(); - patterns.insert(ctx); + patterns.insert(ctx); } diff --git a/lib/Optimizer/Dialect/CC/CCOps.cpp b/lib/Optimizer/Dialect/CC/CCOps.cpp index d61182e5d6..73660a6191 100644 --- a/lib/Optimizer/Dialect/CC/CCOps.cpp +++ b/lib/Optimizer/Dialect/CC/CCOps.cpp @@ -11,6 +11,7 @@ #include "cudaq/Optimizer/Dialect/CC/CCDialect.h" #include "cudaq/Optimizer/Dialect/Quake/QuakeOps.h" #include "llvm/ADT/TypeSwitch.h" +#include "mlir/Dialect/Complex/IR/Complex.h" #include "mlir/Dialect/ControlFlow/IR/ControlFlowOps.h" #include "mlir/Dialect/Utils/IndexingUtils.h" #include "mlir/Dialect/Utils/StructuredOpsUtils.h" @@ -39,6 +40,13 @@ std::optional cudaq::opt::factory::getIntIfConstant(Value value) { return {}; } +std::optional cudaq::opt::factory::getDoubleIfConstant(Value value) { + APFloat constant{0.0}; + if (matchPattern(value, m_ConstantFloat(&constant))) + return {constant}; + return {}; +} + Value cudaq::cc::getByteSizeOfType(OpBuilder &builder, Location loc, Type ty, bool useSizeOf) { auto createInt = [&](std::int32_t byteWidth) -> Value { @@ -187,10 +195,100 @@ void cudaq::cc::AllocaOp::getCanonicalizationPatterns( // CastOp //===----------------------------------------------------------------------===// -OpFoldResult cudaq::cc::CastOp::fold(FoldAdaptor) { +OpFoldResult cudaq::cc::CastOp::fold(FoldAdaptor adaptor) { // If cast is a nop, just forward the argument to the uses. if (getType() == getValue().getType()) return getValue(); + if (auto optConst = adaptor.getValue()) { + // Replace a constant + cast with a new constant of an updated type. + auto ty = getType(); + OpBuilder builder(*this); + auto fltTy = builder.getF32Type(); + auto dblTy = builder.getF64Type(); + auto loc = getLoc(); + if (auto attr = dyn_cast(optConst)) { + auto val = attr.getInt(); + if (isa(ty)) { + auto width = ty.getIntOrFloatBitWidth(); + return builder.create(loc, val, width) + .getResult(); + } else if (ty == fltTy) { + if (getZint()) { + APFloat fval(static_cast(static_cast(val))); + return builder.create(loc, fval, fltTy) + .getResult(); + } + if (getSint()) { + APFloat fval(static_cast(val)); + return builder.create(loc, fval, fltTy) + .getResult(); + } + } else if (ty == dblTy) { + if (getZint()) { + APFloat fval(static_cast(static_cast(val))); + return builder.create(loc, fval, dblTy) + .getResult(); + } + if (getSint()) { + APFloat fval(static_cast(val)); + return builder.create(loc, fval, dblTy) + .getResult(); + } + } + } + if (auto attr = dyn_cast(optConst)) { + auto val = attr.getValue(); + if (isa(ty)) { + auto width = ty.getIntOrFloatBitWidth(); + if (getZint()) { + std::uint64_t v = val.convertToDouble(); + return builder.create(loc, v, width) + .getResult(); + } + if (getSint()) { + std::int64_t v = val.convertToDouble(); + return builder.create(loc, v, width) + .getResult(); + } + } else if (ty == fltTy) { + float f = val.convertToDouble(); + APFloat fval(f); + return builder.create(loc, fval, fltTy) + .getResult(); + } else if (ty == dblTy) { + APFloat fval{val.convertToDouble()}; + return builder.create(loc, fval, dblTy) + .getResult(); + } + } + + // %5 = complex.constant ... -> complex + // %6 = cc.cast %5 : (complex) -> complex + // ──────────────────────────────────────────── + // %6 = complex.constant ... -> complex + if (auto attr = dyn_cast(optConst)) { + auto eleTy = cast(ty).getElementType(); + auto reFp = dyn_cast(attr[0]); + auto imFp = dyn_cast(attr[1]); + if (reFp && imFp) { + if (eleTy == fltTy) { + float reVal = reFp.getValue().convertToDouble(); + float imVal = imFp.getValue().convertToDouble(); + auto rePart = builder.getFloatAttr(eleTy, APFloat{reVal}); + auto imPart = builder.getFloatAttr(eleTy, APFloat{imVal}); + auto cv = builder.getArrayAttr({rePart, imPart}); + return builder.create(loc, ty, cv).getResult(); + } else if (eleTy == dblTy) { + double reVal = reFp.getValue().convertToDouble(); + double imVal = imFp.getValue().convertToDouble(); + auto rePart = builder.getFloatAttr(eleTy, APFloat{reVal}); + auto imPart = builder.getFloatAttr(eleTy, APFloat{imVal}); + auto cv = builder.getArrayAttr({rePart, imPart}); + return builder.create(loc, ty, cv).getResult(); + } + } + } + } return nullptr; } @@ -253,6 +351,9 @@ LogicalResult cudaq::cc::CastOp::verify() { } else if (isa(inTy) && isa(outTy)) { // ok, pointer casts: bitcast, nop + } else if (isa(inTy) && isa(outTy)) { + // ok, type conversion of a complex value + // NB: use complex.re or complex.im to convert (extract) a fp value. } else { // Could support a bitcast of a float with pointer size bits to/from a // pointer, but that doesn't seem like it would be very common. @@ -282,11 +383,62 @@ struct FuseCastCascade : public OpRewritePattern { return success(); } }; + +// Ad hoc pattern to erase casts used by arith.cmpi. +struct SimplifyIntegerCompare : public OpRewritePattern { + using OpRewritePattern::OpRewritePattern; + + LogicalResult matchAndRewrite(arith::CmpIOp compare, + PatternRewriter &rewriter) const override { + auto lhsCast = compare.getLhs().getDefiningOp(); + auto rhsCast = compare.getRhs().getDefiningOp(); + // %4 = cc.cast %2 ... + // %5 = cc.cast %3 ... + // %6 = arith.cmpi %4, %5 ... + // and + // type(%2) == type(%3) + // and + // %4 and %5 are compatible casts + // ────────────────────────────── + // %5 = arith.cmpi %2, %3 ... + if (lhsCast && rhsCast) { + auto lhsVal = lhsCast.getValue(); + auto rhsVal = rhsCast.getValue(); + if (lhsVal.getType() == rhsVal.getType() && + lhsCast.getSint() == rhsCast.getSint() && + lhsCast.getZint() == rhsCast.getZint()) + rewriter.replaceOpWithNewOp( + compare, compare.getType(), compare.getPredicate(), lhsVal, rhsVal); + } + return success(); + } +}; + +// Ad hoc pattern to erase complex.create. (MLIR doesn't do this.) +struct FuseComplexCreate : public OpRewritePattern { + using OpRewritePattern::OpRewritePattern; + LogicalResult matchAndRewrite(complex::CreateOp create, + PatternRewriter &rewriter) const override { + auto reVal = cudaq::opt::factory::getDoubleIfConstant(create.getReal()); + auto imVal = + cudaq::opt::factory::getDoubleIfConstant(create.getImaginary()); + if (reVal && imVal) { + auto eleTy = cast(create.getType()).getElementType(); + auto rePart = rewriter.getFloatAttr(eleTy, *reVal); + auto imPart = rewriter.getFloatAttr(eleTy, *imVal); + auto arrAttr = rewriter.getArrayAttr({rePart, imPart}); + rewriter.replaceOpWithNewOp( + create, ComplexType::get(eleTy), arrAttr); + } + return success(); + } +}; } // namespace void cudaq::cc::CastOp::getCanonicalizationPatterns(RewritePatternSet &patterns, MLIRContext *context) { - patterns.add(context); + patterns.add( + context); } //===----------------------------------------------------------------------===// diff --git a/lib/Optimizer/Dialect/CC/CMakeLists.txt b/lib/Optimizer/Dialect/CC/CMakeLists.txt index 81efab4d20..c897a150ac 100644 --- a/lib/Optimizer/Dialect/CC/CMakeLists.txt +++ b/lib/Optimizer/Dialect/CC/CMakeLists.txt @@ -12,12 +12,13 @@ add_cudaq_dialect_library(CCDialect CCTypes.cpp DEPENDS - CCDialectIncGen - CCOpsIncGen - CCTypesIncGen + CCDialectIncGen + CCOpsIncGen + CCTypesIncGen LINK_LIBS - MLIRFuncDialect - MLIRLLVMDialect - MLIRIR + MLIRComplexDialect + MLIRFuncDialect + MLIRLLVMDialect + MLIRIR ) diff --git a/test/AST-Quake/adjoint-3.cpp b/test/AST-Quake/adjoint-3.cpp index 792ad97116..7201ddeeba 100644 --- a/test/AST-Quake/adjoint-3.cpp +++ b/test/AST-Quake/adjoint-3.cpp @@ -95,9 +95,9 @@ struct run_circuit { // ADJOINT-DAG: %[[VAL_6:.*]] = arith.constant 0 : i64 // ADJOINT-DAG: %[[VAL_7:.*]] = arith.constant 1 : i32 // ADJOINT: %[[VAL_8:.*]] = quake.veq_size %[[VAL_0]] : (!quake.veq) -> i64 -// ADJOINT: %[[VAL_9:.*]] = arith.trunci %[[VAL_8]] : i64 to i32 +// ADJOINT: %[[VAL_9:.*]] = cc.cast %[[VAL_8]] : (i64) -> i32 // ADJOINT: %[[VAL_10:.*]] = arith.subi %[[VAL_9]], %[[VAL_7]] : i32 -// ADJOINT: %[[VAL_11:.*]] = arith.extsi %[[VAL_10]] : i32 to i64 +// ADJOINT: %[[VAL_11:.*]] = cc.cast signed %[[VAL_10]] : (i32) -> i64 // ADJOINT: %[[VAL_12:.*]] = arith.subi %[[VAL_11]], %[[VAL_5]] : i64 // ADJOINT: %[[VAL_13:.*]] = quake.subveq %[[VAL_0]], %[[VAL_6]], %[[VAL_12]] : (!quake.veq, i64, i64) -> !quake.veq // ADJOINT: %[[VAL_14:.*]] = quake.veq_size %[[VAL_13]] : (!quake.veq) -> i64 @@ -105,7 +105,7 @@ struct run_circuit { // ADJOINT: %[[VAL_18:.*]] = math.fpowi %[[VAL_2]], %[[VAL_16]] : f64, i32 // ADJOINT: %[[VAL_19:.*]] = arith.divf %[[VAL_1]], %[[VAL_18]] : f64 // ADJOINT: %[[VAL_20:.*]] = arith.subi %[[VAL_9]], %[[VAL_7]] : i32 -// ADJOINT: %[[VAL_21:.*]] = arith.extsi %[[VAL_20]] : i32 to i64 +// ADJOINT: %[[VAL_21:.*]] = cc.cast signed %[[VAL_20]] : (i32) -> i64 // ADJOINT: %[[VAL_22:.*]] = quake.extract_ref %[[VAL_0]]{{\[}}%[[VAL_21]]] : (!quake.veq, i64) -> !quake.ref // ADJOINT: %[[VAL_23:.*]] = arith.constant 0 : i32 // ADJOINT: %[[VAL_24:.*]] = arith.subi %[[VAL_9]], %[[VAL_7]] : i32 @@ -131,10 +131,10 @@ struct run_circuit { // ADJOINT: %[[VAL_50:.*]] = math.fpowi %[[VAL_2]], %[[VAL_48]] : f64, i32 // ADJOINT: %[[VAL_51:.*]] = arith.divf %[[VAL_1]], %[[VAL_50]] : f64 // ADJOINT: %[[VAL_52:.*]] = arith.subi %[[VAL_43]], %[[VAL_7]] : i32 -// ADJOINT: %[[VAL_53:.*]] = arith.extsi %[[VAL_52]] : i32 to i64 +// ADJOINT: %[[VAL_53:.*]] = cc.cast signed %[[VAL_52]] : (i32) -> i64 // ADJOINT: %[[VAL_54:.*]] = quake.extract_ref %[[VAL_0]]{{\[}}%[[VAL_53]]] : (!quake.veq, i64) -> !quake.ref // ADJOINT: %[[VAL_55:.*]] = arith.subi %[[VAL_9]], %[[VAL_7]] : i32 -// ADJOINT: %[[VAL_56:.*]] = arith.extsi %[[VAL_55]] : i32 to i64 +// ADJOINT: %[[VAL_56:.*]] = cc.cast signed %[[VAL_55]] : (i32) -> i64 // ADJOINT: %[[VAL_57:.*]] = quake.extract_ref %[[VAL_0]]{{\[}}%[[VAL_56]]] : (!quake.veq, i64) -> !quake.ref // ADJOINT: %[[VAL_58:.*]] = arith.negf %[[VAL_51]] : f64 // ADJOINT: quake.ry (%[[VAL_58]]) [%[[VAL_54]]] %[[VAL_57]] : (f64, !quake.ref, !quake.ref) -> () diff --git a/test/AST-Quake/array.cpp b/test/AST-Quake/array.cpp index 7429587e3a..40c7d74dc1 100644 --- a/test/AST-Quake/array.cpp +++ b/test/AST-Quake/array.cpp @@ -24,7 +24,7 @@ struct T { // CHECK: %[[VAL_3:.*]] = cc.alloca i32 // CHECK: cc.store %[[VAL_0]], %[[VAL_3]] : !cc.ptr // CHECK: %[[VAL_4:.*]] = cc.load %[[VAL_3]] : !cc.ptr -// CHECK: %[[VAL_5:.*]] = arith.extsi %[[VAL_4]] : i32 to i64 +// CHECK: %[[VAL_5:.*]] = cc.cast signed %[[VAL_4]] : (i32) -> i64 // CHECK: %[[VAL_6:.*]] = quake.alloca !quake.veq{{\[}}%[[VAL_5]] : i64] // CHECK: %[[VAL_7:.*]] = quake.veq_size %[[VAL_6]] : (!quake.veq) -> i64 // CHECK: %[[VAL_9:.*]] = cc.loop while ((%[[VAL_10:.*]] = %[[VAL_2]]) -> (i64)) { diff --git a/test/AST-Quake/cast.cpp b/test/AST-Quake/cast.cpp index 203b556e4e..3b13179763 100644 --- a/test/AST-Quake/cast.cpp +++ b/test/AST-Quake/cast.cpp @@ -29,7 +29,7 @@ struct testCast { // CHECK: quake.h %[[VAL_1]] : (!quake.ref) -> () // CHECK: %[[VAL_3:.*]] = quake.mz %[[VAL_1]] : (!quake.ref) -> !quake.measure // CHECK: %[[VAL_10:.*]] = quake.discriminate %[[VAL_3]] : -// CHECK: %[[VAL_4:.*]] = arith.uitofp %[[VAL_10]] : i1 to f64 +// CHECK: %[[VAL_4:.*]] = cc.cast unsigned %[[VAL_10]] : (i1) -> f64 // CHECK: %[[VAL_5:.*]] = cc.alloca f64 // CHECK: cc.store %[[VAL_4]], %[[VAL_5]] : !cc.ptr // CHECK: %[[VAL_6:.*]] = cc.load %[[VAL_5]] : !cc.ptr diff --git a/test/AST-Quake/compute_action-2.cpp b/test/AST-Quake/compute_action-2.cpp index f7d9546178..78c87e4282 100644 --- a/test/AST-Quake/compute_action-2.cpp +++ b/test/AST-Quake/compute_action-2.cpp @@ -72,7 +72,7 @@ struct ctrlHeisenberg { // CHECK: cc.store %[[VAL_0]], %[[VAL_1]] : !cc.ptr // CHECK: %[[VAL_2:.*]] = quake.alloca !quake.ref // CHECK: %[[VAL_3:.*]] = cc.load %[[VAL_1]] : !cc.ptr -// CHECK: %[[VAL_4:.*]] = arith.extsi %[[VAL_3]] : i32 to i64 +// CHECK: %[[VAL_4:.*]] = cc.cast signed %[[VAL_3]] : (i32) -> i64 // CHECK: %[[VAL_5:.*]] = quake.alloca !quake.veq[%[[VAL_4]] : i64] // CHECK: %[[VAL_6:.*]] = quake.concat %[[VAL_2]] : (!quake.ref) -> !quake.veq // CHECK: call @__nvqpp__mlirgen__function_magic_func.{{.*}}.ctrl(%[[VAL_6]], %[[VAL_5]]) : (!quake.veq, !quake.veq) -> () diff --git a/test/AST-Quake/custom_operations.cpp b/test/AST-Quake/custom_operations.cpp index 837f50b447..4baceb75aa 100644 --- a/test/AST-Quake/custom_operations.cpp +++ b/test/AST-Quake/custom_operations.cpp @@ -128,10 +128,10 @@ __qpu__ void kernel_6() { } // CHECK-LABEL: func.func @__nvqpp__mlirgen__function_kernel_6._Z8kernel_6v() attributes {"cudaq-entrypoint", "cudaq-kernel", no_this} { -// CHECK: %[[VAL_0:.*]] = arith.constant 1 : i64 -// CHECK: %[[VAL_1:.*]] = arith.constant 0 : i64 -// CHECK: %[[VAL_2:.*]] = arith.constant 3 : i64 -// CHECK: %[[VAL_3:.*]] = quake.alloca !quake.veq<3> +// CHECK-DAG: %[[VAL_0:.*]] = arith.constant 1 : i64 +// CHECK-DAG: %[[VAL_1:.*]] = arith.constant 0 : i64 +// CHECK-DAG: %[[VAL_2:.*]] = arith.constant 3 : i64 +// CHECK-DAG: %[[VAL_3:.*]] = quake.alloca !quake.veq<3> // CHECK: %[[VAL_4:.*]] = cc.loop while ((%[[VAL_5:.*]] = %[[VAL_1]]) -> (i64)) { // CHECK: %[[VAL_6:.*]] = arith.cmpi slt, %[[VAL_5]], %[[VAL_2]] : i64 // CHECK: cc.condition %[[VAL_6]](%[[VAL_5]] : i64) diff --git a/test/AST-Quake/empty_step.cpp b/test/AST-Quake/empty_step.cpp index ad7f31beb3..86214481e5 100644 --- a/test/AST-Quake/empty_step.cpp +++ b/test/AST-Quake/empty_step.cpp @@ -25,27 +25,27 @@ __qpu__ void test(cudaq::qview<> a, cudaq::qview<> b) { // CHECK-DAG: %[[VAL_2:.*]] = arith.constant 1 : i64 // CHECK-DAG: %[[VAL_3:.*]] = arith.constant 1 : i32 // CHECK: %[[VAL_4:.*]] = quake.veq_size %[[VAL_0]] : (!quake.veq) -> i64 -// CHECK: %[[VAL_5:.*]] = arith.trunci %[[VAL_4]] : i64 to i32 +// CHECK: %[[VAL_5:.*]] = cc.cast %[[VAL_4]] : (i64) -> i32 // CHECK: %[[VAL_6:.*]] = cc.alloca i32 // CHECK: cc.store %[[VAL_5]], %[[VAL_6]] : !cc.ptr // CHECK: cc.loop while { // CHECK: %[[VAL_7:.*]] = cc.load %[[VAL_6]] : !cc.ptr // CHECK: %[[VAL_8:.*]] = arith.subi %[[VAL_7]], %[[VAL_3]] : i32 // CHECK: cc.store %[[VAL_8]], %[[VAL_6]] : !cc.ptr -// CHECK: %[[VAL_9:.*]] = arith.extui %[[VAL_7]] : i32 to i64 +// CHECK: %[[VAL_9:.*]] = cc.cast unsigned %[[VAL_7]] : (i32) -> i64 // CHECK: %[[VAL_10:.*]] = arith.cmpi ugt, %[[VAL_9]], %[[VAL_2]] : i64 // CHECK: cc.condition %[[VAL_10]] // CHECK: } do { // CHECK: %[[VAL_11:.*]] = cc.load %[[VAL_6]] : !cc.ptr -// CHECK: %[[VAL_12:.*]] = arith.extui %[[VAL_11]] : i32 to i64 +// CHECK: %[[VAL_12:.*]] = cc.cast unsigned %[[VAL_11]] : (i32) -> i64 // CHECK: %[[VAL_13:.*]] = arith.subi %[[VAL_12]], %[[VAL_2]] : i64 // CHECK: %[[VAL_14:.*]] = quake.extract_ref %[[VAL_0]]{{\[}}%[[VAL_13]]] : (!quake.veq, i64) -> !quake.ref // CHECK: %[[VAL_15:.*]] = cc.load %[[VAL_6]] : !cc.ptr -// CHECK: %[[VAL_16:.*]] = arith.extui %[[VAL_15]] : i32 to i64 +// CHECK: %[[VAL_16:.*]] = cc.cast unsigned %[[VAL_15]] : (i32) -> i64 // CHECK: %[[VAL_17:.*]] = arith.subi %[[VAL_16]], %[[VAL_2]] : i64 // CHECK: %[[VAL_18:.*]] = quake.extract_ref %[[VAL_1]]{{\[}}%[[VAL_17]]] : (!quake.veq, i64) -> !quake.ref // CHECK: %[[VAL_19:.*]] = cc.load %[[VAL_6]] : !cc.ptr -// CHECK: %[[VAL_20:.*]] = arith.extui %[[VAL_19]] : i32 to i64 +// CHECK: %[[VAL_20:.*]] = cc.cast unsigned %[[VAL_19]] : (i32) -> i64 // CHECK: %[[VAL_21:.*]] = quake.extract_ref %[[VAL_0]]{{\[}}%[[VAL_20]]] : (!quake.veq, i64) -> !quake.ref // CHECK: func.call @__nvqpp__mlirgen__function_uma._Z3umaRN5cudaq5quditILm2EEES2_S2_(%[[VAL_14]], %[[VAL_18]], %[[VAL_21]]) : (!quake.ref, !quake.ref, !quake.ref) -> () // CHECK: cc.continue diff --git a/test/AST-Quake/loop_normal.cpp b/test/AST-Quake/loop_normal.cpp index 2d78eaa4c0..917c7ca7d6 100644 --- a/test/AST-Quake/loop_normal.cpp +++ b/test/AST-Quake/loop_normal.cpp @@ -79,7 +79,7 @@ __qpu__ void foo3() { // CHECK: } do { // CHECK: ^bb0(%[[VAL_8:.*]]: i32): // CHECK: %[[VAL_9:.*]] = arith.muli %[[VAL_8]], %[[VAL_2]] : i32 -// CHECK: %[[VAL_10:.*]] = arith.extsi %[[VAL_9]] : i32 to i64 +// CHECK: %[[VAL_10:.*]] = cc.cast signed %[[VAL_9]] : (i32) -> i64 // CHECK: %[[VAL_11:.*]] = quake.extract_ref %{{.*}}[%[[VAL_10]]] : (!quake.veq<10>, i64) -> !quake.ref // CHECK: cc.continue %[[VAL_8]] : i32 // CHECK: } step { @@ -104,7 +104,7 @@ __qpu__ void foo4() { // CHECK: ^bb0(%[[VAL_9:.*]]: i32): // CHECK: %[[VAL_10:.*]] = arith.muli %[[VAL_9]], %[[VAL_3]] : i32 // CHECK: %[[VAL_11:.*]] = arith.subi %[[VAL_0]], %[[VAL_10]] : i32 -// CHECK: %[[VAL_12:.*]] = arith.extsi %[[VAL_11]] : i32 to i64 +// CHECK: %[[VAL_12:.*]] = cc.cast signed %[[VAL_11]] : (i32) -> i64 // CHECK: %[[VAL_13:.*]] = quake.extract_ref %{{.*}}[%[[VAL_12]]] : (!quake.veq<10>, i64) -> !quake.ref // CHECK: ^bb0(%[[VAL_14:.*]]: i32): // CHECK: %[[VAL_15:.*]] = arith.addi %[[VAL_14]], %[[VAL_2]] : i32 @@ -394,7 +394,7 @@ __qpu__ void linear_expr6() { // CHECK: ^bb0(%[[VAL_9:.*]]: i32): // CHECK: %[[VAL_10:.*]] = arith.muli %[[VAL_9]], %[[VAL_2]] : i32 // CHECK: %[[VAL_11:.*]] = arith.addi %[[VAL_10]], %[[VAL_1]] : i32 -// CHECK: %[[VAL_12:.*]] = arith.extsi %[[VAL_11]] : i32 to i64 +// CHECK: %[[VAL_12:.*]] = cc.cast signed %[[VAL_11]] : (i32) -> i64 // CHECK: %[[VAL_13:.*]] = quake.extract_ref %{{.*}}[%[[VAL_12]]] : // CHECK: cc.continue %[[VAL_9]] : i32 // CHECK: } step { diff --git a/test/AST-Quake/mz.cpp b/test/AST-Quake/mz.cpp index 7ac0af4813..015ffa24b8 100644 --- a/test/AST-Quake/mz.cpp +++ b/test/AST-Quake/mz.cpp @@ -69,10 +69,10 @@ struct VectorOfDynamicVeq { // CHECK: cc.store %[[VAL_1]], %[[VAL_3]] : !cc.ptr // CHECK: %[[VAL_4:.*]] = quake.alloca !quake.ref // CHECK: %[[VAL_5:.*]] = cc.load %[[VAL_2]] : !cc.ptr -// CHECK: %[[VAL_6:.*]] = arith.extui %[[VAL_5]] : i32 to i64 +// CHECK: %[[VAL_6:.*]] = cc.cast unsigned %[[VAL_5]] : (i32) -> i64 // CHECK: %[[VAL_7:.*]] = quake.alloca !quake.veq[%[[VAL_6]] : i64] // CHECK: %[[VAL_8:.*]] = cc.load %[[VAL_3]] : !cc.ptr -// CHECK: %[[VAL_9:.*]] = arith.extui %[[VAL_8]] : i32 to i64 +// CHECK: %[[VAL_9:.*]] = cc.cast unsigned %[[VAL_8]] : (i32) -> i64 // CHECK: %[[VAL_10:.*]] = quake.alloca !quake.veq[%[[VAL_9]] : i64] // CHECK: %[[VAL_11:.*]] = quake.alloca !quake.ref // CHECK: %[[VAL_112:.*]] = quake.mz %[[VAL_4]], %[[VAL_7]], %[[VAL_10]], %[[VAL_11]] : (!quake.ref, !quake.veq, !quake.veq, !quake.ref) -> !cc.stdvec diff --git a/test/AST-Quake/operators.cpp b/test/AST-Quake/operators.cpp index 824f530279..4c96315267 100644 --- a/test/AST-Quake/operators.cpp +++ b/test/AST-Quake/operators.cpp @@ -104,22 +104,22 @@ struct short_test { // CHECK: %[[VAL_6:.*]] = cc.alloca i16 // CHECK: cc.store %[[VAL_1]], %[[VAL_6]] : !cc.ptr // CHECK: %[[VAL_7:.*]] = cc.load %[[VAL_5]] : !cc.ptr -// CHECK: %[[VAL_8:.*]] = arith.extsi %[[VAL_7]] : i16 to i32 +// CHECK: %[[VAL_8:.*]] = cc.cast signed %[[VAL_7]] : (i16) -> i32 // CHECK: %[[VAL_9:.*]] = arith.shrsi %[[VAL_8]], %[[VAL_4]] : i32 // CHECK: %[[VAL_10:.*]] = cc.alloca i32 // CHECK: cc.store %[[VAL_9]], %[[VAL_10]] : !cc.ptr // CHECK: %[[VAL_11:.*]] = cc.load %[[VAL_6]] : !cc.ptr -// CHECK: %[[VAL_12:.*]] = arith.extui %[[VAL_11]] : i16 to i32 +// CHECK: %[[VAL_12:.*]] = cc.cast unsigned %[[VAL_11]] : (i16) -> i32 // CHECK: %[[VAL_13:.*]] = arith.shrsi %[[VAL_12]], %[[VAL_4]] : i32 // CHECK: %[[VAL_14:.*]] = cc.alloca i32 // CHECK: cc.store %[[VAL_13]], %[[VAL_14]] : !cc.ptr // CHECK: %[[VAL_15:.*]] = cc.load %[[VAL_5]] : !cc.ptr -// CHECK: %[[VAL_16:.*]] = arith.extsi %[[VAL_15]] : i16 to i32 +// CHECK: %[[VAL_16:.*]] = cc.cast signed %[[VAL_15]] : (i16) -> i32 // CHECK: %[[VAL_17:.*]] = arith.shli %[[VAL_16]], %[[VAL_3]] : i32 // CHECK: %[[VAL_18:.*]] = cc.alloca i32 // CHECK: cc.store %[[VAL_17]], %[[VAL_18]] : !cc.ptr // CHECK: %[[VAL_19:.*]] = cc.load %[[VAL_6]] : !cc.ptr -// CHECK: %[[VAL_20:.*]] = arith.extui %[[VAL_19]] : i16 to i32 +// CHECK: %[[VAL_20:.*]] = cc.cast unsigned %[[VAL_19]] : (i16) -> i32 // CHECK: %[[VAL_21:.*]] = arith.shli %[[VAL_20]], %[[VAL_2]] : i32 // CHECK: %[[VAL_22:.*]] = cc.alloca i32 // CHECK: cc.store %[[VAL_21]], %[[VAL_22]] : !cc.ptr @@ -184,17 +184,17 @@ struct fp_test { // CHECK: %[[VAL_4:.*]] = cc.load %[[VAL_2]] : !cc.ptr // CHECK: %[[VAL_5:.*]] = cc.load %[[VAL_3]] : !cc.ptr // CHECK: %[[VAL_6:.*]] = arith.addf %[[VAL_4]], %[[VAL_5]] : f32 -// CHECK: %[[VAL_7:.*]] = arith.extf %[[VAL_6]] : f32 to f64 +// CHECK: %[[VAL_7:.*]] = cc.cast %[[VAL_6]] : (f32) -> f64 // CHECK: %[[VAL_8:.*]] = cc.alloca f64 // CHECK: cc.store %[[VAL_7]], %[[VAL_8]] : !cc.ptr // CHECK: %[[VAL_9:.*]] = cc.load %[[VAL_2]] : !cc.ptr // CHECK: %[[VAL_10:.*]] = cc.load %[[VAL_3]] : !cc.ptr // CHECK: %[[VAL_11:.*]] = arith.mulf %[[VAL_9]], %[[VAL_10]] : f32 -// CHECK: %[[VAL_12:.*]] = arith.extf %[[VAL_11]] : f32 to f64 +// CHECK: %[[VAL_12:.*]] = cc.cast %[[VAL_11]] : (f32) -> f64 // CHECK: %[[VAL_13:.*]] = cc.alloca f64 // CHECK: cc.store %[[VAL_12]], %[[VAL_13]] : !cc.ptr // CHECK: %[[VAL_14:.*]] = cc.load %[[VAL_2]] : !cc.ptr -// CHECK: %[[VAL_15:.*]] = arith.extf %[[VAL_14]] : f32 to f64 +// CHECK: %[[VAL_15:.*]] = cc.cast %[[VAL_14]] : (f32) -> f64 // CHECK: %[[VAL_16:.*]] = cc.load %[[VAL_13]] : !cc.ptr // CHECK: %[[VAL_17:.*]] = arith.subf %[[VAL_15]], %[[VAL_16]] : f64 // CHECK: %[[VAL_18:.*]] = cc.alloca f64 diff --git a/test/AST-Quake/postfix_ops.cpp b/test/AST-Quake/postfix_ops.cpp index d3328a56d6..ae071098bf 100644 --- a/test/AST-Quake/postfix_ops.cpp +++ b/test/AST-Quake/postfix_ops.cpp @@ -23,28 +23,28 @@ __qpu__ void test(cudaq::qview<> a, cudaq::qview<> b) { // CHECK: %[[VAL_2:.*]] = arith.constant 1 : i64 // CHECK: %[[VAL_3:.*]] = arith.constant 1 : i32 // CHECK: %[[VAL_4:.*]] = quake.veq_size %[[VAL_0]] : (!quake.veq) -> i64 -// CHECK: %[[VAL_5:.*]] = arith.trunci %[[VAL_4]] : i64 to i32 +// CHECK: %[[VAL_5:.*]] = cc.cast %[[VAL_4]] : (i64) -> i32 // CHECK: %[[VAL_6:.*]] = cc.alloca i32 // CHECK: cc.store %[[VAL_5]], %[[VAL_6]] : !cc.ptr // CHECK: cc.loop while { // CHECK: %[[VAL_7:.*]] = cc.load %[[VAL_6]] : !cc.ptr // CHECK: %[[VAL_8:.*]] = arith.subi %[[VAL_7]], %[[VAL_3]] : i32 // CHECK: cc.store %[[VAL_8]], %[[VAL_6]] : !cc.ptr -// CHECK: %[[VAL_9:.*]] = arith.extui %[[VAL_7]] : i32 to i64 +// CHECK: %[[VAL_9:.*]] = cc.cast unsigned %[[VAL_7]] : (i32) -> i64 // CHECK: %[[VAL_10:.*]] = arith.cmpi ugt, %[[VAL_9]], %[[VAL_2]] : i64 // CHECK: cc.condition %[[VAL_10]] // CHECK: } do { // CHECK: %[[VAL_11:.*]] = cc.load %[[VAL_6]] : !cc.ptr -// CHECK: %[[VAL_12:.*]] = arith.extui %[[VAL_11]] : i32 to i64 +// CHECK: %[[VAL_12:.*]] = cc.cast unsigned %[[VAL_11]] : (i32) -> i64 // CHECK: %[[VAL_13:.*]] = arith.subi %[[VAL_12]], %[[VAL_2]] : i64 // CHECK: %[[VAL_14:.*]] = quake.extract_ref %[[VAL_0]]{{\[}}%[[VAL_13]]] : (!quake.veq, i64) -> !quake.ref // CHECK: %[[VAL_15:.*]] = cc.load %[[VAL_6]] : !cc.ptr -// CHECK: %[[VAL_16:.*]] = arith.extui %[[VAL_15]] : i32 to i64 +// CHECK: %[[VAL_16:.*]] = cc.cast unsigned %[[VAL_15]] : (i32) -> i64 // CHECK: %[[VAL_17:.*]] = arith.subi %[[VAL_16]], %[[VAL_2]] : i64 // CHECK: %[[VAL_18:.*]] = quake.extract_ref %[[VAL_1]]{{\[}}%[[VAL_17]]] : (!quake.veq, i64) -> !quake.ref // CHECK: %[[VAL_19:.*]] = cc.load %[[VAL_6]] : !cc.ptr -// CHECK: %[[VAL_20:.*]] = arith.extui %[[VAL_19]] : i32 to i64 -// CHECK: %[[VAL_21:.*]] = quake.extract_ref %[[VAL_0]]{{\[}}%[[VAL_20]]] : (!quake.veq, i64) -> !quake.ref +// CHECK: %[[VAL_20:.*]] = cc.cast unsigned %[[VAL_19]] : (i32) -> i64 +// CHECK: %[[VAL_21:.*]] = quake.extract_ref %[[VAL_0]][%[[VAL_20]]] : (!quake.veq, i64) -> !quake.ref // CHECK: func.call @_Z3umaRN5cudaq5quditILm2EEES2_S2_(%[[VAL_14]], %[[VAL_18]], %[[VAL_21]]) : (!quake.ref, !quake.ref, !quake.ref) -> () // CHECK: cc.continue // CHECK: } diff --git a/test/AST-Quake/qalloc_initialization.cpp b/test/AST-Quake/qalloc_initialization.cpp index acc89080fe..1acc6d31f6 100644 --- a/test/AST-Quake/qalloc_initialization.cpp +++ b/test/AST-Quake/qalloc_initialization.cpp @@ -43,23 +43,24 @@ struct Cherry { // clang-format off // CHECK-LABEL: func.func @__nvqpp__mlirgen__Cherry() -> !cc.stdvec attributes {"cudaq-entrypoint", "cudaq-kernel"} { -// CHECK-DAG: %[[VAL_0:.*]] = arith.constant 1 : i64 -// CHECK-DAG: %[[VAL_3:.*]] = arith.constant 4.000000e-01 : f64 -// CHECK-DAG: %[[VAL_4:.*]] = arith.constant 6.000000e-01 : f64 -// CHECK-DAG: %[[VAL_5:.*]] = arith.constant 0.000000e+00 : f64 -// CHECK-DAG: %[[VAL_6:.*]] = arith.constant 1.000000e+00 : f64 -// CHECK: %[[VAL_7:.*]] = complex.create %[[VAL_5]], %[[VAL_6]] : complex -// CHECK: %[[VAL_8:.*]] = complex.create %[[VAL_4]], %[[VAL_3]] : complex -// CHECK: %[[VAL_9:.*]] = complex.create %[[VAL_6]], %[[VAL_5]] : complex -// CHECK: %[[VAL_10:.*]] = cc.alloca !cc.array x 4> -// CHECK: %[[VAL_11:.*]] = cc.cast %[[VAL_10]] : (!cc.ptr x 4>>) -> !cc.ptr> -// CHECK: cc.store %[[VAL_7]], %[[VAL_11]] : !cc.ptr> -// CHECK: %[[VAL_12:.*]] = cc.compute_ptr %[[VAL_10]][1] : (!cc.ptr x 4>>) -> !cc.ptr> -// CHECK: cc.store %[[VAL_8]], %[[VAL_12]] : !cc.ptr> -// CHECK: %[[VAL_13:.*]] = cc.compute_ptr %[[VAL_10]][2] : (!cc.ptr x 4>>) -> !cc.ptr> -// CHECK: cc.store %[[VAL_9]], %[[VAL_13]] : !cc.ptr> -// CHECK: %[[VAL_14:.*]] = quake.alloca !quake.veq<2> -// CHECK: %[[VAL_15:.*]] = quake.init_state %[[VAL_14]], %[[VAL_10]] : (!quake.veq<2>, !cc.ptr x 4>>) -> !quake.veq<2> +// CHECK-DAG: %[[VAL_0:.*]] = arith.constant 2 : i64 +// CHECK-DAG: %[[VAL_1:.*]] = complex.constant [0.000000e+00, 0.000000e+00] : complex +// CHECK-DAG: %[[VAL_2:.*]] = complex.constant [1.000000e+00, 0.000000e+00] : complex +// CHECK-DAG: %[[VAL_3:.*]] = complex.constant [6.000000e-01, 4.000000e-01] : complex +// CHECK-DAG: %[[VAL_4:.*]] = complex.constant [0.000000e+00, 1.000000e+00] : complex +// CHECK-DAG: %[[VAL_5:.*]] = arith.constant 1 : i64 +// CHECK-DAG: %[[VAL_6:.*]] = arith.constant 0 : i64 +// CHECK-DAG: %[[VAL_7:.*]] = cc.alloca !cc.array x 4> +// CHECK: %[[VAL_8:.*]] = cc.cast %[[VAL_7]] : (!cc.ptr x 4>>) -> !cc.ptr> +// CHECK: cc.store %[[VAL_4]], %[[VAL_8]] : !cc.ptr> +// CHECK: %[[VAL_9:.*]] = cc.compute_ptr %[[VAL_7]][1] : (!cc.ptr x 4>>) -> !cc.ptr> +// CHECK: cc.store %[[VAL_3]], %[[VAL_9]] : !cc.ptr> +// CHECK: %[[VAL_10:.*]] = cc.compute_ptr %[[VAL_7]][2] : (!cc.ptr x 4>>) -> !cc.ptr> +// CHECK: cc.store %[[VAL_2]], %[[VAL_10]] : !cc.ptr> +// CHECK: %[[VAL_11:.*]] = cc.compute_ptr %[[VAL_7]][3] : (!cc.ptr x 4>>) -> !cc.ptr> +// CHECK: cc.store %[[VAL_1]], %[[VAL_11]] : !cc.ptr> +// CHECK: %[[VAL_12:.*]] = quake.alloca !quake.veq<2> +// CHECK: %[[VAL_13:.*]] = quake.init_state %[[VAL_12]], %[[VAL_7]] : (!quake.veq<2>, !cc.ptr x 4>>) -> !quake.veq<2> // clang-format on struct MooseTracks { @@ -75,23 +76,24 @@ struct MooseTracks { // clang-format off // CHECK-LABEL: func.func @__nvqpp__mlirgen__MooseTracks() -> !cc.stdvec attributes {"cudaq-entrypoint", "cudaq-kernel"} { -// CHECK-DAG: %[[VAL_0:.*]] = arith.constant 1 : i64 -// CHECK-DAG: %[[VAL_3:.*]] = arith.constant 2.500000e-01 : f64 -// CHECK-DAG: %[[VAL_4:.*]] = arith.constant 7.500000e-01 : f64 -// CHECK-DAG: %[[VAL_5:.*]] = arith.constant 0.000000e+00 : f64 -// CHECK-DAG: %[[VAL_6:.*]] = arith.constant 1.000000e+00 : f64 -// CHECK: %[[VAL_7:.*]] = complex.create %[[VAL_5]], %[[VAL_6]] : complex -// CHECK: %[[VAL_8:.*]] = complex.create %[[VAL_4]], %[[VAL_3]] : complex -// CHECK: %[[VAL_9:.*]] = complex.create %[[VAL_6]], %[[VAL_5]] : complex -// CHECK: %[[VAL_10:.*]] = cc.alloca !cc.array x 4> -// CHECK: %[[VAL_11:.*]] = cc.cast %[[VAL_10]] : (!cc.ptr x 4>>) -> !cc.ptr> -// CHECK: cc.store %[[VAL_7]], %[[VAL_11]] : !cc.ptr> -// CHECK: %[[VAL_12:.*]] = cc.compute_ptr %[[VAL_10]][1] : (!cc.ptr x 4>>) -> !cc.ptr> -// CHECK: cc.store %[[VAL_8]], %[[VAL_12]] : !cc.ptr> -// CHECK: %[[VAL_13:.*]] = cc.compute_ptr %[[VAL_10]][2] : (!cc.ptr x 4>>) -> !cc.ptr> -// CHECK: cc.store %[[VAL_9]], %[[VAL_13]] : !cc.ptr> -// CHECK: %[[VAL_14:.*]] = quake.alloca !quake.veq<2> -// CHECK: %[[VAL_15:.*]] = quake.init_state %[[VAL_14]], %[[VAL_10]] : (!quake.veq<2>, !cc.ptr x 4>>) -> !quake.veq<2> +// CHECK-DAG: %[[VAL_0:.*]] = arith.constant 2 : i64 +// CHECK-DAG: %[[VAL_1:.*]] = complex.constant [0.000000e+00, 0.000000e+00] : complex +// CHECK-DAG: %[[VAL_2:.*]] = complex.constant [1.000000e+00, 0.000000e+00] : complex +// CHECK-DAG: %[[VAL_3:.*]] = complex.constant [7.500000e-01, 2.500000e-01] : complex +// CHECK-DAG: %[[VAL_4:.*]] = complex.constant [0.000000e+00, 1.000000e+00] : complex +// CHECK-DAG: %[[VAL_5:.*]] = arith.constant 1 : i64 +// CHECK-DAG: %[[VAL_6:.*]] = arith.constant 0 : i64 +// CHECK-DAG: %[[VAL_7:.*]] = cc.alloca !cc.array x 4> +// CHECK: %[[VAL_8:.*]] = cc.cast %[[VAL_7]] : (!cc.ptr x 4>>) -> !cc.ptr> +// CHECK: cc.store %[[VAL_4]], %[[VAL_8]] : !cc.ptr> +// CHECK: %[[VAL_9:.*]] = cc.compute_ptr %[[VAL_7]][1] : (!cc.ptr x 4>>) -> !cc.ptr> +// CHECK: cc.store %[[VAL_3]], %[[VAL_9]] : !cc.ptr> +// CHECK: %[[VAL_10:.*]] = cc.compute_ptr %[[VAL_7]][2] : (!cc.ptr x 4>>) -> !cc.ptr> +// CHECK: cc.store %[[VAL_2]], %[[VAL_10]] : !cc.ptr> +// CHECK: %[[VAL_11:.*]] = cc.compute_ptr %[[VAL_7]][3] : (!cc.ptr x 4>>) -> !cc.ptr> +// CHECK: cc.store %[[VAL_1]], %[[VAL_11]] : !cc.ptr> +// CHECK: %[[VAL_12:.*]] = quake.alloca !quake.veq<2> +// CHECK: %[[VAL_13:.*]] = quake.init_state %[[VAL_12]], %[[VAL_7]] : (!quake.veq<2>, !cc.ptr x 4>>) -> !quake.veq<2> // clang-format on struct RockyRoad { @@ -106,35 +108,38 @@ struct RockyRoad { // clang-format off // CHECK-LABEL: func.func @__nvqpp__mlirgen__RockyRoad() -> !cc.stdvec attributes {"cudaq-entrypoint", "cudaq-kernel"} { -// CHECK-DAG: %[[VAL_0:.*]] = arith.constant 1 : i64 -// CHECK-DAG: %[[VAL_3:.*]] = arith.constant 0.000000e+00 : f{{[1280]+}} -// CHECK-DAG: %[[VAL_4:.*]] = arith.constant 1.000000e+00 : f64 -// CHECK-DAG: %[[VAL_5:.*]] = arith.constant 2.000000e-01 : f64 -// CHECK-DAG: %[[VAL_6:.*]] = arith.constant 8.000000e-01 : f64 -// CHECK-DAG: %[[VAL_7:.*]] = arith.constant 1.000000e+00 : f{{[1280]+}} +// CHECK-DAG: %[[VAL_0:.*]] = arith.constant 2 : i64 +// CHECK-DAG: %[[VAL_1:.*]] = complex.constant [0.000000e+00, 0.000000e+00] : complex +// CHECK-DAG: %[[VAL_2:.*]] = complex.constant [8.000000e-01, 2.000000e-01] : complex +// CHECK-DAG: %[[VAL_3:.*]] = arith.constant 1 : i64 +// CHECK-DAG: %[[VAL_4:.*]] = arith.constant 0 : i64 +// CHECK-DAG: %[[VAL_5:.*]] = arith.constant 0.000000e+00 : f{{[0-9]+}} +// CHECK-DAG: %[[VAL_6:.*]] = arith.constant 1.000000e+00 : f64 +// CHECK-DAG: %[[VAL_7:.*]] = arith.constant 1.000000e+00 : f{{[0-9]+}} // CHECK-DAG: %[[VAL_8:.*]] = arith.constant 0.000000e+00 : f64 // CHECK-DAG: %[[VAL_9:.*]] = cc.alloca f64 // CHECK: cc.store %[[VAL_8]], %[[VAL_9]] : !cc.ptr -// CHECK: %[[VAL_10:.*]] = call @_ZNSt8literals16complex_literalsli1iEe(%[[VAL_7]]) : (f{{[1280]+}}) -> complex +// CHECK: %[[VAL_10:.*]] = call @_ZNSt8literals16complex_literalsli1iEe(%[[VAL_7]]) : (f{{[0-9]+}}) -> complex // CHECK: %[[VAL_11:.*]] = cc.alloca complex // CHECK: cc.store %[[VAL_10]], %[[VAL_11]] : !cc.ptr> // CHECK: %[[VAL_12:.*]] = call @_ZStplIdESt7complexIT_ERKS1_RKS2_(%[[VAL_9]], %[[VAL_11]]) : (!cc.ptr, !cc.ptr>) -> complex -// CHECK: %[[VAL_13:.*]] = complex.create %[[VAL_6]], %[[VAL_5]] : complex -// CHECK: %[[VAL_14:.*]] = cc.alloca f64 -// CHECK: cc.store %[[VAL_4]], %[[VAL_14]] : !cc.ptr -// CHECK: %[[VAL_15:.*]] = call @_ZNSt8literals16complex_literalsli1iEe(%[[VAL_3]]) : (f{{[1280]+}}) -> complex -// CHECK: %[[VAL_16:.*]] = cc.alloca complex -// CHECK: cc.store %[[VAL_15]], %[[VAL_16]] : !cc.ptr> -// CHECK: %[[VAL_17:.*]] = call @_ZStplIdESt7complexIT_ERKS1_RKS2_(%[[VAL_14]], %[[VAL_16]]) : (!cc.ptr, !cc.ptr>) -> complex -// CHECK: %[[VAL_18:.*]] = cc.alloca !cc.array x 4> -// CHECK: %[[VAL_19:.*]] = cc.cast %[[VAL_18]] : (!cc.ptr x 4>>) -> !cc.ptr> -// CHECK: cc.store %[[VAL_12]], %[[VAL_19]] : !cc.ptr> -// CHECK: %[[VAL_20:.*]] = cc.compute_ptr %[[VAL_18]][1] : (!cc.ptr x 4>>) -> !cc.ptr> -// CHECK: cc.store %[[VAL_13]], %[[VAL_20]] : !cc.ptr> -// CHECK: %[[VAL_21:.*]] = cc.compute_ptr %[[VAL_18]][2] : (!cc.ptr x 4>>) -> !cc.ptr> -// CHECK: cc.store %[[VAL_17]], %[[VAL_21]] : !cc.ptr> +// CHECK: %[[VAL_13:.*]] = cc.alloca f64 +// CHECK: cc.store %[[VAL_6]], %[[VAL_13]] : !cc.ptr +// CHECK: %[[VAL_14:.*]] = call @_ZNSt8literals16complex_literalsli1iEe(%[[VAL_5]]) : (f{{[0-9]+}}) -> complex +// CHECK: %[[VAL_15:.*]] = cc.alloca complex +// CHECK: cc.store %[[VAL_14]], %[[VAL_15]] : !cc.ptr> +// CHECK: %[[VAL_16:.*]] = call @_ZStplIdESt7complexIT_ERKS1_RKS2_(%[[VAL_13]], %[[VAL_15]]) : (!cc.ptr, !cc.ptr>) -> complex +// CHECK: %[[VAL_17:.*]] = cc.alloca !cc.array x 4> +// CHECK: %[[VAL_18:.*]] = cc.cast %[[VAL_17]] : (!cc.ptr x 4>>) -> !cc.ptr> +// CHECK: cc.store %[[VAL_12]], %[[VAL_18]] : !cc.ptr> +// CHECK: %[[VAL_19:.*]] = cc.compute_ptr %[[VAL_17]][1] : (!cc.ptr x 4>>) -> !cc.ptr> +// CHECK: cc.store %[[VAL_2]], %[[VAL_19]] : !cc.ptr> +// CHECK: %[[VAL_20:.*]] = cc.compute_ptr %[[VAL_17]][2] : (!cc.ptr x 4>>) -> !cc.ptr> +// CHECK: cc.store %[[VAL_16]], %[[VAL_20]] : !cc.ptr> +// CHECK: %[[VAL_21:.*]] = cc.compute_ptr %[[VAL_17]][3] : (!cc.ptr x 4>>) -> !cc.ptr> +// CHECK: cc.store %[[VAL_1]], %[[VAL_21]] : !cc.ptr> // CHECK: %[[VAL_22:.*]] = quake.alloca !quake.veq<2> -// CHECK: %[[VAL_23:.*]] = quake.init_state %[[VAL_22]], %[[VAL_18]] : (!quake.veq<2>, !cc.ptr x 4>>) -> !quake.veq<2> +// CHECK: %[[VAL_23:.*]] = quake.init_state %[[VAL_22]], %[[VAL_17]] : (!quake.veq<2>, !cc.ptr x 4>>) -> !quake.veq<2> // clang-format on std::vector getTwoTimesRank(); @@ -220,21 +225,19 @@ __qpu__ auto Strawberry() { // clang-format off // CHECK-LABEL: func.func @__nvqpp__mlirgen__function_Strawberry._Z10Strawberryv() -> i1 attributes {"cudaq-entrypoint", "cudaq-kernel", no_this} { -// CHECK: %[[VAL_0:.*]] = arith.constant 1.000000e+00 : f64 -// CHECK: %[[VAL_1:.*]] = arith.constant 0.000000e+00 : f64 -// CHECK: %[[VAL_2:.*]] = complex.create %[[VAL_1]], %[[VAL_1]] : complex -// CHECK: %[[VAL_3:.*]] = complex.create %[[VAL_0]], %[[VAL_1]] : complex -// CHECK: %[[VAL_4:.*]] = cc.alloca !cc.array x 2> -// CHECK: %[[VAL_5:.*]] = cc.cast %[[VAL_4]] : (!cc.ptr x 2>>) -> !cc.ptr> -// CHECK: cc.store %[[VAL_2]], %[[VAL_5]] : !cc.ptr> -// CHECK: %[[VAL_6:.*]] = cc.compute_ptr %[[VAL_4]][1] : (!cc.ptr x 2>>) -> !cc.ptr> -// CHECK: cc.store %[[VAL_3]], %[[VAL_6]] : !cc.ptr> -// CHECK: %[[VAL_7:.*]] = quake.alloca !quake.veq<1> -// CHECK: %[[VAL_8:.*]] = quake.init_state %[[VAL_7]], %[[VAL_4]] : (!quake.veq<1>, !cc.ptr x 2>>) -> !quake.veq<1> -// CHECK: %[[VAL_9:.*]] = quake.extract_ref %[[VAL_8]][0] : (!quake.veq<1>) -> !quake.ref -// CHECK: %[[VAL_10:.*]] = quake.mz %[[VAL_9]] : (!quake.ref) -> !quake.measure -// CHECK: %[[VAL_11:.*]] = quake.discriminate %[[VAL_10]] : (!quake.measure) -> i1 -// CHECK: return %[[VAL_11]] : i1 +// CHECK: %[[VAL_0:.*]] = complex.constant [1.000000e+00, 0.000000e+00] : complex +// CHECK: %[[VAL_1:.*]] = complex.constant [0.000000e+00, 0.000000e+00] : complex +// CHECK: %[[VAL_2:.*]] = cc.alloca !cc.array x 2> +// CHECK: %[[VAL_3:.*]] = cc.cast %[[VAL_2]] : (!cc.ptr x 2>>) -> !cc.ptr> +// CHECK: cc.store %[[VAL_1]], %[[VAL_3]] : !cc.ptr> +// CHECK: %[[VAL_4:.*]] = cc.compute_ptr %[[VAL_2]][1] : (!cc.ptr x 2>>) -> !cc.ptr> +// CHECK: cc.store %[[VAL_0]], %[[VAL_4]] : !cc.ptr> +// CHECK: %[[VAL_5:.*]] = quake.alloca !quake.veq<1> +// CHECK: %[[VAL_6:.*]] = quake.init_state %[[VAL_5]], %[[VAL_2]] : (!quake.veq<1>, !cc.ptr x 2>>) -> !quake.veq<1> +// CHECK: %[[VAL_7:.*]] = quake.extract_ref %[[VAL_6]][0] : (!quake.veq<1>) -> !quake.ref +// CHECK: %[[VAL_8:.*]] = quake.mz %[[VAL_7]] : (!quake.ref) -> !quake.measure +// CHECK: %[[VAL_9:.*]] = quake.discriminate %[[VAL_8]] : (!quake.measure) -> i1 +// CHECK: return %[[VAL_9]] : i1 // CHECK: } // clang-format on @@ -253,21 +256,18 @@ __qpu__ bool Peppermint() { // clang-format off // CHECK-LABEL: func.func @__nvqpp__mlirgen__function_Peppermint._Z10Peppermintv() -> i1 attributes {"cudaq-entrypoint", "cudaq-kernel", no_this} { -// CHECK: %[[VAL_0:.*]] = arith.constant 0.70710678118654757 : f64 -// CHECK: %[[VAL_1:.*]] = arith.constant 0.000000e+00 : f64 -// CHECK: %[[VAL_2:.*]] = complex.create %[[VAL_0]], %[[VAL_1]] : complex -// CHECK: %[[VAL_3:.*]] = complex.create %[[VAL_0]], %[[VAL_1]] : complex -// CHECK: %[[VAL_4:.*]] = cc.alloca !cc.array x 2> -// CHECK: %[[VAL_5:.*]] = cc.cast %[[VAL_4]] : (!cc.ptr x 2>>) -> !cc.ptr> -// CHECK: cc.store %[[VAL_2]], %[[VAL_5]] : !cc.ptr> -// CHECK: %[[VAL_6:.*]] = cc.compute_ptr %[[VAL_4]][1] : (!cc.ptr x 2>>) -> !cc.ptr> -// CHECK: cc.store %[[VAL_3]], %[[VAL_6]] : !cc.ptr> -// CHECK: %[[VAL_7:.*]] = quake.alloca !quake.veq<1> -// CHECK: %[[VAL_8:.*]] = quake.init_state %[[VAL_7]], %[[VAL_4]] : (!quake.veq<1>, !cc.ptr x 2>>) -> !quake.veq<1> -// CHECK: %[[VAL_9:.*]] = quake.extract_ref %[[VAL_8]][0] : (!quake.veq<1>) -> !quake.ref -// CHECK: %[[VAL_10:.*]] = quake.mz %[[VAL_9]] : (!quake.ref) -> !quake.measure -// CHECK: %[[VAL_11:.*]] = quake.discriminate %[[VAL_10]] : (!quake.measure) -> i1 -// CHECK: return %[[VAL_11]] : i1 +// CHECK: %[[VAL_0:.*]] = complex.constant [0.70710678118654757, 0.000000e+00] : complex +// CHECK: %[[VAL_1:.*]] = cc.alloca !cc.array x 2> +// CHECK: %[[VAL_2:.*]] = cc.cast %[[VAL_1]] : (!cc.ptr x 2>>) -> !cc.ptr> +// CHECK: cc.store %[[VAL_0]], %[[VAL_2]] : !cc.ptr> +// CHECK: %[[VAL_3:.*]] = cc.compute_ptr %[[VAL_1]][1] : (!cc.ptr x 2>>) -> !cc.ptr> +// CHECK: cc.store %[[VAL_0]], %[[VAL_3]] : !cc.ptr> +// CHECK: %[[VAL_4:.*]] = quake.alloca !quake.veq<1> +// CHECK: %[[VAL_5:.*]] = quake.init_state %[[VAL_4]], %[[VAL_1]] : (!quake.veq<1>, !cc.ptr x 2>>) -> !quake.veq<1> +// CHECK: %[[VAL_6:.*]] = quake.extract_ref %[[VAL_5]][0] : (!quake.veq<1>) -> !quake.ref +// CHECK: %[[VAL_7:.*]] = quake.mz %[[VAL_6]] : (!quake.ref) -> !quake.measure +// CHECK: %[[VAL_8:.*]] = quake.discriminate %[[VAL_7]] : (!quake.measure) -> i1 +// CHECK: return %[[VAL_8]] : i1 // CHECK: } // clang-format on diff --git a/test/AST-Quake/qpe.cpp b/test/AST-Quake/qpe.cpp index e2d41d8aad..c6b210f734 100644 --- a/test/AST-Quake/qpe.cpp +++ b/test/AST-Quake/qpe.cpp @@ -110,7 +110,7 @@ int main() { // CHECK-DAG: %[[VAL_4:.*]] = arith.constant 2 : i32 // CHECK-DAG: %[[VAL_5:.*]] = arith.constant 0 : i32 // CHECK: %[[VAL_6:.*]] = quake.veq_size %[[VAL_0]] : (!quake.veq) -> i64 -// CHECK: %[[VAL_7:.*]] = arith.trunci %[[VAL_6]] : i64 to i32 +// CHECK: %[[VAL_7:.*]] = cc.cast %[[VAL_6]] : (i64) -> i32 // CHECK: %[[VAL_8:.*]] = cc.alloca i32 // CHECK: cc.store %[[VAL_7]], %[[VAL_8]] : !cc.ptr // CHECK: cc.scope { @@ -124,13 +124,13 @@ int main() { // CHECK: cc.condition %[[VAL_13]] // CHECK: } do { // CHECK: %[[VAL_14:.*]] = cc.load %[[VAL_9]] : !cc.ptr -// CHECK: %[[VAL_15:.*]] = arith.extsi %[[VAL_14]] : i32 to i64 -// CHECK: %[[VAL_16:.*]] = quake.extract_ref %[[VAL_0]]{{\[}}%[[VAL_15]]] : (!quake.veq, i64) -> !quake.ref +// CHECK: %[[VAL_15:.*]] = cc.cast signed %[[VAL_14]] : (i32) -> i64 +// CHECK: %[[VAL_16:.*]] = quake.extract_ref %[[VAL_0]][%[[VAL_15]]] : (!quake.veq, i64) -> !quake.ref // CHECK: %[[VAL_17:.*]] = cc.load %[[VAL_8]] : !cc.ptr // CHECK: %[[VAL_18:.*]] = cc.load %[[VAL_9]] : !cc.ptr // CHECK: %[[VAL_19:.*]] = arith.subi %[[VAL_17]], %[[VAL_18]] : i32 // CHECK: %[[VAL_20:.*]] = arith.subi %[[VAL_19]], %[[VAL_3]] : i32 -// CHECK: %[[VAL_21:.*]] = arith.extsi %[[VAL_20]] : i32 to i64 +// CHECK: %[[VAL_21:.*]] = cc.cast signed %[[VAL_20]] : (i32) -> i64 // CHECK: %[[VAL_22:.*]] = quake.extract_ref %[[VAL_0]]{{\[}}%[[VAL_21]]] : (!quake.veq, i64) -> !quake.ref // CHECK: quake.swap %[[VAL_16]], %[[VAL_22]] : (!quake.ref, !quake.ref) -> () // CHECK: cc.continue @@ -152,7 +152,7 @@ int main() { // CHECK: } do { // CHECK: cc.scope { // CHECK: %[[VAL_30:.*]] = cc.load %[[VAL_25]] : !cc.ptr -// CHECK: %[[VAL_31:.*]] = arith.extsi %[[VAL_30]] : i32 to i64 +// CHECK: %[[VAL_31:.*]] = cc.cast signed %[[VAL_30]] : (i32) -> i64 // CHECK: %[[VAL_32:.*]] = quake.extract_ref %[[VAL_0]]{{\[}}%[[VAL_31]]] : (!quake.veq, i64) -> !quake.ref // CHECK: quake.h %[[VAL_32]] : (!quake.ref) -> () // CHECK: %[[VAL_33:.*]] = cc.load %[[VAL_25]] : !cc.ptr @@ -178,10 +178,10 @@ int main() { // CHECK: cc.store %[[VAL_44]], %[[VAL_45]] : !cc.ptr // CHECK: %[[VAL_46:.*]] = cc.load %[[VAL_45]] : !cc.ptr // CHECK: %[[VAL_47:.*]] = cc.load %[[VAL_35]] : !cc.ptr -// CHECK: %[[VAL_48:.*]] = arith.extsi %[[VAL_47]] : i32 to i64 +// CHECK: %[[VAL_48:.*]] = cc.cast signed %[[VAL_47]] : (i32) -> i64 // CHECK: %[[VAL_49:.*]] = quake.extract_ref %[[VAL_0]]{{\[}}%[[VAL_48]]] : (!quake.veq, i64) -> !quake.ref // CHECK: %[[VAL_50:.*]] = cc.load %[[VAL_37]] : !cc.ptr -// CHECK: %[[VAL_51:.*]] = arith.extsi %[[VAL_50]] : i32 to i64 +// CHECK: %[[VAL_51:.*]] = cc.cast signed %[[VAL_50]] : (i32) -> i64 // CHECK: %[[VAL_52:.*]] = quake.extract_ref %[[VAL_0]]{{\[}}%[[VAL_51]]] : (!quake.veq, i64) -> !quake.ref // CHECK: quake.r1 (%[[VAL_46]]) {{\[}}%[[VAL_49]]] %[[VAL_52]] : (f64, !quake.ref, !quake.ref) -> () // CHECK: } @@ -202,7 +202,7 @@ int main() { // CHECK: } // CHECK: %[[VAL_57:.*]] = cc.load %[[VAL_8]] : !cc.ptr // CHECK: %[[VAL_58:.*]] = arith.subi %[[VAL_57]], %[[VAL_3]] : i32 -// CHECK: %[[VAL_59:.*]] = arith.extsi %[[VAL_58]] : i32 to i64 +// CHECK: %[[VAL_59:.*]] = cc.cast signed %[[VAL_58]] : (i32) -> i64 // CHECK: %[[VAL_60:.*]] = quake.extract_ref %[[VAL_0]]{{\[}}%[[VAL_59]]] : (!quake.veq, i64) -> !quake.ref // CHECK: quake.h %[[VAL_60]] : (!quake.ref) -> () // CHECK: return @@ -263,14 +263,14 @@ int main() { // CHECK: %[[VAL_12:.*]] = cc.load %[[VAL_10]] : !cc.ptr // CHECK: %[[VAL_13:.*]] = cc.load %[[VAL_11]] : !cc.ptr // CHECK: %[[VAL_14:.*]] = arith.addi %[[VAL_12]], %[[VAL_13]] : i32 -// CHECK: %[[VAL_15:.*]] = arith.extsi %[[VAL_14]] : i32 to i64 +// CHECK: %[[VAL_15:.*]] = cc.cast signed %[[VAL_14]] : (i32) -> i64 // CHECK: %[[VAL_16:.*]] = quake.alloca !quake.veq{{\[}}%[[VAL_15]] : i64] // CHECK: %[[VAL_17:.*]] = cc.load %[[VAL_10]] : !cc.ptr -// CHECK: %[[VAL_18:.*]] = arith.extsi %[[VAL_17]] : i32 to i64 +// CHECK: %[[VAL_18:.*]] = cc.cast signed %[[VAL_17]] : (i32) -> i64 // CHECK: %[[VAL_19:.*]] = arith.subi %[[VAL_18]], %[[VAL_6]] : i64 // CHECK: %[[VAL_20:.*]] = quake.subveq %[[VAL_16]], %[[VAL_7]], %[[VAL_19]] : (!quake.veq, i64, i64) -> !quake.veq // CHECK: %[[VAL_21:.*]] = cc.load %[[VAL_11]] : !cc.ptr -// CHECK: %[[VAL_22:.*]] = arith.extsi %[[VAL_21]] : i32 to i64 +// CHECK: %[[VAL_22:.*]] = cc.cast signed %[[VAL_21]] : (i32) -> i64 // CHECK: %[[VAL_23:.*]] = quake.veq_size %[[VAL_16]] : (!quake.veq) -> i64 // CHECK: %[[VAL_24:.*]] = arith.subi %[[VAL_23]], %[[VAL_6]] : i64 // CHECK: %[[VAL_25:.*]] = arith.subi %[[VAL_23]], %[[VAL_22]] : i64 @@ -305,15 +305,15 @@ int main() { // CHECK: cc.store %[[VAL_5]], %[[VAL_40]] : !cc.ptr // CHECK: cc.loop while { // CHECK: %[[VAL_41:.*]] = cc.load %[[VAL_40]] : !cc.ptr -// CHECK: %[[VAL_42:.*]] = arith.extsi %[[VAL_41]] : i32 to i64 +// CHECK: %[[VAL_42:.*]] = cc.cast signed %[[VAL_41]] : (i32) -> i64 // CHECK: %[[VAL_43:.*]] = cc.load %[[VAL_36]] : !cc.ptr -// CHECK: %[[VAL_44:.*]] = arith.extsi %[[VAL_43]] : i32 to i64 +// CHECK: %[[VAL_44:.*]] = cc.cast signed %[[VAL_43]] : (i32) -> i64 // CHECK: %[[VAL_45:.*]] = arith.shli %[[VAL_6]], %[[VAL_44]] : i64 // CHECK: %[[VAL_46:.*]] = arith.cmpi ult, %[[VAL_42]], %[[VAL_45]] : i64 // CHECK: cc.condition %[[VAL_46]] // CHECK: } do { // CHECK: %[[VAL_47:.*]] = cc.load %[[VAL_36]] : !cc.ptr -// CHECK: %[[VAL_48:.*]] = arith.extsi %[[VAL_47]] : i32 to i64 +// CHECK: %[[VAL_48:.*]] = cc.cast signed %[[VAL_47]] : (i32) -> i64 // CHECK: %[[VAL_49:.*]] = quake.extract_ref %[[VAL_20]]{{\[}}%[[VAL_48]]] : (!quake.veq, i64) -> !quake.ref // CHECK: quake.apply @__nvqpp__mlirgen__tgate [%[[VAL_49]]] %[[VAL_26]] : (!quake.ref, !quake.veq) -> () // CHECK: cc.continue diff --git a/test/AST-Quake/ranged_for.cpp b/test/AST-Quake/ranged_for.cpp index d96092a858..f71cb617ba 100644 --- a/test/AST-Quake/ranged_for.cpp +++ b/test/AST-Quake/ranged_for.cpp @@ -252,7 +252,7 @@ struct Nesting { // CHECK: %[[VAL_24:.*]] = cc.compute_ptr %[[VAL_17]]{{\[}}%[[VAL_22]]] : (!cc.ptr>, i64) -> !cc.ptr // CHECK-DAG: %[[VAL_25:.*]] = cc.load %[[VAL_15]] : !cc.ptr // CHECK-DAG: %[[VAL_26:.*]] = cc.load %[[VAL_24]] : !cc.ptr -// CHECK: %[[VAL_27:.*]] = arith.extf %[[VAL_26]] : f32 to f64 +// CHECK: %[[VAL_27:.*]] = cc.cast %[[VAL_26]] : (f32) -> f64 // CHECK: %[[VAL_28:.*]] = arith.mulf %[[VAL_25]], %[[VAL_27]] : f64 // CHECK: %[[VAL_29:.*]] = cc.load %[[VAL_6]] : !cc.ptr // CHECK: %[[VAL_30:.*]] = arith.addf %[[VAL_29]], %[[VAL_28]] : f64 diff --git a/test/AST-Quake/simple.cpp b/test/AST-Quake/simple.cpp index cbe4903037..41f4fcf457 100644 --- a/test/AST-Quake/simple.cpp +++ b/test/AST-Quake/simple.cpp @@ -33,7 +33,7 @@ struct ghz { // CHECK: %[[VAL_3:.*]] = cc.alloca i32 // CHECK: cc.store %[[VAL_0]], %[[VAL_3]] : !cc.ptr // CHECK: %[[VAL_4:.*]] = cc.load %[[VAL_3]] : !cc.ptr -// CHECK: %[[VAL_5:.*]] = arith.extsi %[[VAL_4]] : i32 to i64 +// CHECK: %[[VAL_5:.*]] = cc.cast signed %[[VAL_4]] : (i32) -> i64 // CHECK: %[[VAL_6:.*]] = quake.alloca !quake.veq[%[[VAL_5]] : i64] // CHECK: %[[VAL_7:.*]] = quake.extract_ref %[[VAL_6]][0] : (!quake.veq) -> !quake.ref // CHECK: quake.h %[[VAL_7]] : (!quake.ref) -> () @@ -48,11 +48,11 @@ struct ghz { // CHECK: cc.condition %[[VAL_12]] // CHECK: } do { // CHECK: %[[VAL_13:.*]] = cc.load %[[VAL_8]] : !cc.ptr -// CHECK: %[[VAL_14:.*]] = arith.extsi %[[VAL_13]] : i32 to i64 +// CHECK: %[[VAL_14:.*]] = cc.cast signed %[[VAL_13]] : (i32) -> i64 // CHECK: %[[VAL_15:.*]] = quake.extract_ref %[[VAL_6]][%[[VAL_14]]] : (!quake.veq, i64) -> !quake.ref // CHECK: %[[VAL_16:.*]] = cc.load %[[VAL_8]] : !cc.ptr // CHECK: %[[VAL_17:.*]] = arith.addi %[[VAL_16]], %[[VAL_1]] : i32 -// CHECK: %[[VAL_18:.*]] = arith.extsi %[[VAL_17]] : i32 to i64 +// CHECK: %[[VAL_18:.*]] = cc.cast signed %[[VAL_17]] : (i32) -> i64 // CHECK: %[[VAL_19:.*]] = quake.extract_ref %[[VAL_6]][%[[VAL_18]]] : (!quake.veq, i64) -> !quake.ref // CHECK: quake.x [%[[VAL_15]]] %[[VAL_19]] : (!quake.ref, !quake.ref) -> () // CHECK: cc.continue diff --git a/test/AST-Quake/simple_qarray.cpp b/test/AST-Quake/simple_qarray.cpp index 95e55a78a2..32776a8ae2 100644 --- a/test/AST-Quake/simple_qarray.cpp +++ b/test/AST-Quake/simple_qarray.cpp @@ -61,11 +61,11 @@ int main() { // CHECK: cc.condition %[[VAL_7]] // CHECK: } do { // CHECK: %[[VAL_8:.*]] = cc.load %[[VAL_5]] : !cc.ptr -// CHECK: %[[VAL_9:.*]] = arith.extsi %[[VAL_8]] : i32 to i64 +// CHECK: %[[VAL_9:.*]] = cc.cast signed %[[VAL_8]] : (i32) -> i64 // CHECK: %[[VAL_10:.*]] = quake.extract_ref %[[VAL_3]][%[[VAL_9]]] : (!quake.veq<5>, i64) -> !quake.ref // CHECK: %[[VAL_11:.*]] = cc.load %[[VAL_5]] : !cc.ptr // CHECK: %[[VAL_12:.*]] = arith.addi %[[VAL_11]], %[[VAL_0]] : i32 -// CHECK: %[[VAL_13:.*]] = arith.extsi %[[VAL_12]] : i32 to i64 +// CHECK: %[[VAL_13:.*]] = cc.cast signed %[[VAL_12]] : (i32) -> i64 // CHECK: %[[VAL_14:.*]] = quake.extract_ref %[[VAL_3]][%[[VAL_13]]] : (!quake.veq<5>, i64) -> !quake.ref // CHECK: quake.x [%[[VAL_10]]] %[[VAL_14]] : (!quake.ref, !quake.ref) -> () // CHECK: cc.continue diff --git a/test/AST-Quake/struct-1.cpp b/test/AST-Quake/struct-1.cpp index 7feea4e9f8..1164e59e2c 100644 --- a/test/AST-Quake/struct-1.cpp +++ b/test/AST-Quake/struct-1.cpp @@ -293,12 +293,12 @@ struct S6 { // CHECK: %[[VAL_16:.*]] = cc.compute_ptr %[[VAL_3]][1] : (!cc.ptr>) -> !cc.ptr // CHECK: %[[VAL_17:.*]] = cc.load %[[VAL_16]] : !cc.ptr // CHECK: %[[VAL_18:.*]] = arith.cmpi sgt, %[[VAL_17]], %[[VAL_1]] : i32 -// CHECK: %[[VAL_19:.*]] = arith.extui %[[VAL_18]] : i1 to i16 +// CHECK: %[[VAL_19:.*]] = cc.cast unsigned %[[VAL_18]] : (i1) -> i16 // CHECK: cc.store %[[VAL_19]], %[[VAL_15]] : !cc.ptr // CHECK: %[[VAL_20:.*]] = cc.compute_ptr %[[VAL_10]][3] : (!cc.ptr>) -> !cc.ptr // CHECK: %[[VAL_21:.*]] = cc.compute_ptr %[[VAL_3]][2] : (!cc.ptr>) -> !cc.ptr // CHECK: %[[VAL_22:.*]] = cc.load %[[VAL_21]] : !cc.ptr -// CHECK: %[[VAL_23:.*]] = arith.fptosi %[[VAL_22]] : f64 to i32 +// CHECK: %[[VAL_23:.*]] = cc.cast signed %[[VAL_22]] : (f64) -> i32 // CHECK: cc.store %[[VAL_23]], %[[VAL_20]] : !cc.ptr // CHECK: %[[VAL_24:.*]] = cc.compute_ptr %[[VAL_10]][1] : (!cc.ptr>) -> !cc.ptr // CHECK: %[[VAL_25:.*]] = cc.cast %[[VAL_3]] : (!cc.ptr>) -> !cc.ptr diff --git a/test/AST-Quake/tuple-0.cpp b/test/AST-Quake/tuple-0.cpp index d257718aee..6074053019 100644 --- a/test/AST-Quake/tuple-0.cpp +++ b/test/AST-Quake/tuple-0.cpp @@ -63,15 +63,15 @@ struct ArithmeticTupleQernelWithUse { // CHECK: cc.store %[[VAL_0]], %[[VAL_3]] : !cc.ptr> // CHECK: %[[VAL_4:.*]] = cc.cast %[[VAL_3]] : (!cc.ptr>) -> !cc.ptr // CHECK: %[[VAL_5:.*]] = cc.load %[[VAL_4]] : !cc.ptr -// CHECK: %[[VAL_6:.*]] = arith.extsi %[[VAL_5]] : i32 to i64 -// CHECK: %[[VAL_7:.*]] = quake.alloca !quake.veq{{\[}}%[[VAL_6]] : i64] +// CHECK: %[[VAL_6:.*]] = cc.cast signed %[[VAL_5]] : (i32) -> i64 +// CHECK: %[[VAL_7:.*]] = quake.alloca !quake.veq[%[[VAL_6]] : i64] // CHECK: %[[VAL_8:.*]] = quake.veq_size %[[VAL_7]] : (!quake.veq) -> i64 // CHECK: %[[VAL_9:.*]] = cc.loop while ((%[[VAL_10:.*]] = %[[VAL_2]]) -> (i64)) { // CHECK: %[[VAL_11:.*]] = arith.cmpi slt, %[[VAL_10]], %[[VAL_8]] : i64 // CHECK: cc.condition %[[VAL_11]](%[[VAL_10]] : i64) // CHECK: } do { // CHECK: ^bb0(%[[VAL_12:.*]]: i64): -// CHECK: %[[VAL_13:.*]] = quake.extract_ref %[[VAL_7]]{{\[}}%[[VAL_12]]] : (!quake.veq, i64) -> !quake.ref +// CHECK: %[[VAL_13:.*]] = quake.extract_ref %[[VAL_7]][%[[VAL_12]]] : (!quake.veq, i64) -> !quake.ref // CHECK: quake.h %[[VAL_13]] : (!quake.ref) -> () // CHECK: cc.continue %[[VAL_12]] : i64 // CHECK: } step { @@ -101,15 +101,15 @@ struct ArithmeticTupleQernelWithUse0 { // CHECK: cc.store %[[VAL_0]], %[[VAL_3]] : !cc.ptr> // CHECK: %[[VAL_4:.*]] = cc.cast %[[VAL_3]] : (!cc.ptr>) -> !cc.ptr // CHECK: %[[VAL_5:.*]] = cc.load %[[VAL_4]] : !cc.ptr -// CHECK: %[[VAL_6:.*]] = arith.extsi %[[VAL_5]] : i32 to i64 -// CHECK: %[[VAL_7:.*]] = quake.alloca !quake.veq{{\[}}%[[VAL_6]] : i64] +// CHECK: %[[VAL_6:.*]] = cc.cast signed %[[VAL_5]] : (i32) -> i64 +// CHECK: %[[VAL_7:.*]] = quake.alloca !quake.veq[%[[VAL_6]] : i64] // CHECK: %[[VAL_8:.*]] = quake.veq_size %[[VAL_7]] : (!quake.veq) -> i64 // CHECK: %[[VAL_9:.*]] = cc.loop while ((%[[VAL_10:.*]] = %[[VAL_2]]) -> (i64)) { // CHECK: %[[VAL_11:.*]] = arith.cmpi slt, %[[VAL_10]], %[[VAL_8]] : i64 // CHECK: cc.condition %[[VAL_11]](%[[VAL_10]] : i64) // CHECK: } do { // CHECK: ^bb0(%[[VAL_12:.*]]: i64): -// CHECK: %[[VAL_13:.*]] = quake.extract_ref %[[VAL_7]]{{\[}}%[[VAL_12]]] : (!quake.veq, i64) -> !quake.ref +// CHECK: %[[VAL_13:.*]] = quake.extract_ref %[[VAL_7]][%[[VAL_12]]] : (!quake.veq, i64) -> !quake.ref // CHECK: quake.h %[[VAL_13]] : (!quake.ref) -> () // CHECK: cc.continue %[[VAL_12]] : i64 // CHECK: } step { @@ -136,8 +136,8 @@ struct ArithmeticPairQernelWithUse { // CHECK: cc.store %[[VAL_0]], %[[VAL_1]] : !cc.ptr> // CHECK: %[[VAL_2:.*]] = cc.compute_ptr %[[VAL_1]][1] : (!cc.ptr>) -> !cc.ptr // CHECK: %[[VAL_3:.*]] = cc.load %[[VAL_2]] : !cc.ptr -// CHECK: %[[VAL_4:.*]] = arith.extsi %[[VAL_3]] : i32 to i64 -// CHECK: %[[VAL_5:.*]] = quake.alloca !quake.veq{{\[}}%[[VAL_4]] : i64] +// CHECK: %[[VAL_4:.*]] = cc.cast signed %[[VAL_3]] : (i32) -> i64 +// CHECK: %[[VAL_5:.*]] = quake.alloca !quake.veq[%[[VAL_4]] : i64] // CHECK: %[[VAL_6:.*]] = quake.mz %[[VAL_5]] : (!quake.veq) -> !cc.stdvec // CHECK: return // CHECK: } diff --git a/test/AST-Quake/vector_ctor_initlist_int.cpp b/test/AST-Quake/vector_ctor_initlist_int.cpp index 016a3af625..020202201d 100644 --- a/test/AST-Quake/vector_ctor_initlist_int.cpp +++ b/test/AST-Quake/vector_ctor_initlist_int.cpp @@ -36,18 +36,18 @@ __qpu__ void testInt() { // CHECK: cc.store %[[VAL_1]], %[[VAL_8]] : !cc.ptr // CHECK: %[[VAL_10:.*]] = cc.cast %[[VAL_5]] : (!cc.ptr>) -> !cc.ptr // CHECK: %[[VAL_11:.*]] = cc.load %[[VAL_10]] : !cc.ptr -// CHECK: %[[VAL_12:.*]] = arith.extsi %[[VAL_11]] : i32 to i64 -// CHECK: %[[VAL_13:.*]] = quake.extract_ref %[[VAL_4]]{{\[}}%[[VAL_12]]] : (!quake.veq<3>, i64) -> !quake.ref +// CHECK: %[[VAL_12:.*]] = cc.cast signed %[[VAL_11]] : (i32) -> i64 +// CHECK: %[[VAL_13:.*]] = quake.extract_ref %[[VAL_4]][%[[VAL_12]]] : (!quake.veq<3>, i64) -> !quake.ref // CHECK: quake.ry (%[[VAL_0]]) %[[VAL_13]] : (f64, !quake.ref) -> () // CHECK: %[[VAL_15:.*]] = cc.compute_ptr %[[VAL_5]][1] : (!cc.ptr>) -> !cc.ptr // CHECK: %[[VAL_16:.*]] = cc.load %[[VAL_15]] : !cc.ptr -// CHECK: %[[VAL_17:.*]] = arith.extsi %[[VAL_16]] : i32 to i64 -// CHECK: %[[VAL_18:.*]] = quake.extract_ref %[[VAL_4]]{{\[}}%[[VAL_17]]] : (!quake.veq<3>, i64) -> !quake.ref +// CHECK: %[[VAL_17:.*]] = cc.cast signed %[[VAL_16]] : (i32) -> i64 +// CHECK: %[[VAL_18:.*]] = quake.extract_ref %[[VAL_4]][%[[VAL_17]]] : (!quake.veq<3>, i64) -> !quake.ref // CHECK: quake.ry (%[[VAL_0]]) %[[VAL_18]] : (f64, !quake.ref) -> () // CHECK: %[[VAL_20:.*]] = cc.compute_ptr %[[VAL_5]][2] : (!cc.ptr>) -> !cc.ptr // CHECK: %[[VAL_21:.*]] = cc.load %[[VAL_20]] : !cc.ptr -// CHECK: %[[VAL_22:.*]] = arith.extsi %[[VAL_21]] : i32 to i64 -// CHECK: %[[VAL_23:.*]] = quake.extract_ref %[[VAL_4]]{{\[}}%[[VAL_22]]] : (!quake.veq<3>, i64) -> !quake.ref +// CHECK: %[[VAL_22:.*]] = cc.cast signed %[[VAL_21]] : (i32) -> i64 +// CHECK: %[[VAL_23:.*]] = quake.extract_ref %[[VAL_4]][%[[VAL_22]]] : (!quake.veq<3>, i64) -> !quake.ref // CHECK: quake.ry (%[[VAL_0]]) %[[VAL_23]] : (f64, !quake.ref) -> () // CHECK: return // CHECK: } diff --git a/test/AST-Quake/vector_vector.cpp b/test/AST-Quake/vector_vector.cpp index 62eef37486..8267d39e96 100644 --- a/test/AST-Quake/vector_vector.cpp +++ b/test/AST-Quake/vector_vector.cpp @@ -310,7 +310,7 @@ struct VectorVectorBilingual { // CHECK: %[[VAL_29:.*]] = cc.stdvec_data %[[VAL_28]] : (!cc.stdvec) -> !cc.ptr> // CHECK: %[[VAL_30:.*]] = cc.compute_ptr %[[VAL_29]][%[[VAL_27]]] : (!cc.ptr>, i64) -> !cc.ptr // CHECK: %[[VAL_31:.*]] = cc.load %[[VAL_30]] : !cc.ptr -// CHECK: %[[VAL_32:.*]] = arith.sitofp %[[VAL_31]] : i32 to f64 +// CHECK: %[[VAL_32:.*]] = cc.cast signed %[[VAL_31]] : (i32) -> f64 // CHECK: cc.store %[[VAL_32]], %[[VAL_26]] : !cc.ptr // CHECK: cc.continue // CHECK: } step { diff --git a/test/AST-Quake/veq_size_init_state.cpp b/test/AST-Quake/veq_size_init_state.cpp index c1b86aebd5..0826a7844a 100644 --- a/test/AST-Quake/veq_size_init_state.cpp +++ b/test/AST-Quake/veq_size_init_state.cpp @@ -20,28 +20,24 @@ struct kernel { }; // CHECK-LABEL: func.func @__nvqpp__mlirgen__kernel() attributes -// CHECK-DAG: %[[VAL_0:.*]] = arith.constant 1.000000e+00 : f64 -// CHECK-DAG: %[[VAL_1:.*]] = arith.constant 0.000000e+00 : f64 -// CHECK: %[[VAL_2:.*]] = complex.create %[[VAL_0]], %[[VAL_1]] : complex -// CHECK: %[[VAL_3:.*]] = complex.create %[[VAL_1]], %[[VAL_1]] : complex -// CHECK: %[[VAL_4:.*]] = complex.create %[[VAL_1]], %[[VAL_1]] : complex -// CHECK: %[[VAL_5:.*]] = complex.create %[[VAL_1]], %[[VAL_1]] : complex -// CHECK: %[[VAL_6:.*]] = cc.alloca !cc.array x 4> -// CHECK: %[[VAL_7:.*]] = cc.cast %[[VAL_6]] : (!cc.ptr x 4>>) -> !cc.ptr> -// CHECK: cc.store %[[VAL_2]], %[[VAL_7]] : !cc.ptr> -// CHECK: %[[VAL_8:.*]] = cc.compute_ptr %[[VAL_6]][1] : (!cc.ptr x 4>>) -> !cc.ptr> -// CHECK: cc.store %[[VAL_3]], %[[VAL_8]] : !cc.ptr> -// CHECK: %[[VAL_9:.*]] = cc.compute_ptr %[[VAL_6]][2] : (!cc.ptr x 4>>) -> !cc.ptr> -// CHECK: cc.store %[[VAL_4]], %[[VAL_9]] : !cc.ptr> -// CHECK: %[[VAL_10:.*]] = cc.compute_ptr %[[VAL_6]][3] : (!cc.ptr x 4>>) -> !cc.ptr> -// CHECK: cc.store %[[VAL_5]], %[[VAL_10]] : !cc.ptr> -// CHECK: %[[VAL_11:.*]] = cc.cast %[[VAL_6]] : (!cc.ptr x 4>>) -> !cc.ptr> -// CHECK: %[[VAL_12:.*]] = quake.alloca !quake.veq<2> -// CHECK: %[[VAL_13:.*]] = quake.init_state %[[VAL_12]], %[[VAL_11]] : (!quake.veq<2>, !cc.ptr>) -> !quake.veq<2> -// CHECK: %[[VAL_14:.*]] = quake.extract_ref %[[VAL_13]][0] : (!quake.veq<2>) -> !quake.ref -// CHECK: quake.h %[[VAL_14]] : (!quake.ref) -> () -// CHECK: %[[VAL_15:.*]] = quake.extract_ref %[[VAL_13]][1] : (!quake.veq<2>) -> !quake.ref -// CHECK: quake.h %[[VAL_15]] : (!quake.ref) -> () -// CHECK: %[[VAL_16:.*]] = quake.mz %[[VAL_13]] : (!quake.veq<2>) -> !cc.stdvec +// CHECK: %[[VAL_0:.*]] = complex.constant [0.000000e+00, 0.000000e+00] : complex +// CHECK: %[[VAL_1:.*]] = complex.constant [1.000000e+00, 0.000000e+00] : complex +// CHECK: %[[VAL_2:.*]] = cc.alloca !cc.array x 4> +// CHECK: %[[VAL_3:.*]] = cc.cast %[[VAL_2]] : (!cc.ptr x 4>>) -> !cc.ptr> +// CHECK: cc.store %[[VAL_1]], %[[VAL_3]] : !cc.ptr> +// CHECK: %[[VAL_4:.*]] = cc.compute_ptr %[[VAL_2]][1] : (!cc.ptr x 4>>) -> !cc.ptr> +// CHECK: cc.store %[[VAL_0]], %[[VAL_4]] : !cc.ptr> +// CHECK: %[[VAL_5:.*]] = cc.compute_ptr %[[VAL_2]][2] : (!cc.ptr x 4>>) -> !cc.ptr> +// CHECK: cc.store %[[VAL_0]], %[[VAL_5]] : !cc.ptr> +// CHECK: %[[VAL_6:.*]] = cc.compute_ptr %[[VAL_2]][3] : (!cc.ptr x 4>>) -> !cc.ptr> +// CHECK: cc.store %[[VAL_0]], %[[VAL_6]] : !cc.ptr> +// CHECK: %[[VAL_7:.*]] = cc.cast %[[VAL_2]] : (!cc.ptr x 4>>) -> !cc.ptr> +// CHECK: %[[VAL_8:.*]] = quake.alloca !quake.veq<2> +// CHECK: %[[VAL_9:.*]] = quake.init_state %[[VAL_8]], %[[VAL_7]] : (!quake.veq<2>, !cc.ptr>) -> !quake.veq<2> +// CHECK: %[[VAL_10:.*]] = quake.extract_ref %[[VAL_9]][0] : (!quake.veq<2>) -> !quake.ref +// CHECK: quake.h %[[VAL_10]] : (!quake.ref) -> () +// CHECK: %[[VAL_11:.*]] = quake.extract_ref %[[VAL_9]][1] : (!quake.veq<2>) -> !quake.ref +// CHECK: quake.h %[[VAL_11]] : (!quake.ref) -> () +// CHECK: %[[VAL_12:.*]] = quake.mz %[[VAL_9]] : (!quake.veq<2>) -> !cc.stdvec // CHECK: return // CHECK: } diff --git a/test/AST-Quake/while-1.cpp b/test/AST-Quake/while-1.cpp index acc031fdec..a260cbb4e2 100644 --- a/test/AST-Quake/while-1.cpp +++ b/test/AST-Quake/while-1.cpp @@ -47,23 +47,23 @@ __qpu__ double test4(cudaq::qview<> a, cudaq::qview<> b) { // CHECK: %[[VAL_2:.*]] = arith.constant true // CHECK: %[[VAL_3:.*]] = arith.constant 1 : i64 // CHECK: %[[VAL_4:.*]] = quake.veq_size %[[VAL_0]] : (!quake.veq) -> i64 -// CHECK: %[[VAL_5:.*]] = arith.trunci %[[VAL_4]] : i64 to i32 +// CHECK: %[[VAL_5:.*]] = cc.cast %[[VAL_4]] : (i64) -> i32 // CHECK: %[[VAL_6:.*]] = cc.alloca i32 // CHECK: cc.store %[[VAL_5]], %[[VAL_6]] : !cc.ptr // CHECK: cc.loop while { // CHECK: cc.condition %[[VAL_2]] // CHECK: } do { // CHECK: %[[VAL_7:.*]] = cc.load %[[VAL_6]] : !cc.ptr -// CHECK: %[[VAL_8:.*]] = arith.extui %[[VAL_7]] : i32 to i64 +// CHECK: %[[VAL_8:.*]] = cc.cast unsigned %[[VAL_7]] : (i32) -> i64 // CHECK: %[[VAL_9:.*]] = arith.subi %[[VAL_8]], %[[VAL_3]] : i64 // CHECK: %[[VAL_10:.*]] = quake.extract_ref %[[VAL_0]]{{\[}}%[[VAL_9]]] : (!quake.veq, i64) -> !quake.ref // CHECK: %[[VAL_11:.*]] = cc.load %[[VAL_6]] : !cc.ptr -// CHECK: %[[VAL_12:.*]] = arith.extui %[[VAL_11]] : i32 to i64 +// CHECK: %[[VAL_12:.*]] = cc.cast unsigned %[[VAL_11]] : (i32) -> i64 // CHECK: %[[VAL_13:.*]] = arith.subi %[[VAL_12]], %[[VAL_3]] : i64 // CHECK: %[[VAL_14:.*]] = quake.extract_ref %[[VAL_1]]{{\[}}%[[VAL_13]]] : (!quake.veq, i64) -> !quake.ref // CHECK: %[[VAL_15:.*]] = cc.load %[[VAL_6]] : !cc.ptr -// CHECK: %[[VAL_16:.*]] = arith.extui %[[VAL_15]] : i32 to i64 -// CHECK: %[[VAL_17:.*]] = quake.extract_ref %[[VAL_0]]{{\[}}%[[VAL_16]]] : (!quake.veq, i64) -> !quake.ref +// CHECK: %[[VAL_16:.*]] = cc.cast unsigned %[[VAL_15]] : (i32) -> i64 +// CHECK: %[[VAL_17:.*]] = quake.extract_ref %[[VAL_0]][%[[VAL_16]]] : (!quake.veq, i64) -> !quake.ref // CHECK: func.call @_Z3umaRN5cudaq5quditILm2EEES2_S2_(%[[VAL_10]], %[[VAL_14]], %[[VAL_17]]) : (!quake.ref, !quake.ref, !quake.ref) -> () // CHECK: cc.continue // CHECK: } @@ -75,23 +75,23 @@ __qpu__ double test4(cudaq::qview<> a, cudaq::qview<> b) { // CHECK: %[[VAL_2:.*]] = arith.constant 1 : i64 // CHECK: %[[VAL_3:.*]] = arith.constant true // CHECK: %[[VAL_4:.*]] = quake.veq_size %[[VAL_0]] : (!quake.veq) -> i64 -// CHECK: %[[VAL_5:.*]] = arith.trunci %[[VAL_4]] : i64 to i32 +// CHECK: %[[VAL_5:.*]] = cc.cast %[[VAL_4]] : (i64) -> i32 // CHECK: %[[VAL_6:.*]] = cc.alloca i32 // CHECK: cc.store %[[VAL_5]], %[[VAL_6]] : !cc.ptr // CHECK: cc.loop while { // CHECK: cc.condition %[[VAL_3]] // CHECK: } do { // CHECK: %[[VAL_7:.*]] = cc.load %[[VAL_6]] : !cc.ptr -// CHECK: %[[VAL_8:.*]] = arith.extui %[[VAL_7]] : i32 to i64 +// CHECK: %[[VAL_8:.*]] = cc.cast unsigned %[[VAL_7]] : (i32) -> i64 // CHECK: %[[VAL_9:.*]] = arith.subi %[[VAL_8]], %[[VAL_2]] : i64 // CHECK: %[[VAL_10:.*]] = quake.extract_ref %[[VAL_0]]{{\[}}%[[VAL_9]]] : (!quake.veq, i64) -> !quake.ref // CHECK: %[[VAL_11:.*]] = cc.load %[[VAL_6]] : !cc.ptr -// CHECK: %[[VAL_12:.*]] = arith.extui %[[VAL_11]] : i32 to i64 +// CHECK: %[[VAL_12:.*]] = cc.cast unsigned %[[VAL_11]] : (i32) -> i64 // CHECK: %[[VAL_13:.*]] = arith.subi %[[VAL_12]], %[[VAL_2]] : i64 // CHECK: %[[VAL_14:.*]] = quake.extract_ref %[[VAL_1]]{{\[}}%[[VAL_13]]] : (!quake.veq, i64) -> !quake.ref // CHECK: %[[VAL_15:.*]] = cc.load %[[VAL_6]] : !cc.ptr -// CHECK: %[[VAL_16:.*]] = arith.extui %[[VAL_15]] : i32 to i64 -// CHECK: %[[VAL_17:.*]] = quake.extract_ref %[[VAL_0]]{{\[}}%[[VAL_16]]] : (!quake.veq, i64) -> !quake.ref +// CHECK: %[[VAL_16:.*]] = cc.cast unsigned %[[VAL_15]] : (i32) -> i64 +// CHECK: %[[VAL_17:.*]] = quake.extract_ref %[[VAL_0]][%[[VAL_16]]] : (!quake.veq, i64) -> !quake.ref // CHECK: func.call @_Z3umaRN5cudaq5quditILm2EEES2_S2_(%[[VAL_10]], %[[VAL_14]], %[[VAL_17]]) : (!quake.ref, !quake.ref, !quake.ref) -> () // CHECK: cc.continue // CHECK: } @@ -103,20 +103,20 @@ __qpu__ double test4(cudaq::qview<> a, cudaq::qview<> b) { // CHECK: %[[VAL_2:.*]] = arith.constant 1 : i64 // CHECK: %[[VAL_3:.*]] = arith.constant false // CHECK: %[[VAL_4:.*]] = quake.veq_size %[[VAL_0]] : (!quake.veq) -> i64 -// CHECK: %[[VAL_5:.*]] = arith.trunci %[[VAL_4]] : i64 to i32 +// CHECK: %[[VAL_5:.*]] = cc.cast %[[VAL_4]] : (i64) -> i32 // CHECK: %[[VAL_6:.*]] = cc.alloca i32 // CHECK: cc.store %[[VAL_5]], %[[VAL_6]] : !cc.ptr // CHECK: cc.loop do { // CHECK: %[[VAL_7:.*]] = cc.load %[[VAL_6]] : !cc.ptr -// CHECK: %[[VAL_8:.*]] = arith.extui %[[VAL_7]] : i32 to i64 +// CHECK: %[[VAL_8:.*]] = cc.cast unsigned %[[VAL_7]] : (i32) -> i64 // CHECK: %[[VAL_9:.*]] = arith.subi %[[VAL_8]], %[[VAL_2]] : i64 // CHECK: %[[VAL_10:.*]] = quake.extract_ref %[[VAL_0]]{{\[}}%[[VAL_9]]] : (!quake.veq, i64) -> !quake.ref // CHECK: %[[VAL_11:.*]] = cc.load %[[VAL_6]] : !cc.ptr -// CHECK: %[[VAL_12:.*]] = arith.extui %[[VAL_11]] : i32 to i64 +// CHECK: %[[VAL_12:.*]] = cc.cast unsigned %[[VAL_11]] : (i32) -> i64 // CHECK: %[[VAL_13:.*]] = arith.subi %[[VAL_12]], %[[VAL_2]] : i64 // CHECK: %[[VAL_14:.*]] = quake.extract_ref %[[VAL_1]]{{\[}}%[[VAL_13]]] : (!quake.veq, i64) -> !quake.ref // CHECK: %[[VAL_15:.*]] = cc.load %[[VAL_6]] : !cc.ptr -// CHECK: %[[VAL_16:.*]] = arith.extui %[[VAL_15]] : i32 to i64 +// CHECK: %[[VAL_16:.*]] = cc.cast unsigned %[[VAL_15]] : (i32) -> i64 // CHECK: %[[VAL_17:.*]] = quake.extract_ref %[[VAL_0]]{{\[}}%[[VAL_16]]] : (!quake.veq, i64) -> !quake.ref // CHECK: func.call @_Z3umaRN5cudaq5quditILm2EEES2_S2_(%[[VAL_10]], %[[VAL_14]], %[[VAL_17]]) : (!quake.ref, !quake.ref, !quake.ref) -> () // CHECK: cc.continue @@ -131,25 +131,25 @@ __qpu__ double test4(cudaq::qview<> a, cudaq::qview<> b) { // CHECK: %[[VAL_2:.*]] = arith.constant false // CHECK: %[[VAL_3:.*]] = arith.constant 1 : i64 // CHECK: %[[VAL_4:.*]] = quake.veq_size %[[VAL_0]] : (!quake.veq) -> i64 -// CHECK: %[[VAL_5:.*]] = arith.trunci %[[VAL_4]] : i64 to i32 +// CHECK: %[[VAL_5:.*]] = cc.cast %[[VAL_4]] : (i64) -> i32 // CHECK: %[[VAL_6:.*]] = cc.alloca i32 // CHECK: cc.store %[[VAL_5]], %[[VAL_6]] : !cc.ptr // CHECK: %[[VAL_7:.*]] = cc.load %[[VAL_6]] : !cc.ptr -// CHECK: %[[VAL_8:.*]] = arith.uitofp %[[VAL_7]] : i32 to f64 +// CHECK: %[[VAL_8:.*]] = cc.cast unsigned %[[VAL_7]] : (i32) -> f64 // CHECK: %[[VAL_9:.*]] = cc.alloca f64 // CHECK: cc.store %[[VAL_8]], %[[VAL_9]] : !cc.ptr // CHECK: cc.loop do { // CHECK: %[[VAL_10:.*]] = cc.load %[[VAL_6]] : !cc.ptr -// CHECK: %[[VAL_11:.*]] = arith.extui %[[VAL_10]] : i32 to i64 +// CHECK: %[[VAL_11:.*]] = cc.cast unsigned %[[VAL_10]] : (i32) -> i64 // CHECK: %[[VAL_12:.*]] = arith.subi %[[VAL_11]], %[[VAL_3]] : i64 // CHECK: %[[VAL_13:.*]] = quake.extract_ref %[[VAL_0]]{{\[}}%[[VAL_12]]] : (!quake.veq, i64) -> !quake.ref // CHECK: %[[VAL_14:.*]] = cc.load %[[VAL_6]] : !cc.ptr -// CHECK: %[[VAL_15:.*]] = arith.extui %[[VAL_14]] : i32 to i64 +// CHECK: %[[VAL_15:.*]] = cc.cast unsigned %[[VAL_14]] : (i32) -> i64 // CHECK: %[[VAL_16:.*]] = arith.subi %[[VAL_15]], %[[VAL_3]] : i64 // CHECK: %[[VAL_17:.*]] = quake.extract_ref %[[VAL_1]]{{\[}}%[[VAL_16]]] : (!quake.veq, i64) -> !quake.ref // CHECK: %[[VAL_18:.*]] = cc.load %[[VAL_6]] : !cc.ptr -// CHECK: %[[VAL_19:.*]] = arith.extui %[[VAL_18]] : i32 to i64 -// CHECK: %[[VAL_20:.*]] = quake.extract_ref %[[VAL_0]]{{\[}}%[[VAL_19]]] : (!quake.veq, i64) -> !quake.ref +// CHECK: %[[VAL_19:.*]] = cc.cast unsigned %[[VAL_18]] : (i32) -> i64 +// CHECK: %[[VAL_20:.*]] = quake.extract_ref %[[VAL_0]][%[[VAL_19]]] : (!quake.veq, i64) -> !quake.ref // CHECK: func.call @_Z3umaRN5cudaq5quditILm2EEES2_S2_(%[[VAL_13]], %[[VAL_17]], %[[VAL_20]]) : (!quake.ref, !quake.ref, !quake.ref) -> () // CHECK: cc.continue // CHECK: } while { diff --git a/test/Quake/cast_fold.qke b/test/Quake/cast_fold.qke new file mode 100644 index 0000000000..a57f414262 --- /dev/null +++ b/test/Quake/cast_fold.qke @@ -0,0 +1,108 @@ +// ========================================================================== // +// Copyright (c) 2022 - 2024 NVIDIA Corporation & Affiliates. // +// All rights reserved. // +// // +// This source code and the accompanying materials are made available under // +// the terms of the Apache License 2.0 which accompanies this distribution. // +// ========================================================================== // + +// RUN: cudaq-opt -canonicalize %s | cudaq-opt | FileCheck %s + +func.func @b1() -> f32 { + %0 = arith.constant 22 : i64 + %1 = cc.cast signed %0 : (i64) -> f32 + return %1 : f32 +} + +func.func @b2() -> f32 { + %0 = arith.constant -21 : i64 + %1 = cc.cast unsigned %0 : (i64) -> f32 + return %1 : f32 +} + +func.func @b3() -> f32 { + %0 = arith.constant 2.34 : f64 + %1 = cc.cast %0 : (f64) -> f32 + return %1 : f32 +} + +func.func @b4() -> f64 { + %0 = arith.constant 6.34 : f32 + %1 = cc.cast %0 : (f32) -> f64 + return %1 : f64 +} + +func.func @b5() -> i32 { + %0 = arith.constant 94 : i64 + %1 = cc.cast signed %0 : (i64) -> i32 + return %1 : i32 +} + +func.func @b6() -> i64 { + %0 = arith.constant 73 : i16 + %1 = cc.cast signed %0 : (i16) -> i64 + return %1 : i64 +} + +func.func @b7() -> i64 { + %0 = arith.constant -82 : i16 + %1 = cc.cast unsigned %0 : (i16) -> i64 + return %1 : i64 +} + +func.func @b8() -> i64 { + %0 = arith.constant -6.29 : f32 + %1 = cc.cast signed %0 : (f32) -> i64 + return %1 : i64 +} + +func.func @b9() -> i32 { + %0 = arith.constant 7.11 : f64 + %1 = cc.cast unsigned %0 : (f64) -> i32 + return %1 : i32 +} + +// CHECK-LABEL: func.func @b1() -> f32 { +// CHECK: %[[VAL_0:.*]] = arith.constant 2.200000e+01 : f32 +// CHECK: return %[[VAL_0]] : f32 +// CHECK: } + +// CHECK-LABEL: func.func @b2() -> f32 { +// CHECK: %[[VAL_0:.*]] = arith.constant 1.84467441E+19 : f32 +// CHECK: return %[[VAL_0]] : f32 +// CHECK: } + +// CHECK-LABEL: func.func @b3() -> f32 { +// CHECK: %[[VAL_0:.*]] = arith.constant 2.340000e+00 : f32 +// CHECK: return %[[VAL_0]] : f32 +// CHECK: } + +// CHECK-LABEL: func.func @b4() -> f64 { +// CHECK: %[[VAL_0:.*]] = arith.constant 6.3400001525878906 : f64 +// CHECK: return %[[VAL_0]] : f64 +// CHECK: } + +// CHECK-LABEL: func.func @b5() -> i32 { +// CHECK: %[[VAL_0:.*]] = arith.constant 94 : i32 +// CHECK: return %[[VAL_0]] : i32 +// CHECK: } + +// CHECK-LABEL: func.func @b6() -> i64 { +// CHECK: %[[VAL_0:.*]] = arith.constant 73 : i64 +// CHECK: return %[[VAL_0]] : i64 +// CHECK: } + +// CHECK-LABEL: func.func @b7() -> i64 { +// CHECK: %[[VAL_0:.*]] = arith.constant -82 : i64 +// CHECK: return %[[VAL_0]] : i64 +// CHECK: } + +// CHECK-LABEL: func.func @b8() -> i64 { +// CHECK: %[[VAL_0:.*]] = arith.constant -6 : i64 +// CHECK: return %[[VAL_0]] : i64 +// CHECK: } + +// CHECK-LABEL: func.func @b9() -> i32 { +// CHECK: %[[VAL_0:.*]] = arith.constant 7 : i32 +// CHECK: return %[[VAL_0]] : i32 +// CHECK: } diff --git a/test/Quake/complex.qke b/test/Quake/complex.qke new file mode 100644 index 0000000000..821868762e --- /dev/null +++ b/test/Quake/complex.qke @@ -0,0 +1,46 @@ +// ========================================================================== // +// Copyright (c) 2022 - 2024 NVIDIA Corporation & Affiliates. // +// All rights reserved. // +// // +// This source code and the accompanying materials are made available under // +// the terms of the Apache License 2.0 which accompanies this distribution. // +// ========================================================================== // + +// RUN: cudaq-opt -canonicalize %s | FileCheck %s + +func.func @folding_conversion() -> (complex, complex) { + %1 = complex.constant [5.0, 6.0] : complex + %2 = cc.cast %1 : (complex) -> complex + %3 = complex.constant [15.0 : f32, 6.2 :f32] : complex + %4 = cc.cast %3 : (complex) -> complex + return %2, %4 : complex, complex +} + +// CHECK-LABEL: func.func @folding_conversion() -> (complex, complex) { +// CHECK: %[[VAL_0:.*]] = complex.constant [5.000000e+00 : f32, 6.000000e+00 : f32] : complex +// CHECK: %[[VAL_1:.*]] = complex.constant [1.500000e+01, 6.1999998092651367] : complex +// CHECK: return %[[VAL_0]], %[[VAL_1]] : complex, complex +// CHECK: } + +func.func @folds_like_a_lawn_chair() { + %cst = arith.constant 0.000000e+00 : f32 + %cst_0 = arith.constant 0.70710678118654757 : f64 + %0 = cc.cast %cst_0 : (f64) -> f32 + %1 = complex.create %0, %cst : complex + %2 = cc.cast %cst_0 : (f64) -> f32 + %3 = complex.create %2, %cst : complex + %4 = complex.create %cst, %cst : complex + %5 = complex.create %cst, %cst : complex + %6 = cc.alloca !cc.array x 4> + %7 = cc.cast %6 : (!cc.ptr x 4>>) -> !cc.ptr> + cc.store %1, %7 : !cc.ptr> + return +} + +// CHECK-LABEL: func.func @folds_like_a_lawn_chair() { +// CHECK: %[[VAL_0:.*]] = complex.constant [0.707106769 : f32, 0.000000e+00 : f32] : complex +// CHECK: %[[VAL_1:.*]] = cc.alloca !cc.array x 4> +// CHECK: %[[VAL_2:.*]] = cc.cast %[[VAL_1]] : (!cc.ptr x 4>>) -> !cc.ptr> +// CHECK: cc.store %[[VAL_0]], %[[VAL_2]] : !cc.ptr> +// CHECK: return +// CHECK: }