llvm-6502/test/Transforms/Reassociate/multistep.ll
Shuxin Yang 0a46bf13a3 This change is to fix rdar://12571717 which is about assertion in Reassociate pass.
The assertion is trigged when the Reassociater tries to transform expression
     ... + 2 * n * 3 + 2 * m + ...
  into:
     ... + 2 * (n*3 + m).

In the process of the transformation, a helper routine folds the constant 2*3 into 6,
confusing optimizer which is trying the to eliminate the common factor 2, and cannot
find 2 any more. 

Review is pending. But I'd like commit first in order to help those who are waiting 
for this fix. 


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@167740 91177308-0d34-0410-b5e6-96231b3b80d8
2012-11-12 19:34:11 +00:00

32 lines
830 B
LLVM

; RUN: opt < %s -reassociate -S | FileCheck %s
define i64 @multistep1(i64 %a, i64 %b, i64 %c) {
; Check that a*a*b+a*a*c is turned into (a*a)*(b+c).
; CHECK: @multistep1
%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
; CHECK-NEXT: add i64 %c, %b
; CHECK-NEXT: mul i64 %a, %a
; CHECK-NEXT: mul i64 %tmp{{.*}}, %tmp{{.*}}
; 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.
; CHECK: @multistep2
%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)
; CHECK-NEXT: add i64 %c, %b
; CHECK-NEXT: mul i64 %tmp{{.*}}, %a
; CHECK-NEXT: add i64 %tmp{{.*}}, %d
; CHECK-NEXT: ret
ret i64 %t3
}