Skip to content

Commit

Permalink
Replace GenISA ftof usage with arith::TruncFOp
Browse files Browse the repository at this point in the history
Signed-off-by: Whitney Tsang <whitney.tsang@intel.com>
  • Loading branch information
whitneywhtsang committed Apr 25, 2024
1 parent 8bcd236 commit 548612e
Showing 1 changed file with 2 additions and 30 deletions.
32 changes: 2 additions & 30 deletions third_party/intel/lib/TritonIntelGPUToLLVM/ElementwiseOpToLLVM.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "PatternTritonGPUOpToLLVM.h"
#include "mlir/Conversion/ArithCommon/AttrToLLVMConverter.h"
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
#include "mlir/IR/MLIRContext.h"
#include "triton/Conversion/TritonGPUToLLVM/TargetInfoBase.h"
Expand Down Expand Up @@ -1330,33 +1329,6 @@ struct FpToFpOpConversion
ConversionPatternRewriter &rewriter,
const Value &v, const RoundingMode rounding) {
MLIRContext *ctx = rewriter.getContext();

LLVM::RoundingMode roundingMode;
switch (rounding) {
case RoundingMode::RTNE:
roundingMode = LLVM::RoundingMode::NearestTiesToEven;
break;
case RoundingMode::RTZ:
roundingMode = LLVM::RoundingMode::TowardZero;
break;
default:
llvm::errs() << "WARNING: unsupported rounding mode for f32->f16 "
"conversion: "
<< stringifyRoundingMode(rounding) << "\n";
llvm_unreachable("");
}

NamedAttrList convertedAttr;
convertedAttr.set(LLVM::ConstrainedFPTruncIntr::getRoundingModeAttrName(),
LLVM::RoundingModeAttr::get(ctx, roundingMode));
convertedAttr.set(
LLVM::ConstrainedFPTruncIntr::getFPExceptionBehaviorAttrName(),
arith::getLLVMDefaultFPExceptionBehavior(*ctx));
return rewriter.create<LLVM::ConstrainedFPTruncIntr>(loc, f16_ty, v,
convertedAttr);

#if 0
// FIXME: test_typeconvert_downcast fails when lower to arith::TruncFOp.
arith::RoundingMode roundingMode;
switch (rounding) {
case RoundingMode::RTNE:
Expand All @@ -1373,7 +1345,6 @@ struct FpToFpOpConversion
}
return rewriter.create<arith::TruncFOp>(
loc, f16_ty, v, arith::RoundingModeAttr::get(ctx, roundingMode));
#endif
}

std::pair<ConverterT, size_t>
Expand Down Expand Up @@ -2023,9 +1994,10 @@ struct TruncFOpConversion
return {// Trunc uses the default rounding mode: RTNE
FpToFpOpConversion::convertFp32ToBf16(
loc, rewriter, operands[0][0], RoundingMode::RTNE)};
} else {
} else if (!op.getRoundingModeAttr()) {
return {rewriter.create<LLVM::FPTruncOp>(loc, elemTy, operands[0][0])};
}
return {};
}
};

Expand Down

0 comments on commit 548612e

Please sign in to comment.