Subgraph rewrites for trivial arithmetic operations: #9018
+955
−46
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Subgraph rewrites for trivial arithmetic operations:
add(a, neg(b)),add(neg(a), b), orsub(a, neg(b))withsub(a, b),sub(b, a), oradd(a, b), respectively,mul(neg(a), neg(b))ordiv(neg(a), neg(b))withmul(a, b)ordiv(a, b), respectively,mul(x, 1.0),div(x, 1.0),add(x, 0.0), orsub(x, 0.0)withx,mul(x, 0.0f),div(0.0f, x)with a static zero.div(x, x)orsub(x, x)with a static one or zero, respectively.To make identifying and propagating these cases easier (e.g. propagating the dynamic shapes of the output), this change introduces two new
xnn_valueflags:XNN_VALUE_FLAG_IS_ZERO, andXNN_VALUE_FLAG_IS_ONE.These flags are initially attached to static scalar values that are zero and one, respectively, and then propagated through the nodes of the subgraph.