[llvm] [SimplifyLibCalls] Shrink sin, cos to sinf, cosf when allowed (PR #139082)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Thu May 8 08:50:28 PDT 2025
================
@@ -0,0 +1,61 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -passes=instcombine -S | FileCheck %s --check-prefixes=ANY,NO-FLOAT-SHRINK
+; RUN: opt < %s -passes=instcombine -enable-double-float-shrink -S | FileCheck %s --check-prefixes=ANY,DO-FLOAT-SHRINK
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
+
+declare double @llvm.cos.f64(double)
+declare float @llvm.cos.f32(float)
+
+declare double @llvm.sin.f64(double)
+declare float @llvm.sin.f32(float)
+
+; cos -> cosf
+
+; ANY-LABEL: define float @cos_no_fastmath(float %f) {
+; NO-FLOAT-SHRINK: call double @llvm.cos.f64
+; DO-FLOAT-SHRINK: %[[RES:[0-9]+]] = call float @llvm.cos.f32
+; DO-FLOAT-SHRINK: ret float %[[RES]]
+; ANY: }
+define float @cos_no_fastmath(float %f) {
+ %d = fpext float %f to double
+ %result = call double @llvm.cos.f64(double %d)
+ %truncated_result = fptrunc double %result to float
+ ret float %truncated_result
+}
+
+; ANY-LABEL: define float @cos_fastmath(float %f) {
+; ANY: %[[RES:[0-9]+]] = call fast float @llvm.cos.f32
+; ANY: ret float %[[RES]]
+; ANY: }
+define float @cos_fastmath(float %f) {
+ %d = fpext fast float %f to double
+ %result = call fast double @llvm.cos.f64(double %d)
+ %truncated_result = fptrunc fast double %result to float
+ ret float %truncated_result
+}
+
+; sin -> sinf
+
+; ANY-LABEL: define float @sin_no_fastmath(float %f) {
+; NO-FLOAT-SHRINK: call double @llvm.sin.f64
+; DO-FLOAT-SHRINK: %[[RES:[0-9]+]] = call float @llvm.sin.f32
+; DO-FLOAT-SHRINK: ret float %[[RES]]
+; ANY: }
+define float @sin_no_fastmath(float %f) {
+ %d = fpext float %f to double
+ %result = call double @llvm.sin.f64(double %d)
+ %truncated_result = fptrunc double %result to float
+ ret float %truncated_result
+}
+
+; ANY-LABEL: define float @sin_fastmath(float %f) {
+; ANY: %[[RES:[0-9]+]] = call fast float @llvm.sin.f32
+; ANY: ret float %[[RES]]
+; ANY: }
+define float @sin_fastmath(float %f) {
+ %d = fpext fast float %f to double
+ %result = call fast double @llvm.sin.f64(double %d)
----------------
arsenm wrote:
Probably should fix that, this shouldn't require all of them (in particular nsz or contract)
https://github.com/llvm/llvm-project/pull/139082
More information about the llvm-commits
mailing list