[llvm] AMDGPU: Libcall expand fast pow/powr/pown/rootn for float case (PR #180553)

Steffen Larsen via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 10 04:21:37 PST 2026


================
@@ -1170,6 +1198,260 @@ bool AMDGPULibCalls::fold_rootn(FPMathOperator *FPOp, IRBuilder<> &B,
   return false;
 }
 
+// is_integer(y) => trunc(y) == y
+static Value *emitIsInteger(IRBuilder<> &B, Value *Y) {
+  Value *TruncY = B.CreateUnaryIntrinsic(Intrinsic::trunc, Y);
+  return B.CreateFCmpOEQ(TruncY, Y);
+}
+
+static Value *emitIsEvenInteger(IRBuilder<> &B, Value *Y) {
+  // Even integers are still integers after division by 2.
+  auto *HalfY = B.CreateFMul(Y, ConstantFP::get(Y->getType(), 0.5));
+  return emitIsInteger(B, HalfY);
+}
+
+// is_odd_integer(y) => is_integer(y) && !is_even_integer(y)
+static Value *emitIsOddInteger(IRBuilder<> &B, Value *Y) {
+  Value *IsIntY = emitIsInteger(B, Y);
+  Value *IsEvenY = emitIsEvenInteger(B, Y);
+  Value *NotEvenY = B.CreateNot(IsEvenY);
+  return B.CreateAnd(IsIntY, NotEvenY);
+}
----------------
steffenlarsen wrote:

Taking it even further, some of the calculations used in the odd-bit check can also be used to check if the floating point value is an integer: https://alive2.llvm.org/ce/z/r-iJK2
The is-integer check by itself doesn't handle NaN and infinity well, hence the freeze, but the is-odd-integer part does, so the resulting value doesn't matter. If freeze is to be avoided, it can be done by an early check of the exponent.

https://github.com/llvm/llvm-project/pull/180553


More information about the llvm-commits mailing list