[llvm] [AMDGPU] Skip fold_pow constant-exponent shortcuts for powr on possibly-negative base (PR #200579)
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 30 06:40:01 PDT 2026
================
@@ -898,66 +898,76 @@ bool AMDGPULibCalls::fold_pow(FPMathOperator *FPOp, IRBuilder<> &B,
// 0x1111111 means that we don't do anything for this call.
int ci_opr1 = (CINT ? (int)CINT->getSExtValue() : 0x1111111);
- if ((CF && CF->isZero()) || (CINT && ci_opr1 == 0)) {
- // pow/powr/pown(x, 0) == 1
- LLVM_DEBUG(errs() << "AMDIC: " << *FPOp << " ---> 1\n");
- Constant *cnval = ConstantFP::get(eltType, 1.0);
- if (getVecSize(FInfo) > 1) {
- cnval = ConstantDataVector::getSplat(getVecSize(FInfo), cnval);
+ // OpenCL powr(x<0, y) = NaN, but the folds below would turn it into a
+ // finite number. Skip them unless NaNs are ignored or the base is known
+ // non-negative.
+ bool IsPowr = FInfo.getId() == AMDGPULibFunc::EI_POWR ||
+ FInfo.getId() == AMDGPULibFunc::EI_POWR_FAST;
+ bool SkipConstantFolds =
+ (CF || CINT) && IsPowr && !FPOp->hasNoNaNs() &&
----------------
jayfoad wrote:
Could simplify the condition:
```suggestion
IsPowr && !FPOp->hasNoNaNs() &&
```
https://github.com/llvm/llvm-project/pull/200579
More information about the llvm-commits
mailing list