blob: 4aac8dd5884a9dfa5be4a962d673861704036296 [file] [log] [blame]
Duncan Sands3421d902010-12-21 13:32:22 +00001; RUN: opt < %s -instsimplify -S | FileCheck %s
2
3define i32 @factorize(i32 %x, i32 %y) {
4; CHECK: @factorize
Duncan Sands9bd2c2e2010-12-21 13:39:20 +00005; (X | 1) & (X | 2) -> X | (1 & 2) -> X
Duncan Sands3421d902010-12-21 13:32:22 +00006 %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
Duncan Sands025c98b2010-12-21 15:12:22 +000013define 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
Duncan Sands3421d902010-12-21 13:32:22 +000023define i32 @expand(i32 %x) {
24; CHECK: @expand
25; ((X & 1) | 2) & 1 -> ((X & 1) & 1) | (2 & 1) -> (X & 1) | 0 -> X & 1
26 %a = and i32 %x, 1
27 %b = or i32 %a, 2
28 %c = and i32 %b, 1
29 ret i32 %c
30; CHECK: ret i32 %a
31}