(seen on other targets too) For
x / (cond ? const1 : const2) gcc currently always generates a slow general purpose div. But it would be much faster to rewrite it to cond ? (x / const1 : x / const2) and then use the optimized sequences for division by constant In the Linux kernel there are a few cases where this would help. e.g. it is common in device drivers which manage a ring buffer and the ring size depends on the hardware revision. It would be also useful for some other cases where it is not easy to rewrite the code by hand to the better form. I made it rtl-optimization, although I presume it could be as well done on tree level? -- Summary: gcc should optimize x / (cond ? const1 : const2) Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: rtl-optimization AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: ak at muc dot de GCC target triplet: x86_64-linux http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30747