[flang-commits] [flang] [FIR] Avoid generating llvm.undef for dummy scoping info (PR #128098)
via flang-commits
flang-commits at lists.llvm.org
Thu Feb 20 17:01:45 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-fir-hlfir
@llvm/pr-subscribers-flang-codegen
Author: Razvan Lupusoru (razvanlupusoru)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/128098.diff
1 Files Affected:
- (modified) flang/lib/Optimizer/CodeGen/CodeGen.cpp (+8)
``````````diff
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();
``````````
</details>
https://github.com/llvm/llvm-project/pull/128098
More information about the flang-commits
mailing list