1 ; RUN: opt < %s -mtriple=aarch64-linux-gnu -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 -hoist-common-insts=true -enable-unsafe-fp-math -S >%t
2 ; RUN: FileCheck %s < %t
5 ; Function Attrs: nounwind
6 define double @_Z3fooRdS_S_S_(ptr dereferenceable(8) %x, ptr dereferenceable(8) %y, ptr dereferenceable(8) %a) #0 {
8 %0 = load double, ptr %y, align 8
9 %cmp = fcmp oeq double %0, 0.000000e+00
10 %1 = load double, ptr %x, align 8
11 br i1 %cmp, label %if.then, label %if.else
13 ; fadd (const, (fmul x, y))
14 if.then: ; preds = %entry
15 ; CHECK-LABEL: if.then:
16 ; CHECK: %3 = fmul fast double %1, %2
17 ; CHECK-NEXT: %mul = fadd fast double 1.000000e+00, %3
18 %2 = load double, ptr %a, align 8
19 %3 = fmul fast double %1, %2
20 %mul = fadd fast double 1.000000e+00, %3
21 store double %mul, ptr %y, align 8
24 ; fsub ((fmul x, y), z)
25 if.else: ; preds = %entry
26 ; CHECK-LABEL: if.else:
27 ; CHECK: %mul1 = fmul fast double %1, %2
28 ; CHECK-NEXT: %sub1 = fsub fast double %mul1, %0
29 %4 = load double, ptr %a, align 8
30 %mul1 = fmul fast double %1, %4
31 %sub1 = fsub fast double %mul1, %0
32 %gep1 = getelementptr double, ptr %y, i32 1
33 store double %sub1, ptr %gep1, align 8
36 if.end: ; preds = %if.else, %if.then
37 %5 = load double, ptr %y, align 8
38 %cmp2 = fcmp oeq double %5, 2.000000e+00
39 %6 = load double, ptr %x, align 8
40 br i1 %cmp2, label %if.then2, label %if.else2
42 ; fsub (x, (fmul y, z))
43 if.then2: ; preds = %entry
44 ; CHECK-LABEL: if.then2:
45 ; CHECK: %7 = fmul fast double %5, 3.000000e+00
46 ; CHECK-NEXT: %mul2 = fsub fast double %6, %7
47 %7 = load double, ptr %a, align 8
48 %8 = fmul fast double %6, 3.0000000e+00
49 %mul2 = fsub fast double %7, %8
50 store double %mul2, ptr %y, align 8
53 ; fsub (fneg((fmul x, y)), const)
54 if.else2: ; preds = %entry
55 ; CHECK-LABEL: if.else2:
56 ; CHECK: %mul3 = fmul fast double %5, 3.000000e+00
57 ; CHECK-NEXT: %neg = fsub fast double 0.000000e+00, %mul3
58 ; CHECK-NEXT: %sub2 = fsub fast double %neg, 3.000000e+00
59 %mul3 = fmul fast double %6, 3.0000000e+00
60 %neg = fsub fast double 0.0000000e+00, %mul3
61 %sub2 = fsub fast double %neg, 3.0000000e+00
62 store double %sub2, ptr %y, align 8
65 if.end2: ; preds = %if.else, %if.then
66 %9 = load double, ptr %x, align 8
67 %10 = load double, ptr %y, align 8
68 %add = fadd fast double %9, %10
69 %11 = load double, ptr %a, align 8
70 %add2 = fadd fast double %add, %11