[LV] Workaround PR49900 (a crash due to analyzing partially mutated IR)
authorPhilip Reames <listmail@philipreames.com>
Wed, 5 May 2021 16:55:09 +0000 (09:55 -0700)
committerPhilip Reames <listmail@philipreames.com>
Wed, 5 May 2021 16:56:28 +0000 (09:56 -0700)
commit80e8025083982f4eca8ca8200eafecf4a5c3ae6e
tree0ba6b61ff91838f0f5d807872cf903ae7fd24b17
parent95861216ac6558dc0dbcf638902feb9072c84661
[LV] Workaround PR49900 (a crash due to analyzing partially mutated IR)

LoopVectorize has a fairly deeply baked in design problem where it will try to query analysis (primarily SCEV, but also ValueTracking) in the midst of mutating IR. In particular, the intermediate IR state does not represent the semantics of the original (or final) program.

Fixing this for real is hard, but all of the cases seen so far share a common symptom. In cases seen to date, the analysis being queried is the computation of the original loop's trip count. We can fix this particular instance of the issue by simply computing the trip count early, and caching it.

I want to be really clear that this is nothing but a workaround. It does nothing to fix the root issue, and at best, delays the time until we have to fix this for real. Florian and I have discussed an eventual solution in the review comments for https://reviews.llvm.org/D100663, but it's a lot of work.

Test taken from https://reviews.llvm.org/D100663.

Differential Revision: https://reviews.llvm.org/D101487
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
llvm/test/Transforms/LoopVectorize/scev-during-mutation.ll [new file with mode: 0644]