https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107863
--- Comment #9 from Hongtao.liu <crazylht at gmail dot com> --- expand_expr_real_1 generates (const_int 255) without considering the target mode. I guess it's on purpose, so I'll leave that alone and only change the expander in the backend. After applying convert_modes to (const_int 255), it's transformed to (const_int -1) which should fix the issue. -----------cut from expand_expr_real_1-------------- 11010 case INTEGER_CST: 11011 { 11012 /* Given that TYPE_PRECISION (type) is not always equal to 11013 GET_MODE_PRECISION (TYPE_MODE (type)), we need to extend from 11014 the former to the latter according to the signedness of the 11015 type. */ 11016 scalar_int_mode int_mode = SCALAR_INT_TYPE_MODE (type); 11017 temp = immed_wide_int_const 11018 (wi::to_wide (exp, GET_MODE_PRECISION (int_mode)), int_mode); 11019 return temp; 11020 } -----------cut ends------------------------ Proposed patch: diff --git a/gcc/config/i386/i386-expand.cc b/gcc/config/i386/i386-expand.cc index 0373c3614a4..c639ee3a9f7 100644 --- a/gcc/config/i386/i386-expand.cc +++ b/gcc/config/i386/i386-expand.cc @@ -12475,7 +12475,7 @@ ix86_expand_vec_set_builtin (tree exp) op1 = expand_expr (arg1, NULL_RTX, mode1, EXPAND_NORMAL); elt = get_element_number (TREE_TYPE (arg0), arg2); - if (GET_MODE (op1) != mode1 && GET_MODE (op1) != VOIDmode) + if (GET_MODE (op1) != mode1) op1 = convert_modes (mode1, GET_MODE (op1), op1, true); op0 = force_reg (tmode, op0);