Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIRRTL] LowerToHW: guard against folded operations #7358

Merged
merged 1 commit into from
Jul 19, 2024
Merged
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
12 changes: 8 additions & 4 deletions lib/Conversion/FIRRTLToHW/LowerToHW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2729,7 +2729,8 @@ FailureOr<Value> FIRRTLLowering::lowerSubindex(SubindexOp op, Value input) {
result = builder.createOrFold<sv::ArrayIndexInOutOp>(input, iIdx);
else
result = builder.createOrFold<hw::ArrayGetOp>(input, iIdx);
tryCopyName(result.getDefiningOp(), op);
if (auto *definingOp = result.getDefiningOp())
tryCopyName(definingOp, op);
return result;
}

Expand All @@ -2752,7 +2753,8 @@ FailureOr<Value> FIRRTLLowering::lowerSubaccess(SubaccessOp op, Value input) {
result = builder.createOrFold<sv::ArrayIndexInOutOp>(input, valueIdx);
else
result = createArrayIndexing(input, valueIdx);
tryCopyName(result.getDefiningOp(), op);
if (auto *definingOp = result.getDefiningOp())
tryCopyName(definingOp, op);
return result;
}

Expand All @@ -2772,7 +2774,8 @@ FailureOr<Value> FIRRTLLowering::lowerSubfield(SubfieldOp op, Value input) {
result = builder.createOrFold<sv::StructFieldInOutOp>(input, field);
else
result = builder.createOrFold<hw::StructExtractOp>(input, field);
tryCopyName(result.getDefiningOp(), op);
if (auto *definingOp = result.getDefiningOp())
tryCopyName(definingOp, op);
return result;
}

Expand Down Expand Up @@ -3635,7 +3638,8 @@ LogicalResult FIRRTLLowering::lowerDivLikeOp(Operation *op) {
else
result = builder.createOrFold<UnsignedOp>(lhs, rhs, true);

tryCopyName(result.getDefiningOp(), op);
if (auto *definingOp = result.getDefiningOp())
tryCopyName(definingOp, op);

if (resultType == opType)
return setLowering(op->getResult(0), result);
Expand Down
6 changes: 5 additions & 1 deletion test/Conversion/FIRRTLToHW/lower-to-hw.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,11 @@ firrtl.circuit "Simple" attributes {annotations = [{class =
// CHECK-NEXT: = comb.extract [[SHIFT]] from 0 : (i14) -> i4
%31 = firrtl.dshr %25, %18 : (!firrtl.sint<4>, !firrtl.uint<14>) -> !firrtl.sint<4>

// CHECK-NEXT: comb.icmp bin ule {{.*}}, {{.*}} : i4
// Noop.
%c0_ui1 = firrtl.constant 0 : !firrtl.const.uint<1>
%32 = firrtl.dshr %in1, %c0_ui1 { name = "test" } : (!firrtl.uint<4>, !firrtl.const.uint<1>) -> !firrtl.uint<4>

// CHECK: comb.icmp bin ule {{.*}}, {{.*}} : i4
%41 = firrtl.leq %in1, %4 : (!firrtl.uint<4>, !firrtl.uint<4>) -> !firrtl.uint<1>
// CHECK-NEXT: comb.icmp bin ult {{.*}}, {{.*}} : i4
%42 = firrtl.lt %in1, %4 : (!firrtl.uint<4>, !firrtl.uint<4>) -> !firrtl.uint<1>
Expand Down
Loading