[Mlir-commits] [mlir] [MLIR][Arith] SelectOp fix invalid folding (PR #117555)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Mon Nov 25 05:25:55 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir-arith

Author: None (7FM)

<details>
<summary>Changes</summary>

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

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


1 Files Affected:

- (modified) mlir/lib/Dialect/Arith/IR/ArithOps.cpp (+2-1) 


``````````diff
diff --git a/mlir/lib/Dialect/Arith/IR/ArithOps.cpp b/mlir/lib/Dialect/Arith/IR/ArithOps.cpp
index 254f54d9e459e1..f2f23954d5c191 100644
--- a/mlir/lib/Dialect/Arith/IR/ArithOps.cpp
+++ b/mlir/lib/Dialect/Arith/IR/ArithOps.cpp
@@ -2314,7 +2314,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;
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/117555


More information about the Mlir-commits mailing list