[all-commits] [llvm/llvm-project] bf08d0: [flang] fix cg-rewrite DCE (#99653)
jeanPerier via All-commits
all-commits at lists.llvm.org
Mon Jul 22 03:51:51 PDT 2024
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: bf08d0e1182c94b6fe14b8915df6a7e5e755e5f2
https://github.com/llvm/llvm-project/commit/bf08d0e1182c94b6fe14b8915df6a7e5e755e5f2
Author: jeanPerier <jperier at nvidia.com>
Date: 2024-07-22 (Mon, 22 Jul 2024)
Changed paths:
M flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp
M flang/test/Fir/declare-codegen.fir
Log Message:
-----------
[flang] fix cg-rewrite DCE (#99653)
cg-rewrite runs regionDCE to get rid of the unused fir.shape/shift/slice
before codegen since those operations have no codegen.
I came across an issue where unreachable code would cause the pass to
fail with `error: loc(...): null operand found`.
It turns out `mlir::RegionDCE` does not work properly in presence of
unreachable code because it delete operations in reachable code that are
unused in reachable code, but still used in unreachable code (like the
constant in the added test case). It seems `mlir::RegionDCE` is always
run after `mlir::eraseUnreachableBlock` outside of this pass.
A solution could be to run `mlir::eraseUnreachableBlock` here or to try
modifying `mlir::RegionDCE`. But the current behavior may be
intentional, and both of these calls are actually quite expensive. For
instance, RegionDCE will does liveness analysis, and removes unused
block arguments, which is way more than what is needed here. I am not
very found of having this rather heavy transformation inside this pass
(they should be run after or before if they matter in the overall
pipeline).
Do a naïve backward deletion of the trivially dead operations instead.
It is cheaper, and works with unreachable code.
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list