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