Home | History | Annotate | Download | only in Reassociate
      1 ; RUN: opt < %s -reassociate -instcombine -S | FileCheck %s
      2 
      3 ; With sub reassociation, constant folding can eliminate the 12 and -12 constants.
      4 define i32 @test1(i32 %A, i32 %B) {
      5 ; CHECK-LABEL: @test1
      6 ; CHECK-NEXT: %Z = sub i32 %A, %B
      7 ; CHECK-NEXT: ret i32 %Z
      8   %X = add i32 -12, %A
      9   %Y = sub i32 %X, %B
     10   %Z = add i32 %Y, 12
     11   ret i32 %Z
     12 }
     13 
     14 ; PR2047
     15 ; With sub reassociation, constant folding can eliminate the uses of %a.
     16 define i32 @test2(i32 %a, i32 %b, i32 %c) nounwind  {
     17 ; CHECK-LABEL: @test2
     18 ; CHECK-NEXT: %sum = add i32 %c, %b
     19 ; CHECK-NEXT: %tmp7 = sub i32 0, %sum
     20 ; CHECK-NEXT: ret i32 %tmp7
     21 
     22   %tmp3 = sub i32 %a, %b
     23   %tmp5 = sub i32 %tmp3, %c
     24   %tmp7 = sub i32 %tmp5, %a
     25   ret i32 %tmp7
     26 }
     27