A store to an object whose lifetime is about to end can be removed.
See PR40550 for motivation.
Paths
| Differential D57541
[DAGCombiner] Eliminate dead stores to stack. ClosedPublic Authored by courbet on Jan 31 2019, 1:32 PM.
Details Summary A store to an object whose lifetime is about to end can be removed. See PR40550 for motivation.
Diff Detail
Event TimelineHerald added subscribers: llvm-commits, Petar.Avramovic, jsji and 38 others. · View Herald Transcript courbet removed reviewers: • espindola, andreadb, alexander-shaposhnikov, serge-sans-paille, rupprecht.Jan 31 2019, 1:34 PM courbet removed reviewers: • espindola, andreadb, alexander-shaposhnikov, serge-sans-paille, rupprecht.Jan 31 2019, 1:37 PM courbet marked an inline comment as done. courbet added inline comments.
Comment Actions I just realized that there is nothing that guarantees that an alloca's lifetime is ended in one go, so I'll also have to check that the store is within the lifetime.end base and size. Comment Actions
Yes. You should use the BaseIndexOffset alias framework here. Also, you'll need to deal with the additional output from indexed stores. We should probably also add this some LIFETIME nodes casing to FindBetterChains and improve LIFETIME_END's chain so we can deal with overlapping lifetimes. Comment Actions Only remove stores to dead stack space when they are fully contained inside the Comment Actions
I think I'm fine because of the hasOneUse() check. I'm not sure how I should test this though, do you have a suggestion for some test IR for an indexed store ? Comment Actions
I believe the CombineTo will fail from too few values on indexed stores, even if the value isn't used. Better to check isIndexed() or do the unfolding back to an ADD/SUB. I suspect the only way this would trigger currently is if an intrinsic lowers into an indexed store in ARM or AArch64.
Comment Actions
courbet marked 4 inline comments as done. Comment Actions
Comment Actions LGTM, modulo potentially excising the hasOneUse as I've suggested provided you agree with my line of reasoning there.
This revision is now accepted and ready to land.Feb 7 2019, 7:06 AM courbet added inline comments.
Comment Actions
Closed by commit rL354244: [DAGCombiner] Eliminate dead stores to stack. (authored by courbet). · Explain WhyFeb 17 2019, 11:58 PM This revision was automatically updated to reflect the committed changes.
Comment Actions I finally had time to track this down. The issue was that we were missing a hasOneUse() check on the chain (we were only checking it on the store itself), so there could be other nodes dependind on the store (typically through tokenfactors), e.g. store ----> TF ---> LIFETIME_END \-----> some_user We were deleting the store...
Revision Contents
Diff 187193 llvm/trunk/include/llvm/CodeGen/SelectionDAG.h
llvm/trunk/include/llvm/CodeGen/SelectionDAGAddressAnalysis.h
llvm/trunk/include/llvm/CodeGen/SelectionDAGNodes.h
llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGAddressAnalysis.cpp
llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp
llvm/trunk/test/CodeGen/BPF/remove_truncate_5.ll
llvm/trunk/test/CodeGen/X86/swap.ll
llvm/trunk/test/DebugInfo/COFF/inlining.ll
llvm/trunk/test/DebugInfo/COFF/lexicalblock.ll
|
Ahha! We never add the lifetime to the Alias list like we should if we dont' skip past it. I suspect this is why we had to revert this patch.