================
@@ -0,0 +1,136 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -passes=instcombine -S < %s -mtriple=x86_64-apple-macosx10.9 |
FileCheck %s --check-prefixes=CHECK,CHECK-DOUBLE-ALIGN8
+; RUN: opt -passes=instcombine -S < %s -mtriple=arm-apple-ios7.0 | FileCheck
%s --check-prefixes=CHECK,CHECK-DOUBLE-ALIGN4
+; RUN: opt -passes=instcombine -S < %s -mtriple=x86_64-none-linux-gnu |
FileCheck %s --check-prefixes=CHECK,CHECK-DOUBLE-ALIGN8-LINUX
+; REQUIRES: arm-registered-target, x86-registered-target
+
+attributes #0 = { readnone nounwind }
+
+declare float @sinf(float) #0
+declare float @cosf(float) #0
+declare double @sin(double) #0
+declare double @cos(double) #0
+
+@var32 = global float 0.0
+@var64 = global double 0.0
+
+; Basic sin+cos combination for float
+define float @sincos_f32() {
+; CHECK-LABEL: @sincos_f32(
+; CHECK-NEXT: [[VAL:%.*]] = load float, ptr @var32, align 4
+; CHECK-NEXT: [[SINCOS:%.*]] = call { float, float } @llvm.sincos.f32(float
[[VAL]])
+; CHECK-NEXT: [[SIN:%.*]] = extractvalue { float, float } [[SINCOS]], 0
+; CHECK-NEXT: [[COS:%.*]] = extractvalue { float, float } [[SINCOS]], 1
+; CHECK-NEXT: [[C:%.*]] = call float @cosf(float [[VAL]]) #[[ATTR0:[0-9]+]]
+; CHECK-NEXT: [[RES:%.*]] = fadd float [[SIN]], [[COS]]
+; CHECK-NEXT: ret float [[RES]]
+;
+ %val = load float, ptr @var32
+ %s = call float @sinf(float %val) #0
+ %c = call float @cosf(float %val) #0
+ %res = fadd float %s, %c
+ ret float %res
+}
+
+; Basic sin+cos combination for double
+define double @sincos_f64() {
+; CHECK-DOUBLE-ALIGN8-LABEL: @sincos_f64(
+; CHECK-DOUBLE-ALIGN8-NEXT: [[VAL:%.*]] = load double, ptr @var64, align 8
+; CHECK-DOUBLE-ALIGN8-NEXT: [[SINCOS:%.*]] = call { double, double }
@llvm.sincos.f64(double [[VAL]])
+; CHECK-DOUBLE-ALIGN8-NEXT: [[SIN:%.*]] = extractvalue { double, double }
[[SINCOS]], 0
+; CHECK-DOUBLE-ALIGN8-NEXT: [[COS:%.*]] = extractvalue { double, double }
[[SINCOS]], 1
+; CHECK-DOUBLE-ALIGN8-NEXT: [[C:%.*]] = call double @cos(double [[VAL]])
#[[ATTR0]]
+; CHECK-DOUBLE-ALIGN8-NEXT: [[RES:%.*]] = fadd double [[SIN]], [[COS]]
+; CHECK-DOUBLE-ALIGN8-NEXT: ret double [[RES]]
+;
+; CHECK-DOUBLE-ALIGN4-LABEL: @sincos_f64(
+; CHECK-DOUBLE-ALIGN4-NEXT: [[VAL:%.*]] = load double, ptr @var64, align 4
+; CHECK-DOUBLE-ALIGN4-NEXT: [[SINCOS:%.*]] = call { double, double }
@llvm.sincos.f64(double [[VAL]])
+; CHECK-DOUBLE-ALIGN4-NEXT: [[SIN:%.*]] = extractvalue { double, double }
[[SINCOS]], 0
+; CHECK-DOUBLE-ALIGN4-NEXT: [[COS:%.*]] = extractvalue { double, double }
[[SINCOS]], 1
+; CHECK-DOUBLE-ALIGN4-NEXT: [[C:%.*]] = call double @cos(double [[VAL]])
#[[ATTR0]]
+; CHECK-DOUBLE-ALIGN4-NEXT: [[RES:%.*]] = fadd double [[SIN]], [[COS]]
+; CHECK-DOUBLE-ALIGN4-NEXT: ret double [[RES]]
+;
+; CHECK-DOUBLE-ALIGN8-LINUX-LABEL: @sincos_f64(
+; CHECK-DOUBLE-ALIGN8-LINUX-NEXT: [[VAL:%.*]] = load double, ptr @var64,
align 8
+; CHECK-DOUBLE-ALIGN8-LINUX-NEXT: [[SINCOS:%.*]] = call { double, double }
@llvm.sincos.f64(double [[VAL]])
+; CHECK-DOUBLE-ALIGN8-LINUX-NEXT: [[SIN:%.*]] = extractvalue { double,
double } [[SINCOS]], 0
+; CHECK-DOUBLE-ALIGN8-LINUX-NEXT: [[COS:%.*]] = extractvalue { double,
double } [[SINCOS]], 1
+; CHECK-DOUBLE-ALIGN8-LINUX-NEXT: [[C:%.*]] = call double @cos(double
[[VAL]]) #[[ATTR0]]
+; CHECK-DOUBLE-ALIGN8-LINUX-NEXT: [[RES:%.*]] = fadd double [[SIN]], [[COS]]
+; CHECK-DOUBLE-ALIGN8-LINUX-NEXT: ret double [[RES]]
+;
+ %val = load double, ptr @var64
+ %s = call double @sin(double %val) #0
+ %c = call double @cos(double %val) #0
+ %res = fadd double %s, %c
+ ret double %res
+}
+
+; Only sin, no cos - should NOT combine
+define float @sin_only_f32(float %x) {
+; CHECK-LABEL: @sin_only_f32(
+; CHECK-NEXT: [[S:%.*]] = call float @sinf(float [[X:%.*]]) #[[ATTR0]]
+; CHECK-NEXT: ret float [[S]]
+;
+ %s = call float @sinf(float %x) #0
+ ret float %s
+}
+
+; Only cos, no sin - should NOT combine
+define float @cos_only_f32(float %x) {
+; CHECK-LABEL: @cos_only_f32(
+; CHECK-NEXT: [[C:%.*]] = call float @cosf(float [[X:%.*]]) #[[ATTR0]]
+; CHECK-NEXT: ret float [[C]]
+;
+ %c = call float @cosf(float %x) #0
+ ret float %c
+}
+
+; Different arguments - should NOT combine
+define float @sincos_different_args(float %x, float %y) {
+; CHECK-LABEL: @sincos_different_args(
+; CHECK-NEXT: [[S:%.*]] = call float @sinf(float [[X:%.*]]) #[[ATTR0]]
+; CHECK-NEXT: [[C:%.*]] = call float @cosf(float [[Y:%.*]]) #[[ATTR0]]
+; CHECK-NEXT: [[RES:%.*]] = fadd float [[S]], [[C]]
+; CHECK-NEXT: ret float [[RES]]
+;
+ %s = call float @sinf(float %x) #0
+ %c = call float @cosf(float %y) #0
+ %res = fadd float %s, %c
+ ret float %res
+}
+
+; Constant argument - should NOT combine
+define float @sincos_const_arg() {
+; CHECK-LABEL: @sincos_const_arg(
+; CHECK-NEXT: [[S:%.*]] = call float @sinf(float 1.000000e+00) #[[ATTR0]]
+; CHECK-NEXT: [[C:%.*]] = call float @cosf(float 1.000000e+00) #[[ATTR0]]
+; CHECK-NEXT: ret float 0x3FF61BBE40000000
+;
+ %s = call float @sinf(float 1.0) #0
+ %c = call float @cosf(float 1.0) #0
+ %res = fadd float %s, %c
+ ret float %res
+}
+
+; Multiple uses of sin and cos results
+define float @sincos_multi_use(float %x) {
+; CHECK-LABEL: @sincos_multi_use(
+; CHECK-NEXT: [[SINCOS:%.*]] = call { float, float } @llvm.sincos.f32(float
[[X:%.*]])
+; CHECK-NEXT: [[SIN:%.*]] = extractvalue { float, float } [[SINCOS]], 0
+; CHECK-NEXT: [[COS:%.*]] = extractvalue { float, float } [[SINCOS]], 1
+; CHECK-NEXT: [[C:%.*]] = call float @cosf(float [[X]]) #[[ATTR0]]
+; CHECK-NEXT: [[ADD:%.*]] = fadd float [[SIN]], [[COS]]
+; CHECK-NEXT: [[MUL:%.*]] = fmul float [[SIN]], [[COS]]
+; CHECK-NEXT: [[RES:%.*]] = fadd float [[ADD]], [[MUL]]
+; CHECK-NEXT: ret float [[RES]]
+;
+ %s = call float @sinf(float %x) #0
+ %c = call float @cosf(float %x) #0
+ %add = fadd float %s, %c
+ %mul = fmul float %s, %c
+ %res = fadd float %add, %mul
+ ret float %res
+}
----------------
kito-cheng wrote:
Added testcase
https://github.com/llvm/llvm-project/pull/184760
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits