[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 00:38:53 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:
You're right, the exponent may run rampant and take it way outside the space representable by a like-sized integer. I'll give it another think-over, but sadly we might have to roll with the fmul.
https://github.com/llvm/llvm-project/pull/180553
More information about the llvm-commits
mailing list