1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -reassociate -S | FileCheck %s
4 ; Check that a*a*b+a*a*c is turned into a*(a*(b+c)).
6 define float @fmultistep1(float %a, float %b, float %c) {
7 ; CHECK-LABEL: @fmultistep1(
8 ; CHECK-NEXT: [[REASS_ADD1:%.*]] = fadd fast float [[C:%.*]], [[B:%.*]]
9 ; CHECK-NEXT: [[REASS_MUL2:%.*]] = fmul fast float [[A:%.*]], [[A]]
10 ; CHECK-NEXT: [[REASS_MUL:%.*]] = fmul fast float [[REASS_MUL2]], [[REASS_ADD1]]
11 ; CHECK-NEXT: ret float [[REASS_MUL]]
13 %t0 = fmul fast float %a, %b
14 %t1 = fmul fast float %a, %t0 ; a*(a*b)
15 %t2 = fmul fast float %a, %c
16 %t3 = fmul fast float %a, %t2 ; a*(a*c)
17 %t4 = fadd fast float %t1, %t3
21 ; Check that a*b+a*c+d is turned into a*(b+c)+d.
23 define float @fmultistep2(float %a, float %b, float %c, float %d) {
24 ; CHECK-LABEL: @fmultistep2(
25 ; CHECK-NEXT: [[REASS_ADD:%.*]] = fadd fast float [[C:%.*]], [[B:%.*]]
26 ; CHECK-NEXT: [[REASS_MUL:%.*]] = fmul fast float [[REASS_ADD]], [[A:%.*]]
27 ; CHECK-NEXT: [[T3:%.*]] = fadd fast float [[REASS_MUL]], [[D:%.*]]
28 ; CHECK-NEXT: ret float [[T3]]
30 %t0 = fmul fast float %a, %b
31 %t1 = fmul fast float %a, %c
32 %t2 = fadd fast float %t1, %d ; a*c+d
33 %t3 = fadd fast float %t0, %t2 ; a*b+(a*c+d)