https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108583
Tamar Christina <tnfchris at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |rguenth at gcc dot gnu.org, | |rsandifo at gcc dot gnu.org --- Comment #3 from Tamar Christina <tnfchris at gcc dot gnu.org> --- Right, so this is because in the expansion we don't have enough context to decide how to optimize the division. This optimization is only possible when the input is widened because you need an additional free bit so that the second addition can't overflow. The vectorizer has this context but since we didn't want a new IFN the context should instead be derivable in targetm.vectorize.can_special_div_by_const hook. So my proposal to fix this and keep targetm.vectorize.can_special_div_by_const as a general divide optimization hook is to pass the actual `tree` operand0 as well to the hook such that the hook has a bit more context. I was hoping to use get_nonzero_bits to get what the actual range of the operand is. But it looks like for widening operations it still reports -1. So my suggestion is the backend should just check if the operand is a non-constant and the type of the operation being performed is matches the precision we require. Is this ok with you Richards? since I'll need both of you to approve.