]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
vect: Allow unsigned-to-signed promotion in vect_look_through_possible_promotion...
authorFeng Xue <fxue@os.amperecomputing.com>
Mon, 5 Aug 2024 07:23:56 +0000 (15:23 +0800)
committerFeng Xue <fxue@os.amperecomputing.com>
Tue, 6 Aug 2024 03:34:37 +0000 (11:34 +0800)
The function fails to figure out root definition if casts involves more than
two promotions with sign change as:

long a = (long)b;       // promotion cast
 -> int b = (int)c;     // promotion cast, sign change
   -> unsigned short c = ...;

For this case, the function thinks the 2nd cast has different sign as the 1st,
so stop looking through, while "unsigned short -> integer" is a nature sign
extension.

2024-08-05 Feng Xue <fxue@os.amperecomputing.com>

gcc/
PR tree-optimization/115707
* tree-vect-patterns.cc (vect_look_through_possible_promotion): Allow
unsigned-to-signed promotion.

gcc/tree-vect-patterns.cc

index 4674a16d15f472636ca6636f661188a3c718b0f0..b2c83cfd21904f89d27e335a4b5918dc9fd9d3d3 100644 (file)
@@ -434,7 +434,9 @@ vect_look_through_possible_promotion (vec_info *vinfo, tree op,
             sign of the previous promotion.  */
          if (!res
              || TYPE_PRECISION (unprom->type) == orig_precision
-             || TYPE_SIGN (unprom->type) == TYPE_SIGN (op_type))
+             || TYPE_SIGN (unprom->type) == TYPE_SIGN (op_type)
+             || (TYPE_UNSIGNED (op_type)
+                 && TYPE_PRECISION (op_type) < TYPE_PRECISION (unprom->type)))
            {
              unprom->set_op (op, dt, caster);
              min_precision = TYPE_PRECISION (op_type);