In this case, AutoTypes.FindNodeOrInsertPos found appropriate AT
value and should return that directly, however before this patch we
assumed that it always get InsertPos back and create a new AT for
it. In fact InsertPos is a nullptr, which causes segmentfault.
The original code is correct, AutoTypes.FindNodeOrInsertPos(ID, InsertPos) returning non-null should be impossible here, as we are just refreshing the insert position after having possibly invalidated it when we created the canonical node.
We had looked for the node before and didn't find it, so finding it just after having created the canonical node means this is a canonicalization bug.
I think this could have used an assert on the return value to better explain that is going on.
FWIW, someone else already started working on this bug some time ago, and I made some comments there which I think explain the problem better: See https://reviews.llvm.org/D126172
Might be worth a ping since might have stalled on it though.