[llvm] [GlobalISel] Support fixed vectors in constant-fold combines. (PR #220876)

Vikash Gupta via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 8 03:17:08 PDT 2026


================
@@ -1043,22 +1047,21 @@ llvm::ConstantFoldUnaryFPOp(unsigned Opcode, LLT DstTy, Register Src,
                      APFloat::rmNearestTiesToEven, &Unused);
       return Result;
     case TargetOpcode::G_FSQRT:
-      Result.convert(APFloat::IEEEdouble(), APFloat::rmNearestTiesToEven,
-                     &Unused);
-      Result = APFloat(std::sqrt(Result.convertToDouble()));
-      break;
-    case TargetOpcode::G_FLOG2:
-      Result.convert(APFloat::IEEEdouble(), APFloat::rmNearestTiesToEven,
-                     &Unused);
-      Result = APFloat(std::log2(Result.convertToDouble()));
-      break;
+    case TargetOpcode::G_FLOG2: {
+      Type *Ty =
+          Type::getFloatingPointTy(MRI.getMF().getFunction().getContext(),
+                                   getFltSemanticForLLT(DstEltTy));
+      Constant *C = ConstantFoldFP(Opcode == TargetOpcode::G_FSQRT
+                                       ? static_cast<double (*)(double)>(sqrt)
+                                       : static_cast<double (*)(double)>(log2),
----------------
vg0204 wrote:

The ternary operator forms its common type before the double(*)(double) parameter supplies a target, so the overloaded sqrt/log2 operands can't be resolved without the cast. Direct calls like ConstantFoldFP(sqrt, APF, Ty) work because the parameter type applies directly. It compiles in case of glibc's ::sqrt which is a single double(double), but breaks on libc++/MSVC where they're overload sets.

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


More information about the llvm-commits mailing list