-
Notifications
You must be signed in to change notification settings - Fork 13
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
Group constants for commutative ops #301
Conversation
auto lhs = op.getLhs(); | ||
auto rhs = op.getRhs(); | ||
|
||
auto lhsConst = lhs.template getDefiningOp<stablehlo::ConstantOp>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you do this as a matchPattern like for other constants above?
@@ -2922,6 +2922,56 @@ struct AddSimplify : public OpRewritePattern<mlir::stablehlo::AddOp> { | |||
} | |||
}; | |||
|
|||
// ((add x cst0) cst1) -> (add x1 (add cst0 cst1)) | |||
template <typename T> struct BinOpConstSimplify : public OpRewritePattern<T> { | |||
using OpRewritePattern<T>::OpRewritePattern; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should template this with a fastmath flag, since while this is always valid for ints, for floats this may violate IEEE standards
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I applied only to integers for now.
Enzyme-JAX/src/enzyme_ad/jax/Passes/EnzymeHLOOpt.cpp
Lines 2931 to 2933 in 06eb601
// Only apply to integers | |
if (!isa<IntegerType>(op.getType().getElementType())) | |
return failure(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair nuff, open an issue for extending to floats?
Closes #297.