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