https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117890
Bug ID: 117890 Summary: Wrong code with -fvect-cost-model=unlimited Product: gcc Version: 15.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: rtl-optimization Assignee: unassigned at gcc dot gnu.org Reporter: lin1.hu at intel dot com Target Milestone: --- Created attachment 59774 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=59774&action=edit A short case Compile the test file using the option -O2 -march=x86-64-v3 -fvect-cost-model=unlimited will generate wrong code. Without -fvect-cost-model=unlimited, the output should be 4, but the output is currently 0. According to my investigation, in case.c.183t.cunroll. <bb 23> [local count: 761014530]: _63 = _29 >> 2; _64 = ~_63; _65 = (_Bool) _64; if (_65 != 0) goto <bb 18>; [5.50%] else goto <bb 3>; [94.50%] <bb 18> [local count: 223857727]: # vect_vec_iv_.29_45 = PHI <{ 5, 6 }(3), { 1, 2 }(7), { 3, 4 }(23)> # vect_vec_iv_.31_50 = PHI <{ 3, 2 }(3), { 7, 6 }(7), { 5, 4 }(23)> _51 = BIT_FIELD_REF <vect_vec_iv_.31_50, 32, 0>; _46 = BIT_FIELD_REF <vect_vec_iv_.29_45, 32, 0>; goto <bb 17>; [100.00%] when the program jump from bb 23. _46 will be 3. <bb 17> [local count: 563714454]: # i_38 = PHI <7(3), _46(18)> # ivtmp_40 = PHI <1(3), _51(18)> <bb 14> [local count: 1127428908]: # i_9 = PHI <i_35(15), i_38(17)> # ivtmp_17 = PHI <ivtmp_36(15), ivtmp_40(17)> _32 = _29 >> i_9; _33 = ~_32; _34 = (_Bool) _33; if (_34 != 0) goto <bb 4>; [5.50%] else goto <bb 16>; [94.50%] <bb 4> [local count: 51673825]: # i_4 = PHI <i_1(11)> _2 = 1 << i_4; _19 = (unsigned char) _2; goto <bb 6>; [100.00%] Hence, i_9 will be 3. It's strange. The program jump because the 2nd bit (counting from 0) is 0, i_9 should be 2, _2 will be 4. But i_9 starts at 3, making the program semantics change.