Fix insertion of early-break iteration count definition.
Correctly inserts loop iteration count definition after labels in vect_do_peeling.
This commit fixes an issue in the vect_do_peeling function within GCC’s tree-vectorizer, specifically concerning the insertion of the early-break iteration count definition. The problem arose because the insertion was happening after labels using an iterator that required insertion before. The fix changes the insertion method to gsi_insert_before when using a gsi_after_labels iterator, ensuring the definition is placed correctly in the intermediate representation.
In Details
PR tree-optimization/128394 highlights a bug in tree-vect-loop-manip.cc's vect_do_peeling where the iteration count definition for early-break conditions was inserted incorrectly. Because the function uses a gsi_after_labels iterator, insertions should logically occur after, but the gsi_insert_after operation was not correctly placing the definition relative to labels. The fix correctly uses gsi_insert_before in conjunction with the gsi_after_labels iterator to ensure proper placement of the niter definition, maintaining loop invariant correctness.
- tree-optimization
- A phase in the GCC compiler where the code is represented in an intermediate form called 'tree'. Optimizations are applied to this representation before further code generation.
- vect_do_peeling
- A function within GCC's vectorizer that performs loop peeling, a technique where one or more iterations of a loop are duplicated outside the main loop to handle loop termination conditions or alignment requirements for vectorization.
- iteration count definition
- In the context of loop optimization, this refers to the calculation or definition of how many times a loop will execute. This is crucial for optimizations like loop vectorization and software pipelining.
- early-break
- A condition within a loop that causes it to terminate prematurely, before completing all intended iterations. This can complicate optimizations if not handled correctly.
- GSI
- Generic Statement Iterator. An iterator used in GCC's intermediate representation (tree) to traverse and manipulate basic blocks and statements within functions.