Optimization for left shifts by additions sets correct vector type
GCC's tree vectorizer now correctly handles vector types when optimizing left shifts implemented as additions, improving code generation accuracy.
This commit corrects an issue in GCC’s tree vectorizer where internally generated statements for left shifts by additions failed to specify the correct vector type. The synth_lshift_by_additions and apply_binop_and_append_stmt functions now ensure the proper vector type is set on the pattern statements. This fix improves the accuracy of vectorized code generated by the compiler, avoiding potential type-mismatches and incorrect optimizations.
In Details
This change targets GCC's tree-vectorizer, specifically the pattern matching and synthesis of operations like left shifting by additions in tree-vect-patterns.cc. The fix ensures that the vector type information is correctly propagated to the newly synthesized statements, which is crucial for maintaining correctness during vectorization and avoiding miscompilations, particularly with vect_synth_mult_by_constant interactions. This ensures that the vectorization pass accurately represents the data types involved in optimized code. The overall context is about how the compiler uses patterns…
For Context
Compilers like GCC try to make your code run faster by optimizing it. One common optimization is 'vectorization', where the compiler identifies loops or operations that can be performed on multiple pieces of data at once using special CPU instructions (SIMD instructions). This commit specifically addresses an issue in how GCC's optimizer handles left shift operations that are represented as additions. When the compiler converts these operations into a vectorized form, it needs to ensure that the data type of the resulting vectorized operation is correct. This fix ensures that the compiler properly sets these data types during the optimization process, preventing potential errors or inefficient code generation that could arise from type mismatches. If vector types are incorrect, the compiler might generate code that computes wrong results or crashes. The code is located in the tree vectorizer, part of the GCC compiler that uses a tree-like intermediate representation of source code to…