PR24139 ( https://llvm.org/bugs/show_bug.cgi?id=24139 ) contains an analysis of poor register allocation. One of the findings was that when calculating the spill weight, a rematerializable interval once split is no longer rematerializable. This is because the isRematerializable check in CalcSpillWeights.cpp does not follow the copies introduced by live range splitting (after splitting, the live interval register definition is a copy which is not rematerializable).
My initial fix used a hack which was sufficient for my experiments. This patch is a cleaned up version using a different approach. It, however, obtains the same results as my initial hack.
I have not included a test as I don't know how to test it! I could write a test that counted the number of spills but I feel that any such test would be too fragile in the long run. Advice welcome...