Scalar vector binary operation
Joseph S. Myers
joseph@codesourcery.com
Fri Dec 3 18:00:00 GMT 2010
On Mon, 22 Nov 2010, Artem Shinkarov wrote:
> + case stv_firstarg:
> + {
> + tree sc = save_expr (op0);
> + sc = convert (TREE_TYPE (type1), sc);
> + op0 = build_vector_from_val (type1, sc);
> + orig_type0 = type0 = TREE_TYPE (op0);
> + code0 = TREE_CODE (type0);
> + converted = 1;
> + break;
> + }
> + case stv_secondarg:
> + {
> + tree sc = save_expr (op1);
> + sc = convert (TREE_TYPE (type0), sc);
> + op1 = build_vector_from_val (type0, sc);
> + orig_type1 = type1 = TREE_TYPE (op1);
> + code1 = TREE_CODE (type1);
> + converted = 1;
> + break;
> + }
(Watch your indentation; here and elsewhere in the patch you add new code
indented by eight or more spaces when TABs should be used. You also have
a bogus patch hunk in conversion_warning that changes a TAB to spaces and
does nothing else.)
This code has the problem that it can call save_expr on something
containing a C_MAYBE_CONST_EXPR without passing it through c_fully_fold
first. Simply using c_save_expr instead of save_expr isn't enough because
that can result in a C_MAYBE_CONST_EXPR inside a vector. Instead you want
something like
+ case stv_firstarg:
+ {
+ bool maybe_const = true;
+ tree sc;
+ sc = c_fully_fold (op0, false, &maybe_const);
+ sc = save_expr (sc);
+ sc = convert (TREE_TYPE (type1), sc);
+ op0 = build_vector_from_val (type1, sc);
+ if (!maybe_const)
+ op0 = c_wrap_maybe_const (op0, true);
+ orig_type0 = type0 = TREE_TYPE (op0);
+ code0 = TREE_CODE (type0);
+ converted = 1;
+ break;
+ }
and similarly for the second case. Testcase (that ICEs with your
original patch):
int f(void);
unsigned int g(void);
unsigned int h;
typedef unsigned int vec __attribute__((vector_size(16)));
vec i;
vec fv1(void) { return i + (h ? f() : g()); }
vec fv2(void) { return (h ? f() : g()) + i; }
The patch is OK modified as indicated and with that testcase added to the
testsuite (presuming it still passes bootstrap with no regressions).
--
Joseph S. Myers
joseph@codesourcery.com
More information about the Gcc-patches
mailing list