-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Revert "[flang][fir] Add fir.if -> scf.if and add filecheck test … (#142965)" #145345
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…llvm#142965)" This reverts commit 823750d.
@llvm/pr-subscribers-flang-fir-hlfir Author: Lei Huang (lei137) ChangesThis reverts commit 823750d. Test causes segfault on aix flang builder. Full diff: https://github.com/llvm/llvm-project/pull/145345.diff 2 Files Affected:
diff --git a/flang/lib/Optimizer/Transforms/FIRToSCF.cpp b/flang/lib/Optimizer/Transforms/FIRToSCF.cpp
index 9a0071a6c6ae6..f06ad2db90d55 100644
--- a/flang/lib/Optimizer/Transforms/FIRToSCF.cpp
+++ b/flang/lib/Optimizer/Transforms/FIRToSCF.cpp
@@ -87,48 +87,13 @@ struct DoLoopConversion : public OpRewritePattern<fir::DoLoopOp> {
return success();
}
};
-
-struct IfConversion : public OpRewritePattern<fir::IfOp> {
- using OpRewritePattern<fir::IfOp>::OpRewritePattern;
- LogicalResult matchAndRewrite(fir::IfOp ifOp,
- PatternRewriter &rewriter) const override {
- mlir::Location loc = ifOp.getLoc();
- mlir::detail::TypedValue<mlir::IntegerType> condition = ifOp.getCondition();
- ValueTypeRange<ResultRange> resultTypes = ifOp.getResultTypes();
- mlir::scf::IfOp scfIfOp = rewriter.create<scf::IfOp>(
- loc, resultTypes, condition, !ifOp.getElseRegion().empty());
- // then region
- scfIfOp.getThenRegion().takeBody(ifOp.getThenRegion());
- Block &scfThenBlock = scfIfOp.getThenRegion().front();
- Operation *scfThenTerminator = scfThenBlock.getTerminator();
- // fir.result->scf.yield
- rewriter.setInsertionPointToEnd(&scfThenBlock);
- rewriter.replaceOpWithNewOp<scf::YieldOp>(scfThenTerminator,
- scfThenTerminator->getOperands());
-
- // else region
- if (!ifOp.getElseRegion().empty()) {
- scfIfOp.getElseRegion().takeBody(ifOp.getElseRegion());
- mlir::Block &elseBlock = scfIfOp.getElseRegion().front();
- mlir::Operation *elseTerminator = elseBlock.getTerminator();
-
- rewriter.setInsertionPointToEnd(&elseBlock);
- rewriter.replaceOpWithNewOp<scf::YieldOp>(elseTerminator,
- elseTerminator->getOperands());
- }
-
- scfIfOp->setAttrs(ifOp->getAttrs());
- rewriter.replaceOp(ifOp, scfIfOp);
- return success();
- }
-};
} // namespace
void FIRToSCFPass::runOnOperation() {
RewritePatternSet patterns(&getContext());
- patterns.add<DoLoopConversion, IfConversion>(patterns.getContext());
+ patterns.add<DoLoopConversion>(patterns.getContext());
ConversionTarget target(getContext());
- target.addIllegalOp<fir::DoLoopOp, fir::IfOp>();
+ target.addIllegalOp<fir::DoLoopOp>();
target.markUnknownOpDynamicallyLegal([](Operation *) { return true; });
if (failed(
applyPartialConversion(getOperation(), target, std::move(patterns))))
diff --git a/flang/test/Fir/FirToSCF/if.fir b/flang/test/Fir/FirToSCF/if.fir
deleted file mode 100644
index 9e43cf1cd11d0..0000000000000
--- a/flang/test/Fir/FirToSCF/if.fir
+++ /dev/null
@@ -1,56 +0,0 @@
-// RUN: fir-opt %s --fir-to-scf | FileCheck %s
-
-// CHECK: func.func @test_only(%[[ARG0:.*]]: i1, %[[ARG1:.*]]: i32) {
-// CHECK: scf.if %[[ARG0:.*]] {
-// CHECK: %[[VAL_1:.*]] = arith.addi %[[ARG1:.*]], %[[ARG1:.*]] : i32
-// CHECK: }
-// CHECK: return
-// CHECK: }
-func.func @test_only(%arg0 : i1, %arg1 : i32) {
- fir.if %arg0 {
- %0 = arith.addi %arg1, %arg1 : i32
- }
- return
-}
-
-// CHECK: func.func @test_else() {
-// CHECK: %[[VAL_1:.*]] = arith.constant false
-// CHECK: %[[VAL_2:.*]] = arith.constant 2 : i32
-// CHECK: scf.if %[[VAL_1:.*]] {
-// CHECK: %[[VAL_3:.*]] = arith.constant 3 : i32
-// CHECK: } else {
-// CHECK: %[[VAL_3:.*]] = arith.constant 3 : i32
-// CHECK: }
-// CHECK: return
-// CHECK: }
-func.func @test_else() {
- %false = arith.constant false
- %1 = arith.constant 2 : i32
- fir.if %false {
- %2 = arith.constant 3 : i32
- } else {
- %3 = arith.constant 3 : i32
- }
- return
-}
-
-// CHECK-LABEL: func.func @test_two_result() {
-// CHECK: %[[VAL_1:.*]] = arith.constant 2.000000e+00 : f32
-// CHECK: %[[VAL_2:.*]] = arith.constant false
-// CHECK: %[[RES:[0-9]+]]:2 = scf.if %[[VAL_2:.*]] -> (f32, f32) {
-// CHECK: scf.yield %[[VAL_1:.*]], %[[VAL_1:.*]] : f32, f32
-// CHECK: } else {
-// CHECK: scf.yield %[[VAL_1:.*]], %[[VAL_1:.*]] : f32, f32
-// CHECK: }
-// CHECK: return
-// CHECK: }
-func.func @test_two_result() {
- %1 = arith.constant 2.0 : f32
- %cmp = arith.constant false
- %x, %y = fir.if %cmp -> (f32, f32) {
- fir.result %1, %1 : f32, f32
- } else {
- fir.result %1, %1 : f32, f32
- }
- return
-}
|
Failing on an M1 Mac as well. |
kiranchandramohan
approved these changes
Jun 23, 2025
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.
LG.
DrSergei
pushed a commit
to DrSergei/llvm-project
that referenced
this pull request
Jun 24, 2025
…lvm#142965)" (llvm#145345) This reverts commit 823750d. Test causes segfault on aix flang builder.
anthonyhatran
pushed a commit
to anthonyhatran/llvm-project
that referenced
this pull request
Jun 26, 2025
…lvm#142965)" (llvm#145345) This reverts commit 823750d. Test causes segfault on aix flang builder.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This reverts commit 823750d.
Test causes segfault on aix flang builder.