1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -passes=instcombine < %s | FileCheck %s
4 declare double @llvm.exp.f64(double) nounwind readnone speculatable
5 declare void @use(double)
7 ; exp(a) * exp(b) no reassoc flags
8 define double @exp_a_exp_b(double %a, double %b) {
9 ; CHECK-LABEL: @exp_a_exp_b(
10 ; CHECK-NEXT: [[T:%.*]] = call double @llvm.exp.f64(double [[A:%.*]])
11 ; CHECK-NEXT: [[T1:%.*]] = call double @llvm.exp.f64(double [[B:%.*]])
12 ; CHECK-NEXT: [[MUL:%.*]] = fmul double [[T]], [[T1]]
13 ; CHECK-NEXT: ret double [[MUL]]
15 %t = call double @llvm.exp.f64(double %a)
16 %t1 = call double @llvm.exp.f64(double %b)
17 %mul = fmul double %t, %t1
21 ; exp(a) * exp(b) reassoc, multiple uses
22 define double @exp_a_exp_b_multiple_uses(double %a, double %b) {
23 ; CHECK-LABEL: @exp_a_exp_b_multiple_uses(
24 ; CHECK-NEXT: [[T1:%.*]] = call double @llvm.exp.f64(double [[B:%.*]])
25 ; CHECK-NEXT: [[TMP1:%.*]] = fadd reassoc double [[A:%.*]], [[B]]
26 ; CHECK-NEXT: [[MUL:%.*]] = call reassoc double @llvm.exp.f64(double [[TMP1]])
27 ; CHECK-NEXT: call void @use(double [[T1]])
28 ; CHECK-NEXT: ret double [[MUL]]
30 %t = call double @llvm.exp.f64(double %a)
31 %t1 = call double @llvm.exp.f64(double %b)
32 %mul = fmul reassoc double %t, %t1
33 call void @use(double %t1)
37 ; exp(a) * exp(b) reassoc, both with multiple uses
38 define double @exp_a_exp_b_multiple_uses_both(double %a, double %b) {
39 ; CHECK-LABEL: @exp_a_exp_b_multiple_uses_both(
40 ; CHECK-NEXT: [[T:%.*]] = call double @llvm.exp.f64(double [[A:%.*]])
41 ; CHECK-NEXT: [[T1:%.*]] = call double @llvm.exp.f64(double [[B:%.*]])
42 ; CHECK-NEXT: [[MUL:%.*]] = fmul reassoc double [[T]], [[T1]]
43 ; CHECK-NEXT: call void @use(double [[T]])
44 ; CHECK-NEXT: call void @use(double [[T1]])
45 ; CHECK-NEXT: ret double [[MUL]]
47 %t = call double @llvm.exp.f64(double %a)
48 %t1 = call double @llvm.exp.f64(double %b)
49 %mul = fmul reassoc double %t, %t1
50 call void @use(double %t)
51 call void @use(double %t1)
55 ; exp(a) * exp(b) => exp(a+b) with reassoc
56 define double @exp_a_exp_b_reassoc(double %a, double %b) {
57 ; CHECK-LABEL: @exp_a_exp_b_reassoc(
58 ; CHECK-NEXT: [[TMP1:%.*]] = fadd reassoc double [[A:%.*]], [[B:%.*]]
59 ; CHECK-NEXT: [[MUL:%.*]] = call reassoc double @llvm.exp.f64(double [[TMP1]])
60 ; CHECK-NEXT: ret double [[MUL]]
62 %t = call double @llvm.exp.f64(double %a)
63 %t1 = call double @llvm.exp.f64(double %b)
64 %mul = fmul reassoc double %t, %t1
68 define double @exp_a_a(double %a) {
69 ; CHECK-LABEL: @exp_a_a(
70 ; CHECK-NEXT: [[TMP1:%.*]] = fadd reassoc double [[A:%.*]], [[A]]
71 ; CHECK-NEXT: [[M:%.*]] = call reassoc double @llvm.exp.f64(double [[TMP1]])
72 ; CHECK-NEXT: ret double [[M]]
74 %t = call double @llvm.exp.f64(double %a)
75 %m = fmul reassoc double %t, %t
81 define double @exp_a_a_extra_use(double %a) {
82 ; CHECK-LABEL: @exp_a_a_extra_use(
83 ; CHECK-NEXT: [[T:%.*]] = call double @llvm.exp.f64(double [[A:%.*]])
84 ; CHECK-NEXT: call void @use(double [[T]])
85 ; CHECK-NEXT: [[M:%.*]] = fmul reassoc double [[T]], [[T]]
86 ; CHECK-NEXT: ret double [[M]]
88 %t = call double @llvm.exp.f64(double %a)
89 call void @use(double %t)
90 %m = fmul reassoc double %t, %t
94 ; exp(a) * exp(b) * exp(c) * exp(d) => exp(a+b+c+d) with reassoc
95 define double @exp_a_exp_b_exp_c_exp_d_fast(double %a, double %b, double %c, double %d) {
96 ; CHECK-LABEL: @exp_a_exp_b_exp_c_exp_d_fast(
97 ; CHECK-NEXT: [[TMP1:%.*]] = fadd reassoc double [[A:%.*]], [[B:%.*]]
98 ; CHECK-NEXT: [[TMP2:%.*]] = fadd reassoc double [[TMP1]], [[C:%.*]]
99 ; CHECK-NEXT: [[TMP3:%.*]] = fadd reassoc double [[TMP2]], [[D:%.*]]
100 ; CHECK-NEXT: [[MUL2:%.*]] = call reassoc double @llvm.exp.f64(double [[TMP3]])
101 ; CHECK-NEXT: ret double [[MUL2]]
103 %t = call double @llvm.exp.f64(double %a)
104 %t1 = call double @llvm.exp.f64(double %b)
105 %mul = fmul reassoc double %t, %t1
106 %t2 = call double @llvm.exp.f64(double %c)
107 %mul1 = fmul reassoc double %mul, %t2
108 %t3 = call double @llvm.exp.f64(double %d)
109 %mul2 = fmul reassoc double %mul1, %t3