Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There are two peephole optimizations included here:
I chose to split them up because firstly, it's simpler, the vector ops translation is already overcomplicated, and being able to start the algorithm on a plain OpCompositeConstruct is really nice, and secondly, OpCompositeConstruct works on more than just vectors (arrays and structs too) and that algorithm works on those too.
I also had to implement the "run mem2reg until nothing changes anymore" thingy, because the scalar->vector transformation works on immediate values, not memory values (OpCompositeExtract rather than OpAccessChain), and a couple vector ops were getting missed because they were still behind pointers after a single mem2reg.