[Mlir-commits] [mlir] b1c8447 - [mlir][SPIR-V] Fix swapped select operands in index.floordivs lowering (#214770)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Mon Aug 10 19:38:46 PDT 2026


Author: Arseniy Obolenskiy
Date: 2026-08-11T04:38:40+02:00
New Revision: b1c84470b1a8229c2f96631a8c9e6e1f1d835571

URL: https://github.com/llvm/llvm-project/commit/b1c84470b1a8229c2f96631a8c9e6e1f1d835571
DIFF: https://github.com/llvm/llvm-project/commit/b1c84470b1a8229c2f96631a8c9e6e1f1d835571.diff

LOG: [mlir][SPIR-V] Fix swapped select operands in index.floordivs lowering (#214770)

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

Added: 
    

Modified: 
    mlir/lib/Conversion/IndexToSPIRV/IndexToSPIRV.cpp
    mlir/test/Conversion/IndexToSPIRV/index-to-spirv.mlir

Removed: 
    


################################################################################
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, 
diff Sign, 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]]


        


More information about the Mlir-commits mailing list