[Mlir-commits] [mlir] 619e4b7 - [MLIR][Arith] SelectOp fix invalid folding (#117555)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Tue Nov 26 06:11:04 PST 2024
Author: 7FM
Date: 2024-11-26T09:11:00-05:00
New Revision: 619e4b7154606f315572ba54c0fe6c1f6c8848a0
URL: https://github.com/llvm/llvm-project/commit/619e4b7154606f315572ba54c0fe6c1f6c8848a0
DIFF: https://github.com/llvm/llvm-project/commit/619e4b7154606f315572ba54c0fe6c1f6c8848a0.diff
LOG: [MLIR][Arith] SelectOp fix invalid folding (#117555)
The pattern `select %x, true, false => %x` is only valid in case that
the return type is identical to the type of `%x` (i.e., i1). Hence, the
check `isInteger(1)` was replaced with `isSignlessInteger(1)`.
Fixes: https://github.com/llvm/llvm-project/issues/117554
Added:
Modified:
mlir/lib/Dialect/Arith/IR/ArithOps.cpp
mlir/test/Dialect/Arith/canonicalize.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/Arith/IR/ArithOps.cpp b/mlir/lib/Dialect/Arith/IR/ArithOps.cpp
index 47766f36ad05cf..16b4e8eb4f022c 100644
--- a/mlir/lib/Dialect/Arith/IR/ArithOps.cpp
+++ b/mlir/lib/Dialect/Arith/IR/ArithOps.cpp
@@ -2322,7 +2322,8 @@ OpFoldResult arith::SelectOp::fold(FoldAdaptor adaptor) {
return trueVal;
// select %x, true, false => %x
- if (getType().isInteger(1) && matchPattern(adaptor.getTrueValue(), m_One()) &&
+ if (getType().isSignlessInteger(1) &&
+ matchPattern(adaptor.getTrueValue(), m_One()) &&
matchPattern(adaptor.getFalseValue(), m_Zero()))
return condition;
diff --git a/mlir/test/Dialect/Arith/canonicalize.mlir b/mlir/test/Dialect/Arith/canonicalize.mlir
index f56bf0980b13c1..1d4d5fc6f8319a 100644
--- a/mlir/test/Dialect/Arith/canonicalize.mlir
+++ b/mlir/test/Dialect/Arith/canonicalize.mlir
@@ -54,6 +54,18 @@ func.func @select_extui_i1(%arg0: i1) -> i1 {
return %res : i1
}
+// CHECK-LABEL: @select_no_fold_ui1
+// CHECK: %[[CONST_0:.+]] = "test.constant"() <{value = 0 : i32}> : () -> ui1
+// CHECK: %[[CONST_1:.+]] = "test.constant"() <{value = 1 : i32}> : () -> ui1
+// CHECK-NEXT: %[[RES:.+]] = arith.select %arg0, %[[CONST_1]], %[[CONST_0]] : ui1
+// CHECK-NEXT: return %[[RES]]
+func.func @select_no_fold_ui1(%arg0: i1) -> ui1 {
+ %c0_i1 = "test.constant"() {value = 0 : i32} : () -> ui1
+ %c1_i1 = "test.constant"() {value = 1 : i32} : () -> ui1
+ %res = arith.select %arg0, %c1_i1, %c0_i1 : ui1
+ return %res : ui1
+}
+
// CHECK-LABEL: @select_cst_false_scalar
// CHECK-SAME: (%[[ARG0:.+]]: i32, %[[ARG1:.+]]: i32)
// CHECK-NEXT: return %[[ARG1]]
More information about the Mlir-commits
mailing list