https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63666
--- Comment #11 from Richard Biener <rguenth at gcc dot gnu.org> --- Index: gcc/fold-const.c =================================================================== --- gcc/fold-const.c (revision 216834) +++ gcc/fold-const.c (working copy) @@ -82,6 +82,7 @@ along with GCC; see the file COPYING3. #include "ipa-ref.h" #include "cgraph.h" #include "generic-match.h" +#include "optabs.h" /* Nonzero if we are folding constants inside an initializer; zero otherwise. */ @@ -14311,7 +14331,8 @@ fold_ternary_loc (location_t loc, enum t if (op0 == op1 && !single_arg) changed = true; - if (need_mask_canon && arg2 == op2) + if (need_mask_canon && arg2 == op2 + && can_vec_perm_p (TYPE_MODE (type), false, sel)) { tree *tsel = XALLOCAVEC (tree, nelts); tree eltype = TREE_TYPE (TREE_TYPE (arg2)); fixes the IA64 case.