From 3cb1fe60fb00ba3761e34866ffc93c7d7a0b509d Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Mon, 20 May 2024 22:23:02 +0200 Subject: AMDGPU: Don't fold rootn(x, 1) to input for strictfp functions (#92595) We need to insert a constrained canonicalize. Depends #92594 --- llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp') diff --git a/llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp b/llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp index 0a5fbf5034c0..47de1791dae3 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp @@ -1163,14 +1163,19 @@ bool AMDGPULibCalls::fold_rootn(FPMathOperator *FPOp, IRBuilder<> &B, if (!match(opr1, m_APIntAllowPoison(CINT))) return false; + Function *Parent = B.GetInsertBlock()->getParent(); + int ci_opr1 = (int)CINT->getSExtValue(); - if (ci_opr1 == 1) { // rootn(x, 1) = x - LLVM_DEBUG(errs() << "AMDIC: " << *FPOp << " ---> " << *opr0 << "\n"); + if (ci_opr1 == 1 && !Parent->hasFnAttribute(Attribute::StrictFP)) { + // rootn(x, 1) = x + // + // TODO: Insert constrained canonicalize for strictfp case. + LLVM_DEBUG(errs() << "AMDIC: " << *FPOp << " ---> " << *opr0 << '\n'); replaceCall(FPOp, opr0); return true; } - Module *M = B.GetInsertBlock()->getModule(); + Module *M = Parent->getParent(); if (ci_opr1 == 2) { // rootn(x, 2) = sqrt(x) if (FunctionCallee FPExpr = getFunction(M, AMDGPULibFunc(AMDGPULibFunc::EI_SQRT, FInfo))) { -- cgit v1.2.3