[PATCH] D135451: [TTI] New PPC target hook enableUncondDivisionSpeculation

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 7 09:48:32 PDT 2022


efriedma added a comment.

In D135451#3843064 <https://reviews.llvm.org/D135451#3843064>, @alexgatea wrote:

> In D135451#3842992 <https://reviews.llvm.org/D135451#3842992>, @fhahn wrote:
>
>> IIUC this proposal would effectively re-define `udiv` and `urem`'s semantics on the IR level to not have undefined behavior for PPC?
>
> I don't think that's quite correct. We still view them as undefined,

division by zero is currently undefined behavior at the IR level; if your program would execute it, it has no meaning at all.  So hoisting a divide will interact badly with other optimizations; for example, instcombine will currently turn a divide by zero into "unreachable".  This is different from instructions that return poison.

If you want a version of division that returns a poison value, you need to modify the semantics in LangRef.

---------

In the original example, instead of trying to make the divide hoistable, you could teach LLVM to peel the first iteration of the loop, then CSE the divide.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D135451/new/

https://reviews.llvm.org/D135451



More information about the llvm-commits mailing list