https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111401
Bug ID: 111401 Summary: Middle-end: Missed optimization of MASK_LEN_FOLD_LEFT_PLUS Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: juzhe.zhong at rivai dot ai Target Milestone: --- There is a case I think I missed the optimization in the loop vectorizer: https://godbolt.org/z/x5sjdenhM double foo2 (double *__restrict a, double init, int *__restrict cond, int n) { for (int i = 0; i < n; i++) if (cond[i]) init += a[i]; return init; } It generate the GIMPLE IR as follows: _60 = .SELECT_VL (ivtmp_58, 4); ... vect__ifc__35.14_56 = .VCOND_MASK (mask__23.10_50, vect__8.13_54, { 0.0, 0.0, 0.0, 0.0 }); _36 = .MASK_LEN_FOLD_LEFT_PLUS (init_20, vect__ifc__35.14_56, { -1, -1, -1, -1 }, _60, 0); The mask of MASK_LEN_FOLD_LEFT_PLUS is the dummy mask {-1.-1,...-1} I think we should forward the mask of VCOND_MASK into the MASK_LEN_FOLD_LEFT_PLUS. Then we can eliminate the VCOND_MASK. I don't where is the optimal place to do the optimization. Should be the match.pd ? or the loop vectorizer code? Thanks.