Skip to content

Conversation

@lei137
Copy link
Contributor

@lei137 lei137 commented Jun 23, 2025

This reverts commit 823750d.

Test causes segfault on aix flang builder.

@llvmbot llvmbot added flang Flang issues not falling into any other category flang:fir-hlfir labels Jun 23, 2025
@llvmbot
Copy link
Member

llvmbot commented Jun 23, 2025

@llvm/pr-subscribers-flang-fir-hlfir

Author: Lei Huang (lei137)

Changes

This reverts commit 823750d.

Test causes segfault on aix flang builder.


Full diff: https://github.com/llvm/llvm-project/pull/145345.diff

2 Files Affected:

  • (modified) flang/lib/Optimizer/Transforms/FIRToSCF.cpp (+2-37)
  • (removed) flang/test/Fir/FirToSCF/if.fir (-56)
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
-}

@kiranchandramohan
Copy link
Contributor

@StarryCSF

Failing on an M1 Mac as well.

Copy link
Contributor

@kiranchandramohan kiranchandramohan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG.

@lei137 lei137 merged commit d715ecb into llvm:main Jun 23, 2025
10 checks passed
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.
@lei137 lei137 deleted the firToscfCore branch September 5, 2025 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flang:fir-hlfir flang Flang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants