[flang-commits] [flang] f27081b - [FIR] Avoid generating llvm.undef for dummy scoping info (#128098)

via flang-commits flang-commits at lists.llvm.org
Thu Feb 20 18:49:26 PST 2025


Author: Razvan Lupusoru
Date: 2025-02-20T18:49:23-08:00
New Revision: f27081ba6a12685b403181e51a00a3d6f3360ca5

URL: https://github.com/llvm/llvm-project/commit/f27081ba6a12685b403181e51a00a3d6f3360ca5
DIFF: https://github.com/llvm/llvm-project/commit/f27081ba6a12685b403181e51a00a3d6f3360ca5.diff

LOG: [FIR] Avoid generating llvm.undef for dummy scoping info (#128098)

Dummy scoping operations are generated to keep track of scopes for
purpose of Fortran level analyses like Alias Analysis. For codegen, the
scoping info is converted to a fir.undef during pre-codegen rewrite.
Then during declare lowering, this info is no longer used - but it is
still translated to llvm.undef. I cleaned up so it is simply erased. The
generated LLVM should now no longer have a stray undef which looks off
when trying to make sense of the IR.

Co-authored-by: Razvan Lupusoru <rlupusoru at nvidia.com>

Added: 
    

Modified: 
    flang/lib/Optimizer/CodeGen/CodeGen.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Optimizer/CodeGen/CodeGen.cpp b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
index 439cc7a856236..bd87215eeb179 100644
--- a/flang/lib/Optimizer/CodeGen/CodeGen.cpp
+++ b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
@@ -3575,6 +3575,14 @@ struct UndefOpConversion : public fir::FIROpConversion<fir::UndefOp> {
   llvm::LogicalResult
   matchAndRewrite(fir::UndefOp undef, OpAdaptor,
                   mlir::ConversionPatternRewriter &rewriter) const override {
+    if (mlir::isa<fir::DummyScopeType>(undef.getType())) {
+      // Dummy scoping is used for Fortran analyses like AA. Once it gets to
+      // pre-codegen rewrite it is erased and a fir.undef is created to
+      // feed to the fir declare operation. Thus, during codegen, we can
+      // simply erase is as it is no longer used.
+      rewriter.eraseOp(undef);
+      return mlir::success();
+    }
     rewriter.replaceOpWithNewOp<mlir::LLVM::UndefOp>(
         undef, convertType(undef.getType()));
     return mlir::success();


        


More information about the flang-commits mailing list