On Thu, 18 Aug 2011, Artem Shinkarov wrote: > >> + /* Avoid C_MAYBE_CONST in VEC_COND_EXPR. */ > >> + sc = c_fully_fold (ifexp, false, &maybe_const); > >> + sc = save_expr (sc); > >> + if (!maybe_const) > >> + ifexp = c_wrap_maybe_const (sc, true); > >> + else > >> + ifexp = sc; > > > > This looks like it's duplicating c_save_expr; that is, like "ifexp = > > c_save_expr (ifexp);" would suffice. > > > > But, it's not clear that it actually achieves the effect described in the > > comment; have you actually tried with function calls, assignments etc. in > > the operands? > > I tested it with gcc.dg/vector-compare-2.c: > typedef int vec __attribute__((vector_size(16))); > > vec i,j; > extern vec a, b, c; > > vec > foo (int x) > { > return (x ? i : j) ? a : b; > } > > vec > bar (int x) > { > return a ? (x ? i : j) : b; > } > > vec > baz (int x) > { > return a ? b : (x ? i : j); > } > > Is it good enough?
No, because none of the operands there involve assignment, increment, decrement, function call or comma operators (which are the main cases that would trigger the creation of C_MAYBE_CONST_EXPR). > > The code in build_binary_op uses save_expr rather than > > c_save_expr because it does some intermediate operations before calling > > c_wrap_maybe_const, and if you really want to avoid C_MAYBE_CONST in > > VEC_COND_EXPR then you'll need to continue calling save_expr, as here, but > > delay the call to c_wrap_maybe_const so that the whole VEC_COND_EXPR is > > wrapped if required. > > Ok, but I need to wrap it at some point, where do you think it would > be appropriate to do? After the creation of the VEC_COND_EXPR. I.e. don't just return the results of build3 or convert, wrap them as needed before returning them. -- Joseph S. Myers jos...@codesourcery.com