[PATCH] D27618: Failure to vectorize __builtin_sqrt/__builtin_sqrtf

Hal Finkel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 11 13:38:37 PST 2016


hfinkel added inline comments.


================
Comment at: lib/Analysis/ValueTracking.cpp:2526
   case LibFunc::sqrtl:
-    if (ICS->hasNoNaNs())
-      return Intrinsic::sqrt;
-    return Intrinsic::not_intrinsic;
+    return Intrinsic::sqrt;
   }
----------------
RKSimon wrote:
> Do we know the history behind why sqrt was protected by this?
The problem, which has come up a lot, is that our sqrt intrinsic is a special case. Unlike the other intrinsics for math functions, it does not exactly mirror the behavior of the corresponding libm function. As noted in the LangRef, "Unlike sqrt in libm, however, llvm.sqrt has undefined behavior for negative numbers other than -0.0." Thus, unless we get to assume no NaNs, it is possible that the intrinsic might have UB in cases where the libm function does not, and as a result, we can't substitute the intrinsic for the libm call.


https://reviews.llvm.org/D27618





More information about the llvm-commits mailing list