[Mlir-commits] [mlir] [mlir][arith] Canonicalization patterns for `arith.select` (PR #67809)
Matthias Springer
llvmlistbot at llvm.org
Thu Oct 5 09:15:52 PDT 2023
================
@@ -233,6 +233,50 @@ def CmpIExtUI :
CPred<"$0.getValue() == arith::CmpIPredicate::eq || "
"$0.getValue() == arith::CmpIPredicate::ne">> $pred)]>;
+//===----------------------------------------------------------------------===//
+// SelectOp
+//===----------------------------------------------------------------------===//
+
+// select(not(pred), a, b) => select(pred, b, a)
+def SelectNotCond :
+ Pat<(SelectOp (Arith_XOrIOp $pred, (ConstantLikeMatcher APIntAttr:$ones)), $a, $b),
+ (SelectOp $pred, $b, $a),
+ [(IsScalarOrSplatNegativeOne $ones)]>;
+
+// select(pred, select(pred, a, b), c) => select(pred, a, c)
+def RedundantSelectTrue :
+ Pat<(SelectOp $pred, (SelectOp $pred, $a, $b), $c),
+ (SelectOp $pred, $a, $c)>;
+
+// select(pred, a, select(pred, b, c)) => select(pred, a, c)
+def RedundantSelectFalse :
+ Pat<(SelectOp $pred, $a, (SelectOp $pred, $b, $c)),
+ (SelectOp $pred, $a, $c)>;
+
+// select(predA, select(predB, a, b), b) => select(and(predA, predB), a, b)
+def SelectAndCond :
+ Pat<(SelectOp $predA, (SelectOp $predB, $a, $b), $b),
+ (SelectOp (Arith_AndIOp $predA, $predB), $a, $b)>;
+
+// select(predA, select(predB, b, a), b) => select(and(predA, not(predB)), a, b)
----------------
matthias-springer wrote:
Can you rename the variables such that they have different letters? E.g., having both `predA` and `a` makes it harder to read.
https://github.com/llvm/llvm-project/pull/67809
More information about the Mlir-commits
mailing list