[TorchToLinalg] Simplify QuantizePerTensor lowering (#3576)

Uses arith::MaximumFOp and arith::MinimumFOp instead of comparison and
select ops to improve readability of IR.
pull/3608/head
zjgarvey 2024-08-02 11:40:52 -07:00 committed by GitHub
parent f7b5c13870
commit 79ae0afc2f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 2 additions and 6 deletions

View File

@ -1461,12 +1461,8 @@ static Value createLinalgPayloadCalculationForElementwiseOp(
b.create<arith::ConstantOp>(loc, b.getFloatAttr(valueTy, minI));
Value maxVal =
b.create<arith::ConstantOp>(loc, b.getFloatAttr(valueTy, maxI));
Value minCmp =
b.create<arith::CmpFOp>(loc, arith::CmpFPredicate::ULT, value, minVal);
Value maxCmp =
b.create<arith::CmpFOp>(loc, arith::CmpFPredicate::UGT, value, maxVal);
value = b.create<arith::SelectOp>(loc, minCmp, minVal, value);
value = b.create<arith::SelectOp>(loc, maxCmp, maxVal, value);
value = b.create<arith::MaximumFOp>(loc, value, minVal);
value = b.create<arith::MinimumFOp>(loc, value, maxVal);
if (isUnsigned) {
value = b.create<arith::FPToUIOp>(loc, destTy, value);