[PATCH] D39204: [CodeGen] __builtin_sqrt should map to the compiler's intrinsic sqrt function

Hal Finkel via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 26 15:46:13 PDT 2017

hfinkel added a comment.

In https://reviews.llvm.org/D39204#905860, @efriedma wrote:

> I think you're understanding the semantics correctly.
> For r265521, look again at the implementation of llvm::checkUnaryFloatSignature; if "I.onlyReadsMemory()" is true, we somehow proved the call doesn't set errno (mostly likely because we know something about the target's libm).

Right. Either by target default, or because the user passed -fno-math-errno (or something that implies it, such as -ffast-math), we mark the functions as readonly/readnone because they won't write to errno.

In https://reviews.llvm.org/D39204#905361, @spatel wrote:

> Working my way through the stack: does the sqrt LangRef change mean we can revert https://reviews.llvm.org/rL265521?

Yes, maybe. We can now form the intrinsics from the library calls so long as we only care about the result (and not the value of errno), even if the input is negative or would otherwise generate a NaN (as the intrinsic no longer as UB in those situations). However, we still need to know that the potential value of errno is of no interest. I'm not sure how we know that without some particular modeling.

> What allows us to transform any of those libm calls that set errno to vectors in the first place?
> I'm even more confused than usual, but if I can find a way to untangle this mess, I'll try to start making patches.


More information about the cfe-commits mailing list