On Mon, Dec 01, 2025 at 09:12:29AM -0700, Jeff Law wrote:
> > I noticed that GCC on x86-64 also misses this optimization, which
> > suggests this maybe generally beneficial for targets with expensive
> > multiplication. Given this, would you advise investigating a generic RTL
> > fix (e.g., in simplify-rtx.cc)?
> We could try to make a case that the multiply, even though its a single op
> is an exception to the simplistic cost model of gimple. I'm not sure that's
> a great solution, but it's worth keeping in mind.
>
> You could try to see if it could be improved at expansion time, we should be
> able to see the expression as (a * b) == 0 due to TER and during expansion
> we can query target costs and adjust the initial RTL we generate.
If it is a win on all targets, then perhaps lower it at isel time (or if
only on some of them, again decide at isel or expansion time what is
cheaper).
Though, like you said, some targets really hate
if ((a == 0) | (b == 0))
goto ...;
and prefer
if (a == 0)
goto ...;
else if (b == 0)
goto ...;
while others like it for 2 ops. So, if it is lowered, it should also
respect LOGICAL_OP_NON_SHORT_CIRCUIT / param_logical_op_non_short_circuit.
Jakub