Skip to content

Conversation

krzysz00
Copy link
Contributor

@krzysz00 krzysz00 commented Oct 2, 2025

arith.select isn't an arithmetic operation in the sense of things like addf or mulf, which the emulate-unsupported-floats rewrites using extf and truncf.

This patch adds select as a legal operation to prevent a pointless conversion aronud conditional moves.

Fixes iree-org/iree#22181

arith.select isn't an arithmetic operation in the sense of things like
addf or mulf, which the emulate-unsupported-floats rewrites using extf
and truncf.

This patch adds select as a legal operation to prevent a pointless
conversion aronud conditional moves.

Fixes iree-org/iree#22181
@llvmbot
Copy link
Member

llvmbot commented Oct 2, 2025

@llvm/pr-subscribers-mlir-arith

@llvm/pr-subscribers-mlir

Author: Krzysztof Drewniak (krzysz00)

Changes

arith.select isn't an arithmetic operation in the sense of things like addf or mulf, which the emulate-unsupported-floats rewrites using extf and truncf.

This patch adds select as a legal operation to prevent a pointless conversion aronud conditional moves.

Fixes iree-org/iree#22181


Full diff: https://github.com/llvm/llvm-project/pull/161707.diff

2 Files Affected:

  • (modified) mlir/lib/Dialect/Arith/Transforms/EmulateUnsupportedFloats.cpp (+2-1)
  • (modified) mlir/test/Dialect/Arith/emulate-unsupported-floats.mlir (+11)
diff --git a/mlir/lib/Dialect/Arith/Transforms/EmulateUnsupportedFloats.cpp b/mlir/lib/Dialect/Arith/Transforms/EmulateUnsupportedFloats.cpp
index 7626d356a37f2..c64e10f534f8e 100644
--- a/mlir/lib/Dialect/Arith/Transforms/EmulateUnsupportedFloats.cpp
+++ b/mlir/lib/Dialect/Arith/Transforms/EmulateUnsupportedFloats.cpp
@@ -123,7 +123,8 @@ void mlir::arith::populateEmulateUnsupportedFloatsLegality(
                                vector::OuterProductOp, vector::ScanOp>(
       [&](Operation *op) { return converter.isLegal(op); });
   target.addLegalOp<arith::BitcastOp, arith::ExtFOp, arith::TruncFOp,
-                    arith::ConstantOp, vector::SplatOp, vector::BroadcastOp>();
+                    arith::ConstantOp, arith::SelectOp, vector::SplatOp,
+                    vector::BroadcastOp>();
 }
 
 void EmulateUnsupportedFloatsPass::runOnOperation() {
diff --git a/mlir/test/Dialect/Arith/emulate-unsupported-floats.mlir b/mlir/test/Dialect/Arith/emulate-unsupported-floats.mlir
index 99790cc45d490..fcd004ac554aa 100644
--- a/mlir/test/Dialect/Arith/emulate-unsupported-floats.mlir
+++ b/mlir/test/Dialect/Arith/emulate-unsupported-floats.mlir
@@ -85,3 +85,14 @@ func.func @no_expansion(%x: f32) -> f32 {
   %y = arith.addf %x, %c : f32
   func.return %y : f32
 }
+
+// -----
+
+func.func @no_promote_select(%c: i1, %x: bf16, %y: bf16) -> bf16 {
+// CHECK-LABEL: @no_promote_select
+// CHECK-SAME: (%[[C:.+]]: i1, %[[X:.+]]: bf16, %[[Y:.+]]: bf16)
+// CHECK: %[[Z:.+]] = arith.select %[[C]], %[[X]], %[[Y]] : bf16
+// CHECK: return %[[Z]]
+  %z = arith.select %c, %x, %y : bf16
+  func.return %z : bf16
+}

@krzysz00 krzysz00 merged commit 5be4fc2 into llvm:main Oct 2, 2025
10 of 11 checks passed
mahesh-attarde pushed a commit to mahesh-attarde/llvm-project that referenced this pull request Oct 3, 2025
…ts (llvm#161707)

arith.select isn't an arithmetic operation in the sense of things like
addf or mulf, which the emulate-unsupported-floats rewrites using extf
and truncf.

This patch adds select as a legal operation to prevent a pointless
conversion aronud conditional moves.

Fixes iree-org/iree#22181
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Codegen] arith.select doesn't need floating point emulation

4 participants