Page MenuHomePhabricator

[ArgPromotion] Remove dead code produced by removing dead arguments
Needs RevisionPublic

Authored by jrbyrnes on Fri, Mar 17, 1:18 PM.

Details

Reviewers
arsenm
nikic
Summary

ArgPromotion currently produces phantom / dead loads. A good example of this is store-into-inself.ll. First, ArgPromo finds the promotable argument %p in @l. Then it inserts a load of %p in the caller, and passes instead the loaded value / transforms the function body. PromoteMem2Reg is able to optimize out the entire function body, resulting in an unused argument. In a subsequent doPromotion iteration, it removes the dead argument, resulting in a dead load in the caller. These dead loads may reduce effectiveness of other transformations (e.g. SimplifyCFG, MergedLoadStoreMotion).

This patch removes loads and geps that are made dead in the caller after removal of dead args.

Diff Detail

Unit TestsFailed

TimeTest
160 msx64 debian > Flang.Driver::code-gen-rv64.f90
Script: -- : 'RUN: at line 5'; rm -f /var/lib/buildkite-agent/builds/llvm-project/build/tools/flang/test/Driver/Output/code-gen-rv64.f90.tmp.o
120 msx64 debian > MLIR.Target/LLVMIR::llvmir-intrinsics.mlir
Script: -- : 'RUN: at line 1'; /var/lib/buildkite-agent/builds/llvm-project/build/bin/mlir-translate -mlir-to-llvmir /var/lib/buildkite-agent/builds/llvm-project/mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir | /var/lib/buildkite-agent/builds/llvm-project/build/bin/FileCheck /var/lib/buildkite-agent/builds/llvm-project/mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir

Event Timeline

jrbyrnes created this revision.Fri, Mar 17, 1:18 PM
Herald added a project: Restricted Project. · View Herald TranscriptFri, Mar 17, 1:18 PM
jrbyrnes requested review of this revision.Fri, Mar 17, 1:18 PM
Herald added a project: Restricted Project. · View Herald TranscriptFri, Mar 17, 1:18 PM
jrbyrnes edited the summary of this revision. (Show Details)Fri, Mar 17, 1:23 PM
nikic requested changes to this revision.Fri, Mar 17, 1:33 PM

Please add a PhaseOrdering test that demonstrates why it it useful to do this as part of ArgumentPromotion, rather than letting other passes clean this up.

llvm/lib/Transforms/IPO/ArgumentPromotion.cpp
282

This implementation looks too complicated. It should be enough to collect all potentially dead arguments and then call RecursivelyDeleteTriviallyDeadInstructionsPermissive() on the vector.

llvm/test/Transforms/ArgumentPromotion/propagate-remove-dead-args.ll
1

Add --function-signature or --version 2.

6

nounwind not needed?

32

fastcc not needed?

This revision now requires changes to proceed.Fri, Mar 17, 1:33 PM