Sometimes LegalizeTypes knows about common subexpressions before SelectionDAG
does, leading to accidental SDValue removal before its reference count was
truly zero.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Looks OK to me, but I'm not that familiar with the legalizer.
llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp | ||
---|---|---|
191 | Nit: for (auto const &I: ReplacedValues) | |
llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h | ||
204–205 | Do we need an assert at the beginning of the loop that Old != New? Otherwise we may be removing a valid map entry. |
llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h | ||
---|---|---|
204–205 | Good idea. I believe that would only happen for an RAUW(N, N), which the DAGUpdateListener call sites guarantee won't happen. |
llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp | ||
---|---|---|
191 | Don't you need to wrap the whole for loop inside #ifndef NDEBUG. Otherwise I would be a def without any uses in a no-assert build. Looking at the for loop above there is no such protection for UI (but maybe that is because UI is incremented in the loop). I wouldn't mind if you added #ifndef NDEBUG around both loops, as they only make sense when the asserts are active. |
llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp | ||
---|---|---|
191 | Good catch! |
Reverted this in 3ce77142a6452d76d6f97c9a6c2da193e78841ba because one of the new assertions failed in the expensive-checks bots: http://lab.llvm.org:8011/builders/llvm-clang-x86_64-expensive-checks-debian/builds/4971/steps/test-check-all/logs/FAIL%3A%20LLVM%3A%3A2008-12-02-IllegalResultType.ll
This patch removes that check, which apparently wasn't correct.
@bjope are you happy with me re-landing this with that new assert dropped? Looks like that case is properly covered earlier in PerformExpensiveChecks() anyway.
Do we need an assert at the beginning of the loop that Old != New? Otherwise we may be removing a valid map entry.