Message ID | LV2PR01MB78396F84655A6F0751AB4C7BF7BE2@LV2PR01MB7839.prod.exchangelabs.com |
---|---|
State | New |
Headers | show |
Series | vect: Allow unsigned-to-signed promotion in vect_look_through_possible_promotion [PR115707] | expand |
On Mon, Aug 5, 2024 at 12:34 PM Feng Xue OS <fxue@os.amperecomputing.com> wrote: > > The function vect_look_through_possible_promotion() 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. This patch allows this unsigned-to-signed promotion in the function. OK. Thanks, Richard. > Thanks, > Feng > > --- > gcc/ > * tree-vect-patterns.cc (vect_look_through_possible_promotion): Allow > unsigned-to-signed promotion. > --- > gcc/tree-vect-patterns.cc | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/gcc/tree-vect-patterns.cc b/gcc/tree-vect-patterns.cc > index 4674a16d15f..b2c83cfd219 100644 > --- a/gcc/tree-vect-patterns.cc > +++ b/gcc/tree-vect-patterns.cc > @@ -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); > -- > 2.17.1
From 334998e1d991e1d2c8e4c2234663b4d829e88e5c Mon Sep 17 00:00:00 2001 From: Feng Xue <fxue@os.amperecomputing.com> Date: Mon, 5 Aug 2024 15:23:56 +0800 Subject: [PATCH] vect: Allow unsigned-to-signed promotion in vect_look_through_possible_promotion [PR115707] 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/ * tree-vect-patterns.cc (vect_look_through_possible_promotion): Allow unsigned-to-signed promotion. --- gcc/tree-vect-patterns.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gcc/tree-vect-patterns.cc b/gcc/tree-vect-patterns.cc index 4674a16d15f..b2c83cfd219 100644 --- a/gcc/tree-vect-patterns.cc +++ b/gcc/tree-vect-patterns.cc @@ -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); -- 2.17.1