I was looking into this reported issue of a seemingly missed optimization, and I noticed that in recent main branch compilers the problem seems to have been resolved. So my question is – is adding a regression test that ensures this optimization continues to occur a reasonable thing to do? I haven't yet looked to see if such tests already exist, but I assume they probably do, at least for certain types/optimizations.
I think it would be a good idea to add a regression test for this case if there isn't already one.
I have recently also notice that the optimize got noticeably better in certain cases.
cc @Erik_Eckstein
Yes, adding such tests is generally a good idea. There are several approaches, one way is you just FileCheck the output of -emit-sil -O to ensure the full pipeline has the intended effect on some given piece of Swift code, or you can be more precise, and write a SIL test that runs a specific optimization pass with sil-opt and then FileCheck that.
Thanks! Here's a PR with a test. LMK if there are better ways of going about testing for this sort of thing.
From poking around the example a bit, it seemed like copy propagation was likely responsible for improving the generated code (though I could be wrong in that assessment), but for some reason it maybe didn't run on or actually change the relevant function in 6.3... curious why that would be, though haven't looked into it much.
P.S. Nice work optimizer folks :)