-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[mlir][arith] Canonicalization patterns for arith.select
#67809
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, x, y), y) => select(and(predA, predB), x, y) | ||
def SelectAndCond : | ||
Pat<(SelectOp $predA, (SelectOp $predB, $x, $y), $y), | ||
(SelectOp (Arith_AndIOp $predA, $predB), $x, $y)>; | ||
|
||
// select(predA, select(predB, y, x), y) => select(and(predA, not(predB)), x, y) | ||
def SelectAndNotCond : | ||
Pat<(SelectOp $predA, (SelectOp $predB, $y, $x), $y), | ||
(SelectOp (Arith_AndIOp $predA, | ||
(Arith_XOrIOp $predB, (Arith_ConstantOp ConstantAttr<I1Attr, "1">))), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI, this is wrong because it could be vector of i1 types, e.g., vector<4xi1>. This patch introduces failure in downstream project (e.g., IREE). I'm working on a fix now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is a failure example:
|
||
$x, $y)>; | ||
|
||
// select(predA, x, select(predB, x, y)) => select(or(predA, predB), x, y) | ||
def SelectOrCond : | ||
Pat<(SelectOp $predA, $x, (SelectOp $predB, $x, $y)), | ||
(SelectOp (Arith_OrIOp $predA, $predB), $x, $y)>; | ||
|
||
// select(predA, x, select(predB, y, x)) => select(or(predA, not(predB)), x, y) | ||
def SelectOrNotCond : | ||
Pat<(SelectOp $predA, $x, (SelectOp $predB, $y, $x)), | ||
(SelectOp (Arith_OrIOp $predA, | ||
(Arith_XOrIOp $predB, (Arith_ConstantOp ConstantAttr<I1Attr, "1">))), | ||
$x, $y)>; | ||
|
||
//===----------------------------------------------------------------------===// | ||
// IndexCastOp | ||
//===----------------------------------------------------------------------===// | ||
|
Uh oh!
There was an error while loading. Please reload this page.