|
MLIR 24.0.0git
|
select(M, F(a0, a1, ..., a_n), F(b0, b1, ..., b_n)) -> F(select(M, a0, b0), select(M, a1, b1), ...) for pure and elementwise F. More...
Public Member Functions | |
| LogicalResult | matchAndRewrite (arith::SelectOp op, PatternRewriter &rewriter) const override |
| Public Member Functions inherited from mlir::OpRewritePattern< arith::SelectOp > | |
| OpRewritePattern (MLIRContext *context, PatternBenefit benefit=1, ArrayRef< StringRef > generatedNames={}) | |
| Patterns must specify the root operation name they match against, and can also specify the benefit of the pattern matching and a list of generated ops. | |
| Public Member Functions inherited from mlir::detail::OpOrInterfaceRewritePatternBase< arith::SelectOp > | |
| LogicalResult | matchAndRewrite (Operation *op, PatternRewriter &rewriter) const final |
| Wrapper around the RewritePattern method that passes the derived op type. | |
| Public Member Functions inherited from mlir::RewritePattern | |
| virtual | ~RewritePattern ()=default |
| Public Member Functions inherited from mlir::Pattern | |
| ArrayRef< OperationName > | getGeneratedOps () const |
| Return a list of operations that may be generated when rewriting an operation instance with this pattern. | |
| std::optional< OperationName > | getRootKind () const |
| Return the root node that this pattern matches. | |
| std::optional< TypeID > | getRootInterfaceID () const |
| Return the interface ID used to match the root operation of this pattern. | |
| std::optional< TypeID > | getRootTraitID () const |
| Return the trait ID used to match the root operation of this pattern. | |
| PatternBenefit | getBenefit () const |
| Return the benefit (the inverse of "cost") of matching this pattern. | |
| bool | hasBoundedRewriteRecursion () const |
| Returns true if this pattern is known to result in recursive application, i.e. | |
| MLIRContext * | getContext () const |
| Return the MLIRContext used to create this pattern. | |
| StringRef | getDebugName () const |
| Return a readable name for this pattern. | |
| void | setDebugName (StringRef name) |
| Set the human readable debug name used for this pattern. | |
| ArrayRef< StringRef > | getDebugLabels () const |
| Return the set of debug labels attached to this pattern. | |
| void | addDebugLabels (ArrayRef< StringRef > labels) |
| Add the provided debug labels to this pattern. | |
| void | addDebugLabels (StringRef label) |
Additional Inherited Members | |
| Public Types inherited from mlir::OpRewritePattern< arith::SelectOp > | |
| using | Base |
| Type alias to allow derived classes to inherit constructors with using Base::Base;. | |
| Static Public Member Functions inherited from mlir::RewritePattern | |
| template<typename T, typename... Args> | |
| static std::unique_ptr< T > | create (Args &&...args) |
| This method provides a convenient interface for creating and initializing derived rewrite patterns of the given type T. | |
| Protected Member Functions inherited from mlir::RewritePattern | |
| Pattern (StringRef rootName, PatternBenefit benefit, MLIRContext *context, ArrayRef< StringRef > generatedNames={}) | |
| Inherit the base constructors from Pattern. | |
| Pattern (MatchAnyOpTypeTag tag, PatternBenefit benefit, MLIRContext *context, ArrayRef< StringRef > generatedNames={}) | |
| Inherit the base constructors from Pattern. | |
| Pattern (MatchInterfaceOpTypeTag tag, TypeID interfaceID, PatternBenefit benefit, MLIRContext *context, ArrayRef< StringRef > generatedNames={}) | |
| Inherit the base constructors from Pattern. | |
| Pattern (MatchTraitOpTypeTag tag, TypeID traitID, PatternBenefit benefit, MLIRContext *context, ArrayRef< StringRef > generatedNames={}) | |
| Inherit the base constructors from Pattern. | |
| Protected Member Functions inherited from mlir::Pattern | |
| Pattern (StringRef rootName, PatternBenefit benefit, MLIRContext *context, ArrayRef< StringRef > generatedNames={}) | |
| Construct a pattern with a certain benefit that matches the operation with the given root name. | |
| Pattern (MatchAnyOpTypeTag tag, PatternBenefit benefit, MLIRContext *context, ArrayRef< StringRef > generatedNames={}) | |
| Construct a pattern that may match any operation type. | |
| Pattern (MatchInterfaceOpTypeTag tag, TypeID interfaceID, PatternBenefit benefit, MLIRContext *context, ArrayRef< StringRef > generatedNames={}) | |
| Construct a pattern that may match any operation that implements the interface defined by the provided interfaceID. | |
| Pattern (MatchTraitOpTypeTag tag, TypeID traitID, PatternBenefit benefit, MLIRContext *context, ArrayRef< StringRef > generatedNames={}) | |
| Construct a pattern that may match any operation that implements the trait defined by the provided traitID. | |
| void | setHasBoundedRewriteRecursion (bool hasBoundedRecursionArg=true) |
| Set the flag detailing if this pattern has bounded rewrite recursion or not. | |
select(M, F(a0, a1, ..., a_n), F(b0, b1, ..., b_n)) -> F(select(M, a0, b0), select(M, a1, b1), ...) for pure and elementwise F.
Correctness provement:
Let's discuss the cases ignoring poison first.
As F is elementwise, we have
F(a1, a2, ..., a_n)[p] = F(a1[p], a2[p], ..., a_n[p])
then for
L = select(M, F(a0, a1, ..., a_n), F(b0, b1, ..., b_n)) R = F(select(M, a0, b0), select(M, a1, b1), ....)
for any position p, we have:
if M[p] == true, then L[p] == F(a)[p] == F(a[p]) == F(select(true, a[p], b[p])) == R[p] if M[p] == false, then L[p] == F(b)[p] == F(b[p]) == F(select(false, a[p], b[p])) == R[p]
And F is pure, so that we can move and reduce F. So select(M, F(a0, a1, ..., a_n), F(b0, b1, ..., b_n)) is equal to F(select(M, a0, b0), select(M, a1, b1), ...) ignoring poison.
Let's consider the poison value now. ArithBase.td says:
Unless otherwise stated, the operations within this dialect propagate poison values, i.e., if any of its inputs are poison, then the output is poison.
So most F, F(poison) = poison
Then for any position p, if a[p] is poison
if M[p] == true, L[p] == f(a[p]) == poison == F(select(true, a[p], b[p])) == R[p] if M[p] == false, L[p] == f(b[p]) == F(select(false, a[p], b[p])) == R[p] if M[p] == P, L[p] == poison == F(select(P, a, b)) == R[p]
Then the transformation doesn't change poison propagation.
For F which doesn't meet the assumption, this transformation may change the poison propagation, but the language allows us to replace poison with a undef or any value with the same type. So this is still valid transformation.
Definition at line 3215 of file ArithOps.cpp.
|
inlineoverride |
Definition at line 3218 of file ArithOps.cpp.
References b, mlir::OpBuilder::clone(), mlir::RewriterBase::eraseOp(), mlir::Builder::getI1Type(), mlir::Operation::getResults(), mlir::OperationEquivalence::IgnoreLocations, mlir::OperationEquivalence::ignoreValueEquivalence(), inserted(), mlir::OperationEquivalence::isEquivalentTo(), mlir::isPure(), mlir::Type::isSignlessInteger(), mlir::RewriterBase::replaceOp(), mlir::Operation::setOperands(), and success().