-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[flang] Avoid optimizing min and max if not valid type #134972
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
Conversation
@llvm/pr-subscribers-flang-fir-hlfir Author: Miguel Saldivar (Saldivarcher) ChangesIn Fix for #134308 Full diff: https://github.com/llvm/llvm-project/pull/134972.diff 1 Files Affected:
diff --git a/flang/lib/Optimizer/HLFIR/Transforms/OptimizedBufferization.cpp b/flang/lib/Optimizer/HLFIR/Transforms/OptimizedBufferization.cpp
index 96a3622f4afee..cb3894965f9aa 100644
--- a/flang/lib/Optimizer/HLFIR/Transforms/OptimizedBufferization.cpp
+++ b/flang/lib/Optimizer/HLFIR/Transforms/OptimizedBufferization.cpp
@@ -988,8 +988,15 @@ class ReductionConversion : public mlir::OpRewritePattern<Op> {
op, "Currently minloc/maxloc is not handled");
} else if constexpr (std::is_same_v<Op, hlfir::MaxvalOp> ||
std::is_same_v<Op, hlfir::MinvalOp>) {
+ auto ty = op.getType();
+ if (!(mlir::isa<mlir::FloatType>(ty) ||
+ mlir::isa<mlir::IntegerType>(ty))) {
+ return rewriter.notifyMatchFailure(
+ op, "Type is not supported for Maxval or Minval yet");
+ }
+
bool isMax = std::is_same_v<Op, hlfir::MaxvalOp>;
- init = makeMinMaxInitValGenerator(isMax)(builder, loc, op.getType());
+ init = makeMinMaxInitValGenerator(isMax)(builder, loc, ty);
genBodyFn = [inlineSource, isMax](
fir::FirOpBuilder builder, mlir::Location loc,
mlir::Value reduction,
|
Note, I need to add a test. First time working here, so still learning! |
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.
Thank you for fixing this. The change looks good to me once you have added a test.
I would test this by checking that hlfir.minval etc are not modified by the pass for a few types that aren't integers or floating point. See flang/test/HLFIR/minval-elemental.fir
for an example test for this pass.
flang/lib/Optimizer/HLFIR/Transforms/OptimizedBufferization.cpp
Outdated
Show resolved
Hide resolved
In `makeMinMaxInitValGenerator` it explicitly checks for only `FloatType` and `IntegerType`, so we shouldn't match if we don't have either of those types.
1707b84
to
9cbacb6
Compare
Since |
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.
LGTM. Thanks for the update. Feel free to merge without another round of review.
nit: Please could you also test minval in the same way.
@tblah I actually don't have commit access, can you merge for me please. Thanks again for reviewing this PR btw 👍 |
In `makeMinMaxInitValGenerator` it explicitly checks for only `FloatType` and `IntegerType`, so we shouldn't match if we don't have either of those types. Fix for llvm#134308
In
makeMinMaxInitValGenerator
it explicitly checks for onlyFloatType
andIntegerType
, so we shouldn't match if we don't have either of those types.Fix for #134308