Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/Conversion/ImportVerilog/Expressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,7 @@ struct RvalueExprVisitor : public ExprVisitor {
auto type = context.convertType(*expr.type);
if (!type)
return {};
return context.convertRvalueExpression(expr.operand(), type);
return context.convertRvalueExpression(expr.operand(), type, expr.type->isSigned());
}

// Handle blocking and non-blocking assignments.
Expand Down Expand Up @@ -2517,6 +2517,15 @@ Value Context::convertRvalueExpression(const slang::ast::Expression &expr,
materializeConversion(requiredType, value, expr.type->isSigned(), loc);
return value;
}
Value Context::convertRvalueExpression(const slang::ast::Expression &expr,
Type requiredType,bool conversionIsSigned) {
auto loc = convertLocation(expr.sourceRange);
auto value = expr.visit(RvalueExprVisitor(*this, loc));
if (value && requiredType)
value =
materializeConversion(requiredType, value, conversionIsSigned, loc);
return value;
}

Value Context::convertLvalueExpression(const slang::ast::Expression &expr) {
auto loc = convertLocation(expr.sourceRange);
Expand Down
4 changes: 4 additions & 0 deletions lib/Conversion/ImportVerilog/ImportVerilogInternals.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ struct Context {
// Convert an expression AST node to MLIR ops.
Value convertRvalueExpression(const slang::ast::Expression &expr,
Type requiredType = {});
// When materializing a conversion, the caller may need to override the
// source expression's signedness with the conversion's own semantics.
Value convertRvalueExpression(const slang::ast::Expression &expr,
Type requiredType,bool conversionIsSigned);
Comment on lines +246 to +249
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we just add an optional parameter to the existing convertRvalueExpression function?

Value convertLvalueExpression(const slang::ast::Expression &expr);

// Convert an assertion expression AST node to MLIR ops.
Expand Down
24 changes: 24 additions & 0 deletions test/Conversion/ImportVerilog/conversion-signedness.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// RUN: circt-verilog --ir-moore %s | FileCheck %s --check-prefix=MOORE
// REQUIRES: slang

module M(
input logic [7:0] in1,
input logic signed [7:0] in2,
output logic signed [8:0] mux_out
);
logic [7:0] unsigned_src;
logic signed [7:0] signed_src;

always_comb signed_src = in2 >>> 1;
always_comb unsigned_src = in1 >> 1;
always_comb mux_out = signed_src + unsigned_src;
endmodule
Comment on lines +4 to +15
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this test case be reduced at all?


// MOORE-LABEL: moore.module @M(
// MOORE: moore.procedure always_comb {
// MOORE: %[[SIGNED_READ:.+]] = moore.read %signed_src : <l8>
// MOORE: %[[SIGNED_ZEXT:.+]] = moore.zext %[[SIGNED_READ]] : l8 -> l9
// MOORE-NOT: moore.sext
// MOORE: %[[UNSIGNED_READ:.+]] = moore.read %unsigned_src : <l8>
// MOORE: %[[UNSIGNED_ZEXT:.+]] = moore.zext %[[UNSIGNED_READ]] : l8 -> l9
// MOORE: %[[ADD:.+]] = moore.add %[[SIGNED_ZEXT]], %[[UNSIGNED_ZEXT]] : l9
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: missing EOF newline

Loading