Commit aa204568 authored by Nguyen, Thien Minh's avatar Nguyen, Thien Minh
Browse files

Fixed a lowering bug whereby the bit-width narrowing was not properly handled


Signed-off-by: Nguyen, Thien Minh's avatarThien Nguyen <nguyentm@ornl.gov>
parent 3c804049
......@@ -62,11 +62,9 @@ qubit a[8];
qubit b[8];
qubit cout;
bit ans[9];
// FIXME: left shift casting to handle different type:
// e.g. i8 vs. i64 (shift value)
uint[64] a_in = 1;
uint[64] b_in = 15;
// Input values:
uint[8] a_in = 1;
uint[8] b_in = 15;
for i in [0:8] {
// FIXME: not able to do this inline....
......
......@@ -171,7 +171,14 @@ LogicalResult IntegerCastOpLowering::matchAndRewrite(
mlir::IntegerType type = to_be_cast.getType().cast<mlir::IntegerType>();
auto cast_op = rewriter.create<LLVM::DialectCastOp>(
loc, rewriter.getIntegerType(type.getWidth(), false), to_be_cast);
rewriter.replaceOp(op, cast_op.res());
if (resultCastOp.getType().getWidth() < type.getWidth()) {
auto trunc_op = rewriter.create<LLVM::TruncOp>(loc, resultCastOp.getType(),
cast_op.res());
rewriter.replaceOp(op, trunc_op.res());
} else {
rewriter.replaceOp(op, cast_op.res());
}
return success();
}
} // namespace qcor
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment