2012-05-08 20:16:05 +08:00
|
|
|
; RUN: opt < %s -reassociate -S | FileCheck %s
|
|
|
|
|
|
|
|
define i64 @multistep1(i64 %a, i64 %b, i64 %c) {
|
2012-11-13 08:08:49 +08:00
|
|
|
; Check that a*a*b+a*a*c is turned into a*(a*(b+c)).
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @multistep1(
|
2012-05-08 20:16:05 +08:00
|
|
|
%t0 = mul i64 %a, %b
|
|
|
|
%t1 = mul i64 %a, %t0 ; a*(a*b)
|
|
|
|
%t2 = mul i64 %a, %c
|
|
|
|
%t3 = mul i64 %a, %t2 ; a*(a*c)
|
|
|
|
%t4 = add i64 %t1, %t3
|
2015-11-17 02:07:30 +08:00
|
|
|
; CHECK-NEXT: [[TMP1:%tmp.*]] = add i64 %c, %b
|
|
|
|
; CHECK-NEXT: [[TMP2:%tmp.*]] = mul i64 %a, %a
|
|
|
|
; CHECK-NEXT: mul i64 [[TMP2]], [[TMP1]]
|
2012-05-08 20:16:05 +08:00
|
|
|
; CHECK-NEXT: ret
|
|
|
|
ret i64 %t4
|
|
|
|
}
|
|
|
|
|
|
|
|
define i64 @multistep2(i64 %a, i64 %b, i64 %c, i64 %d) {
|
|
|
|
; Check that a*b+a*c+d is turned into a*(b+c)+d.
|
2013-07-14 09:42:54 +08:00
|
|
|
; CHECK-LABEL: @multistep2(
|
2012-05-08 20:16:05 +08:00
|
|
|
%t0 = mul i64 %a, %b
|
|
|
|
%t1 = mul i64 %a, %c
|
|
|
|
%t2 = add i64 %t1, %d ; a*c+d
|
|
|
|
%t3 = add i64 %t0, %t2 ; a*b+(a*c+d)
|
2014-11-20 07:21:20 +08:00
|
|
|
; CHECK-NEXT: add i64 %c, %b
|
|
|
|
; CHECK-NEXT: mul i64 %tmp{{.*}}, %a
|
|
|
|
; CHECK-NEXT: add i64 %tmp{{.*}}, %d
|
2012-05-08 20:16:05 +08:00
|
|
|
; CHECK-NEXT: ret
|
|
|
|
ret i64 %t3
|
|
|
|
}
|