Skip to content

Commit

Permalink
[CPU] Enable fast min/max ops in CPU codegen (iree-org#15130)
Browse files Browse the repository at this point in the history
This patch introduces a flag to generate `arith.minf/maxf` instead of `arith.minimumf/maximumf` ops in the CPU pipeline. We should enable the flag by default in the future as no ML compiler/library is actually caring about NaNs and +/-0.0 values by default.
  • Loading branch information
dcaballe authored Oct 9, 2023
1 parent 94e7e23 commit 9181525
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions compiler/src/iree/compiler/Codegen/LLVMCPU/Passes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ static llvm::cl::opt<bool> clCheckLinalgVectorization(
"Runs the pass to check if all the Linalg ops are vectorized"),
llvm::cl::init(false));

static llvm::cl::opt<bool> clUseFastMinMaxOps(
"iree-llvmcpu-use-fast-min-max-ops",
llvm::cl::desc(
"Use `arith.minf/maxf` instead of `arith.minimumf/maximumf` ops"),
llvm::cl::init(false));

// TODO(#10820): Delete the flag. This should be a nop pass to default pipeline
// while tensor.pad op is lowered to fill + insert_slice before Codegen.
// However, it causes regressions in terms of compilation time. Skip the passes
Expand Down Expand Up @@ -710,6 +716,11 @@ static void addLowerToLLVMPasses(OpPassManager &passManager) {
passManager.addNestedPass<func::FuncOp>(
createHoistStaticallyBoundAllocationsPass());

// Use `arith.minf/maxf` instead of `arith.minimumf/maximumf`.
if (clUseFastMinMaxOps) {
passManager.addNestedPass<func::FuncOp>(createReplaceSlowMinMaxOpsPass());
}

// Resolve get_buffer_descriptor ops. All structural buffer manipulations
// must conclude before this point.
passManager.addNestedPass<func::FuncOp>(
Expand Down

0 comments on commit 9181525

Please sign in to comment.