The generic expand_vector_piecewise routine supports lowering of
a vector operation to vector operations of smaller size.  When
computing the extract position from the larger vector it uses the
element size in bits of the original result vector to determine
the number of elements in the smaller vector.  That is wrong when
lowering a compare as the vector element size of a bool vector
does not have to agree with that of the compare operand.  The
following simplifies this, fixing the error.

Bootstrap and regtest running on x86_64-unknown-linux-gnu.

        PR middle-end/118062
        * tree-vect-generic.cc (expand_vector_piecewise): Properly
        compute delta.
---
 gcc/tree-vect-generic.cc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gcc/tree-vect-generic.cc b/gcc/tree-vect-generic.cc
index 78f6e552cc7..4b9cf734bdd 100644
--- a/gcc/tree-vect-generic.cc
+++ b/gcc/tree-vect-generic.cc
@@ -292,7 +292,8 @@ expand_vector_piecewise (gimple_stmt_iterator *gsi, 
elem_op_func f,
   tree part_width = TYPE_SIZE (inner_type);
   tree index = bitsize_int (0);
   int nunits = nunits_for_known_piecewise_op (type);
-  int delta = tree_to_uhwi (part_width) / vector_element_bits (type);
+  int delta = (VECTOR_TYPE_P (inner_type)
+              ? nunits_for_known_piecewise_op (inner_type) : 1);
   int i;
   location_t loc = gimple_location (gsi_stmt (*gsi));
 
-- 
2.43.0

Reply via email to