Home | History | Annotate | Download | only in Reassociate
      1 ; RUN: opt < %s -reassociate -instcombine -S | FileCheck %s
      2 
      3 ; Test that we can turn things like X*-(Y*Z) -> X*-1*Y*Z.
      4 
      5 define i32 @test1(i32 %a, i32 %b, i32 %z) {
      6 ; CHECK-LABEL: test1
      7 ; CHECK-NEXT: %e = mul i32 %a, 12345
      8 ; CHECK-NEXT: %f = mul i32 %e, %b
      9 ; CHECK-NEXT: %g = mul i32 %f, %z
     10 ; CHECK-NEXT: ret i32 %g
     11 
     12   %c = sub i32 0, %z
     13   %d = mul i32 %a, %b
     14   %e = mul i32 %c, %d
     15   %f = mul i32 %e, 12345
     16   %g = sub i32 0, %f
     17   ret i32 %g
     18 }
     19 
     20 define i32 @test2(i32 %a, i32 %b, i32 %z) {
     21 ; CHECK-LABEL: test2
     22 ; CHECK-NEXT: %e = mul i32 %a, 40
     23 ; CHECK-NEXT: %f = mul i32 %e, %z
     24 ; CHECK-NEXT: ret i32 %f
     25 
     26   %d = mul i32 %z, 40
     27   %c = sub i32 0, %d
     28   %e = mul i32 %a, %c
     29   %f = sub i32 0, %e
     30   ret i32 %f
     31 }
     32