diff --git a/lib/Conversion/FIRRTLToHW/LowerToHW.cpp b/lib/Conversion/FIRRTLToHW/LowerToHW.cpp index dda06bef1801..e524b4b8c9a9 100644 --- a/lib/Conversion/FIRRTLToHW/LowerToHW.cpp +++ b/lib/Conversion/FIRRTLToHW/LowerToHW.cpp @@ -2729,7 +2729,8 @@ FailureOr FIRRTLLowering::lowerSubindex(SubindexOp op, Value input) { result = builder.createOrFold(input, iIdx); else result = builder.createOrFold(input, iIdx); - tryCopyName(result.getDefiningOp(), op); + if (auto *definingOp = result.getDefiningOp()) + tryCopyName(definingOp, op); return result; } @@ -2752,7 +2753,8 @@ FailureOr FIRRTLLowering::lowerSubaccess(SubaccessOp op, Value input) { result = builder.createOrFold(input, valueIdx); else result = createArrayIndexing(input, valueIdx); - tryCopyName(result.getDefiningOp(), op); + if (auto *definingOp = result.getDefiningOp()) + tryCopyName(definingOp, op); return result; } @@ -2772,7 +2774,8 @@ FailureOr FIRRTLLowering::lowerSubfield(SubfieldOp op, Value input) { result = builder.createOrFold(input, field); else result = builder.createOrFold(input, field); - tryCopyName(result.getDefiningOp(), op); + if (auto *definingOp = result.getDefiningOp()) + tryCopyName(definingOp, op); return result; } @@ -3635,7 +3638,8 @@ LogicalResult FIRRTLLowering::lowerDivLikeOp(Operation *op) { else result = builder.createOrFold(lhs, rhs, true); - tryCopyName(result.getDefiningOp(), op); + if (auto *definingOp = result.getDefiningOp()) + tryCopyName(definingOp, op); if (resultType == opType) return setLowering(op->getResult(0), result); diff --git a/test/Conversion/FIRRTLToHW/lower-to-hw.mlir b/test/Conversion/FIRRTLToHW/lower-to-hw.mlir index 5f58423df925..e65f8b59a502 100644 --- a/test/Conversion/FIRRTLToHW/lower-to-hw.mlir +++ b/test/Conversion/FIRRTLToHW/lower-to-hw.mlir @@ -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>