Home | History | Annotate | Download | only in InstSimplify
      1 ; RUN: opt < %s -instsimplify -S | FileCheck %s
      2 
      3 define i32 @factorize(i32 %x, i32 %y) {
      4 ; CHECK: @factorize
      5 ; (X | 1) & (X | 2) -> X | (1 & 2) -> X
      6   %l = or i32 %x, 1
      7   %r = or i32 %x, 2
      8   %z = and i32 %l, %r
      9   ret i32 %z
     10 ; CHECK: ret i32 %x
     11 }
     12 
     13 define i32 @factorize2(i32 %x) {
     14 ; CHECK: @factorize2
     15 ; 3*X - 2*X -> X
     16   %l = mul i32 3, %x
     17   %r = mul i32 2, %x
     18   %z = sub i32 %l, %r
     19   ret i32 %z
     20 ; CHECK: ret i32 %x
     21 }
     22 
     23 define i32 @factorize3(i32 %x, i32 %a, i32 %b) {
     24 ; CHECK: @factorize3
     25 ; (X | (A|B)) & (X | B) -> X | ((A|B) & B) -> X | B
     26   %aORb = or i32 %a, %b
     27   %l = or i32 %x, %aORb
     28   %r = or i32 %x, %b
     29   %z = and i32 %l, %r
     30   ret i32 %z
     31 ; CHECK: ret i32 %r
     32 }
     33 
     34 define i32 @factorize4(i32 %x, i32 %y) {
     35 ; CHECK: @factorize4
     36   %sh = shl i32 %y, 1
     37   %ml = mul i32 %sh, %x
     38   %mr = mul i32 %x, %y
     39   %s = sub i32 %ml, %mr
     40   ret i32 %s
     41 ; CHECK: ret i32 %mr
     42 }
     43 
     44 define i32 @factorize5(i32 %x, i32 %y) {
     45 ; CHECK: @factorize5
     46   %sh = mul i32 %y, 2
     47   %ml = mul i32 %sh, %x
     48   %mr = mul i32 %x, %y
     49   %s = sub i32 %ml, %mr
     50   ret i32 %s
     51 ; CHECK: ret i32 %mr
     52 }
     53 
     54 define i32 @expand(i32 %x) {
     55 ; CHECK: @expand
     56 ; ((X & 1) | 2) & 1 -> ((X & 1) & 1) | (2 & 1) -> (X & 1) | 0 -> X & 1
     57   %a = and i32 %x, 1
     58   %b = or i32 %a, 2
     59   %c = and i32 %b, 1
     60   ret i32 %c
     61 ; CHECK: ret i32 %a
     62 }
     63