[LLVMdev] Failure to optimize ? operator

Eli Friedman eli.friedman at gmail.com
Wed Dec 14 11:32:09 PST 2011


On Wed, Dec 14, 2011 at 5:19 AM, Brent Walker <brenthwalker at gmail.com> wrote:
> I don't understand your point.  Which version is better does NOT
> depend on what inputs are passed to the function.  The compiled code
> for (as per llvm) f1 will always take less time to execute than f2.
>
> for x > 0 => T(f1) < T(f2)
> for x <= 0 => T(f1) = T(f2)
>
> where T() is the time to execute the given function.
>
> So always T(f1) <= T(f2).

You're not taking branch prediction into account.  Given the cost of
the multiplies, it probably doesn't matter so much for your testcase,
but we still need a cost model.

> I would call this a missed optimization opportunity.  I think it
> warrants a bug report.

Sure.

-Eli




More information about the llvm-dev mailing list