https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104116
Bug ID: 104116 Summary: Optimize {FLOOR,CEIL,ROUND}_{DIV,MOD}_EXPR in tree-vect-patterns.cc Product: gcc Version: 12.0 Status: UNCONFIRMED Keywords: ice-on-valid-code Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: jakub at gcc dot gnu.org CC: asolokha at gmx dot com, bergner at gcc dot gnu.org, jakub at gcc dot gnu.org, linkw at gcc dot gnu.org, luoxhu at gcc dot gnu.org, rguenth at gcc dot gnu.org, seurer at gcc dot gnu.org, wschmidt at gcc dot gnu.org Depends on: 102860 Blocks: 102938 Target Milestone: --- Host: powerpc64le-linux-gnu Target: powerpc64le-linux-gnu Build: powerpc64le-linux-gnu +++ This bug was initially created as a clone of Bug #102860 +++ As mentioned in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102860#c7, we should try to pattern recognize these operations and turn them into TRUNC_{DIV,MOD}_EXPR if the optab is supported (note, for constant last operand build on top of the current vect_recog_divmod_pattern, so that we handle it even if the optab isn't supported etc.). For signed operands, r = x %[fl] y; is r = x % y; if (r && (x ^ y) < 0) r += y; and d = x /[fl] y; is r = x % y; d = x / y; if (r && (x ^ y) < 0) --d; and r = x %[cl] y; is r = x % y; if (r && (x ^ y) >= 0) r -= y; and d = /[cl] y; is r = x % y; d = x / y; if (r && (x ^ y) >= 0) ++d; (too lazy to write rounding case or do the unsigned case of %[cl] or /[cl] - ([fl] isn't needed for unsigned)). Of course, in vect-patterns the ifs should be written as COND_EXPRs and probably the conditional increments or decrements should be done using corresponding unsigned type with casts. Referenced Bugs: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102860 [Bug 102860] [12 regression] libgomp.fortran/simd2.f90 ICEs after r12-4526 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102938 [Bug 102938] [12 regression] ICE in fortran test cases after r12-4240