[Mlir-commits] [mlir] [mlir][SPIR-V] Fix swapped select operands in index.floordivs lowering (PR #214770)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Aug 7 08:12:23 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-spirv
Author: Arseniy Obolenskiy (aobolensk)
<details>
<summary>Changes</summary>
Fix ConvertIndexFloorDivSPattern to select `negRes` when `cmp` is true
Previously operands were reversed, producing the wrong sign for the floordiv result whenever the negative result branch should've been taken
---
Full diff: https://github.com/llvm/llvm-project/pull/214770.diff
2 Files Affected:
- (modified) mlir/lib/Conversion/IndexToSPIRV/IndexToSPIRV.cpp (+1-1)
- (modified) mlir/test/Conversion/IndexToSPIRV/index-to-spirv.mlir (+1-1)
``````````diff
diff --git a/mlir/lib/Conversion/IndexToSPIRV/IndexToSPIRV.cpp b/mlir/lib/Conversion/IndexToSPIRV/IndexToSPIRV.cpp
index 9718361d4c4ba..92526da965157 100644
--- a/mlir/lib/Conversion/IndexToSPIRV/IndexToSPIRV.cpp
+++ b/mlir/lib/Conversion/IndexToSPIRV/IndexToSPIRV.cpp
@@ -228,7 +228,7 @@ struct ConvertIndexFloorDivSPattern final : OpConversionPattern<FloorDivSOp> {
Value nNonZero = spirv::INotEqualOp::create(rewriter, loc, n, zero);
Value cmp = spirv::LogicalAndOp::create(rewriter, loc, diffSign, nNonZero);
- rewriter.replaceOpWithNewOp<spirv::SelectOp>(op, cmp, posRes, negRes);
+ rewriter.replaceOpWithNewOp<spirv::SelectOp>(op, cmp, negRes, posRes);
return success();
}
};
diff --git a/mlir/test/Conversion/IndexToSPIRV/index-to-spirv.mlir b/mlir/test/Conversion/IndexToSPIRV/index-to-spirv.mlir
index 650c030d80f55..2d00adff2e8ba 100644
--- a/mlir/test/Conversion/IndexToSPIRV/index-to-spirv.mlir
+++ b/mlir/test/Conversion/IndexToSPIRV/index-to-spirv.mlir
@@ -141,7 +141,7 @@ func.func @floordivs(%n: index, %m: index) -> index {
// CHECK: %[[N_NON_ZERO:.*]] = spirv.INotEqual %[[N]], %[[ZERO]]
// CHECK: %[[CMP:.*]] = spirv.LogicalAnd %[[DIFF_SIGN]], %[[N_NON_ZERO]]
- // CHECK: %[[RESULT:.*]] = spirv.Select %[[CMP]], %[[POS_RES]], %[[NEG_RES]]
+ // CHECK: %[[RESULT:.*]] = spirv.Select %[[CMP]], %[[NEG_RES]], %[[POS_RES]]
%result = index.floordivs %n, %m
// %[[RESULTI:.*] = builtin.unrealized_conversion_cast %[[RESULT]]
``````````
</details>
https://github.com/llvm/llvm-project/pull/214770
More information about the Mlir-commits
mailing list