Implement constant folding for DivFOp

Add a constant folder for DivFOp. Analogous to existing folders for
AddFOp, SubFOp, and MulFOp. Matches the behavior of existing LLVM
constant folding (999f5da6b3/llvm/lib/IR/ConstantFold.cpp (L1432)).

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D94939
This commit is contained in:
Jackson Fellows 2021-01-19 22:41:45 +00:00 committed by Mehdi Amini
parent 96ef4f307d
commit 1bf2b1665b
2 changed files with 10 additions and 0 deletions

View File

@ -1589,6 +1589,7 @@ def DimOp : Std_Op<"dim", [NoSideEffect]> {
def DivFOp : FloatArithmeticOp<"divf"> {
let summary = "floating point division operation";
let hasFolder = 1;
}
//===----------------------------------------------------------------------===//

View File

@ -1483,6 +1483,15 @@ void DimOp::getCanonicalizationPatterns(OwningRewritePatternList &results,
DimOfCastOp<tensor::CastOp>>(context);
}
// ---------------------------------------------------------------------------
// DivFOp
// ---------------------------------------------------------------------------
OpFoldResult DivFOp::fold(ArrayRef<Attribute> operands) {
return constFoldBinaryOp<FloatAttr>(
operands, [](APFloat a, APFloat b) { return a / b; });
}
// ---------------------------------------------------------------------------
// DmaStartOp
// ---------------------------------------------------------------------------