Skip to content

[flang][NFC] make IR generation for ieee_next deterministic #125055

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 30, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions flang/lib/Optimizer/Builder/IntrinsicCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6366,10 +6366,12 @@ mlir::Value IntrinsicLibrary::genNearest(mlir::Type resultType,
mlir::FloatType xType = mlir::dyn_cast<mlir::FloatType>(x.getType());
const unsigned xBitWidth = xType.getWidth();
mlir::Type i1Ty = builder.getI1Type();
if constexpr (proc == NearestProc::NextAfter)
if constexpr (proc == NearestProc::NextAfter) {
// If isNan(Y), set X to a qNaN that will propagate to the resultIsX result.
x = builder.create<mlir::arith::SelectOp>(
loc, genIsFPClass(i1Ty, args[1], nanTest), genQNan(xType), x);
mlir::Value qNan = genQNan(xType);
mlir::Value isFPClass = genIsFPClass(i1Ty, args[1], nanTest);
x = builder.create<mlir::arith::SelectOp>(loc, isFPClass, qNan, x);
}
mlir::Value resultIsX = genIsFPClass(i1Ty, x, nanTest);
mlir::Type intType = builder.getIntegerType(xBitWidth);
mlir::Value one = builder.createIntegerConstant(loc, intType, 1);
Expand Down Expand Up @@ -6489,12 +6491,11 @@ mlir::Value IntrinsicLibrary::genNearest(mlir::Type resultType,
} else {
// Kind 2, 3, 4, 8, 16. Increment or decrement X cast to integer.
mlir::Value intX = builder.create<mlir::arith::BitcastOp>(loc, intType, x);
mlir::Value add = builder.create<mlir::arith::AddIOp>(loc, intX, one);
mlir::Value sub = builder.create<mlir::arith::SubIOp>(loc, intX, one);
result = builder.create<mlir::arith::BitcastOp>(
loc, resultType,
builder.create<mlir::arith::SelectOp>(
loc, magnitudeUp,
builder.create<mlir::arith::AddIOp>(loc, intX, one),
builder.create<mlir::arith::SubIOp>(loc, intX, one)));
builder.create<mlir::arith::SelectOp>(loc, magnitudeUp, add, sub));
if constexpr (proc == NearestProc::Nearest ||
proc == NearestProc::NextAfter) {
genRaiseExcept(_FORTRAN_RUNTIME_IEEE_OVERFLOW |
Expand Down