diff --git a/lib/Conversion/TorchToStablehlo/Basic.cpp b/lib/Conversion/TorchToStablehlo/Basic.cpp index 94037c107..f5844e442 100644 --- a/lib/Conversion/TorchToStablehlo/Basic.cpp +++ b/lib/Conversion/TorchToStablehlo/Basic.cpp @@ -449,11 +449,13 @@ public: "only floating-point or integer datatype legalization supported"); } - if (std::is_same()) { + if constexpr (std::is_same()) { rhs = lhs; - } else if (!rhsType) { - rhs = hlo::scalarToStablehloTensor(rewriter, op, adaptor.getOther(), - outElemTy); + } else { + if (!rhsType) { + rhs = hlo::scalarToStablehloTensor(rewriter, op, adaptor.getOther(), + outElemTy); + } } DenseI64ArrayAttr bcastDimensions; lhs = hlo::promoteType(rewriter, op.getLoc(), lhs, outType); @@ -462,8 +464,8 @@ public: Value result = rewriter.create(loc, outType, lhs, rhs, bcastDimensions); - if (!std::is_same() && - !std::is_same()) { + if constexpr (!std::is_same() && + !std::is_same()) { rewriter.replaceOp(op, result); return success(); } @@ -575,32 +577,32 @@ public: op->getContext(), chlo::ComparisonType::SIGNED); } - if (std::is_same() || - std::is_same()) { + if constexpr (std::is_same() || + std::is_same()) { compareDirectionAttr = chlo::ComparisonDirectionAttr::get( op->getContext(), chlo::ComparisonDirection::LT); - } else if (std::is_same() || - std::is_same()) { + } else if constexpr (std::is_same() || + std::is_same()) { compareDirectionAttr = chlo::ComparisonDirectionAttr::get( op->getContext(), chlo::ComparisonDirection::GT); - } else if (std::is_same() || - std::is_same()) { + } else if constexpr (std::is_same() || + std::is_same()) { compareDirectionAttr = chlo::ComparisonDirectionAttr::get( op->getContext(), chlo::ComparisonDirection::GE); - } else if (std::is_same() || - std::is_same()) { + } else if constexpr (std::is_same() || + std::is_same()) { compareDirectionAttr = chlo::ComparisonDirectionAttr::get( op->getContext(), chlo::ComparisonDirection::EQ); - } else if (std::is_same() || - std::is_same()) { + } else if constexpr (std::is_same() || + std::is_same()) { compareDirectionAttr = chlo::ComparisonDirectionAttr::get( op->getContext(), chlo::ComparisonDirection::NE); - } else if (std::is_same() || - std::is_same()) { + } else if constexpr (std::is_same() || + std::is_same()) { compareDirectionAttr = chlo::ComparisonDirectionAttr::get( op->getContext(), chlo::ComparisonDirection::LT); - } else if (std::is_same() || - std::is_same()) { + } else if constexpr (std::is_same() || + std::is_same()) { compareDirectionAttr = chlo::ComparisonDirectionAttr::get( op->getContext(), chlo::ComparisonDirection::LE); } else { diff --git a/lib/Conversion/TorchToTosa/TorchToTosa.cpp b/lib/Conversion/TorchToTosa/TorchToTosa.cpp index db8a435ab..c7c52d087 100644 --- a/lib/Conversion/TorchToTosa/TorchToTosa.cpp +++ b/lib/Conversion/TorchToTosa/TorchToTosa.cpp @@ -371,8 +371,8 @@ public: } auto rhsTensor = rhsTy ? rhs : rhsAsTensor; // There is no Lesser operator in TOSA. - auto swapLhsRhs = (std::is_same() || - std::is_same()); + constexpr auto swapLhsRhs = (std::is_same() || + std::is_same()); // Promote lhs and rhs dtypes for bitwise operators. TensorType resultTy = OpConversionPattern::getTypeConverter() @@ -388,12 +388,15 @@ public: (swapLhsRhs ? lhs : rhsTensor)); // There is no NE operator in TOSA. - if (std::is_same() || - std::is_same()) + if constexpr (std::is_same() || + std::is_same()) { rewriter.replaceOpWithNewOp(op, resultTy, resultOp.getResult()); - else + } + + else { rewriter.replaceOp(op, resultOp.getResult()); + } return success(); } @@ -425,7 +428,7 @@ public: op, "Only floating-point or integer datatype legalization supported"); Value rhsTensor; - if (std::is_same()) { + if constexpr (std::is_same()) { rhsTensor = lhs; } else { Value rhsAsTensor;