[clang] [CIR] Emit frexp, modf, and powi builtins as library calls (PR #193795)

Andy Kaylor via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 23 16:46:04 PDT 2026


================
@@ -0,0 +1,192 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir
+// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t-cir.ll
+// RUN: FileCheck --check-prefix=LLVM --input-file=%t-cir.ll %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o %t.ll
+// RUN: FileCheck --check-prefix=OGCG --input-file=%t.ll %s
+
+float test_frexpf(float x) {
+  int exp;
+  return __builtin_frexpf(x, &exp);
+}
+
+// CIR-LABEL: cir.func {{.*}} @test_frexpf
+// CIR:         %{{.*}}, %{{.*}} = cir.frexp %{{.*}} : !cir.float -> !cir.float, !s32i
+// CIR:         cir.store
+// CIR:         cir.return
+
+// LLVM-LABEL: define {{.*}} float @test_frexpf
+// LLVM:         %{{.*}} = call { float, i32 } @llvm.frexp.f32.i32(float %{{.*}})
+// LLVM:         %{{.*}} = extractvalue { float, i32 } %{{.*}}, 0
+// LLVM:         %{{.*}} = extractvalue { float, i32 } %{{.*}}, 1
+// LLVM:         ret float
+
+// OGCG-LABEL: define {{.*}} float @test_frexpf
+// OGCG:         call { float, i32 } @llvm.frexp.f32.i32(float %{{.*}})
+// OGCG:         ret float
----------------
andykaylor wrote:

OGCG also has extractvalue here, right? If we're generating matching output, you could use a single set of LLVM checks for both LLVM IR output paths.

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


More information about the cfe-commits mailing list