1 ; RUN: opt < %s -reassociate -S | FileCheck %s
3 ; Check that a*a*b+a*a*c is turned into a*(a*(b+c)).
5 define float @fmultistep1(float %a, float %b, float %c) {
6 ; CHECK-LABEL: @fmultistep1(
7 ; CHECK-NEXT: [[REASS_ADD1:%.*]] = fadd fast float %c, %b
8 ; CHECK-NEXT: [[REASS_MUL2:%.*]] = fmul fast float %a, %a
9 ; CHECK-NEXT: [[REASS_MUL:%.*]] = fmul fast float [[REASS_MUL:%.*]]2, [[REASS_ADD1]]
10 ; CHECK-NEXT: ret float [[REASS_MUL]]
12 %t0 = fmul fast float %a, %b
13 %t1 = fmul fast float %a, %t0 ; a*(a*b)
14 %t2 = fmul fast float %a, %c
15 %t3 = fmul fast float %a, %t2 ; a*(a*c)
16 %t4 = fadd fast float %t1, %t3
20 ; Check that a*b+a*c+d is turned into a*(b+c)+d.
22 define float @fmultistep2(float %a, float %b, float %c, float %d) {
23 ; CHECK-LABEL: @fmultistep2(
24 ; CHECK-NEXT: [[REASS_ADD:%.*]] = fadd fast float %c, %b
25 ; CHECK-NEXT: [[REASS_MUL:%.*]] = fmul fast float [[REASS_ADD]], %a
26 ; CHECK-NEXT: [[T3:%.*]] = fadd fast float [[REASS_MUL]], %d
27 ; CHECK-NEXT: ret float [[T3]]
29 %t0 = fmul fast float %a, %b
30 %t1 = fmul fast float %a, %c
31 %t2 = fadd fast float %t1, %d ; a*c+d
32 %t3 = fadd fast float %t0, %t2 ; a*b+(a*c+d)