|
| 1 | +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py |
| 2 | +; RUN: opt < %s -passes=instcombine -S | FileCheck %s --check-prefixes=ANY,NO-FLOAT-SHRINK |
| 3 | +; RUN: opt < %s -passes=instcombine -enable-double-float-shrink -S | FileCheck %s --check-prefixes=ANY,DO-FLOAT-SHRINK |
| 4 | + |
| 5 | +declare double @llvm.cos.f64(double) |
| 6 | +declare float @llvm.cos.f32(float) |
| 7 | + |
| 8 | +declare double @llvm.sin.f64(double) |
| 9 | +declare float @llvm.sin.f32(float) |
| 10 | + |
| 11 | +; cos -> cosf |
| 12 | + |
| 13 | +define float @cos_no_fastmath(float %f) { |
| 14 | +; NO-FLOAT-SHRINK-LABEL: @cos_no_fastmath( |
| 15 | +; NO-FLOAT-SHRINK-NEXT: [[D:%.*]] = fpext float [[F:%.*]] to double |
| 16 | +; NO-FLOAT-SHRINK-NEXT: [[RESULT:%.*]] = call double @llvm.cos.f64(double [[D]]) |
| 17 | +; NO-FLOAT-SHRINK-NEXT: [[TRUNCATED_RESULT:%.*]] = fptrunc double [[RESULT]] to float |
| 18 | +; NO-FLOAT-SHRINK-NEXT: ret float [[TRUNCATED_RESULT]] |
| 19 | +; |
| 20 | +; DO-FLOAT-SHRINK-LABEL: @cos_no_fastmath( |
| 21 | +; DO-FLOAT-SHRINK-NEXT: [[TMP1:%.*]] = call float @llvm.cos.f32(float [[F:%.*]]) |
| 22 | +; DO-FLOAT-SHRINK-NEXT: ret float [[TMP1]] |
| 23 | +; |
| 24 | + %d = fpext float %f to double |
| 25 | + %result = call double @llvm.cos.f64(double %d) |
| 26 | + %truncated_result = fptrunc double %result to float |
| 27 | + ret float %truncated_result |
| 28 | +} |
| 29 | + |
| 30 | +define float @cos_fastmath(float %f) { |
| 31 | +; ANY-LABEL: @cos_fastmath( |
| 32 | +; ANY-NEXT: [[TMP1:%.*]] = call fast float @llvm.cos.f32(float [[F:%.*]]) |
| 33 | +; ANY-NEXT: ret float [[TMP1]] |
| 34 | +; |
| 35 | + %d = fpext float %f to double |
| 36 | + %result = call fast double @llvm.cos.f64(double %d) |
| 37 | + %truncated_result = fptrunc double %result to float |
| 38 | + ret float %truncated_result |
| 39 | +} |
| 40 | + |
| 41 | +; sin -> sinf |
| 42 | + |
| 43 | +define float @sin_no_fastmath(float %f) { |
| 44 | +; NO-FLOAT-SHRINK-LABEL: @sin_no_fastmath( |
| 45 | +; NO-FLOAT-SHRINK-NEXT: [[D:%.*]] = fpext float [[F:%.*]] to double |
| 46 | +; NO-FLOAT-SHRINK-NEXT: [[RESULT:%.*]] = call double @llvm.sin.f64(double [[D]]) |
| 47 | +; NO-FLOAT-SHRINK-NEXT: [[TRUNCATED_RESULT:%.*]] = fptrunc double [[RESULT]] to float |
| 48 | +; NO-FLOAT-SHRINK-NEXT: ret float [[TRUNCATED_RESULT]] |
| 49 | +; |
| 50 | +; DO-FLOAT-SHRINK-LABEL: @sin_no_fastmath( |
| 51 | +; DO-FLOAT-SHRINK-NEXT: [[TMP1:%.*]] = call float @llvm.sin.f32(float [[F:%.*]]) |
| 52 | +; DO-FLOAT-SHRINK-NEXT: ret float [[TMP1]] |
| 53 | +; |
| 54 | + %d = fpext float %f to double |
| 55 | + %result = call double @llvm.sin.f64(double %d) |
| 56 | + %truncated_result = fptrunc double %result to float |
| 57 | + ret float %truncated_result |
| 58 | +} |
| 59 | + |
| 60 | +define float @sin_fastmath(float %f) { |
| 61 | +; ANY-LABEL: @sin_fastmath( |
| 62 | +; ANY-NEXT: [[TMP1:%.*]] = call fast float @llvm.sin.f32(float [[F:%.*]]) |
| 63 | +; ANY-NEXT: ret float [[TMP1]] |
| 64 | +; |
| 65 | + %d = fpext float %f to double |
| 66 | + %result = call fast double @llvm.sin.f64(double %d) |
| 67 | + %truncated_result = fptrunc double %result to float |
| 68 | + ret float %truncated_result |
| 69 | +} |
0 commit comments