1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
4 define i32 @factorize(i32 %x, i32 %y) {
5 ; CHECK-LABEL: @factorize(
6 ; CHECK-NEXT: ret i32 [[X:%.*]]
8 ; (X | 1) & (X | 2) -> X | (1 & 2) -> X
15 define i32 @factorize2(i32 %x) {
16 ; CHECK-LABEL: @factorize2(
17 ; CHECK-NEXT: ret i32 [[X:%.*]]
26 define i32 @factorize3(i32 %x, i32 %a, i32 %b) {
27 ; CHECK-LABEL: @factorize3(
28 ; CHECK-NEXT: [[Z:%.*]] = or i32 [[B:%.*]], [[X:%.*]]
29 ; CHECK-NEXT: ret i32 [[Z]]
31 ; (X | (A|B)) & (X | B) -> X | ((A|B) & B) -> X | B
39 define i32 @factorize4(i32 %x, i32 %y) {
40 ; CHECK-LABEL: @factorize4(
41 ; CHECK-NEXT: [[S:%.*]] = mul i32 [[Y:%.*]], [[X:%.*]]
42 ; CHECK-NEXT: ret i32 [[S]]
44 ; ((Y << 1) * X) - (X * Y) -> (X * (Y * 2 - Y)) -> (X * Y)
52 define i32 @factorize5(i32 %x, i32 %y) {
53 ; CHECK-LABEL: @factorize5(
54 ; CHECK-NEXT: [[S:%.*]] = mul i32 [[Y:%.*]], [[X:%.*]]
55 ; CHECK-NEXT: ret i32 [[S]]
57 ; ((Y * 2) * X) - (X * Y) -> (X * Y)
65 define i32 @expand(i32 %x) {
66 ; CHECK-LABEL: @expand(
67 ; CHECK-NEXT: [[A:%.*]] = and i32 [[X:%.*]], 1
68 ; CHECK-NEXT: ret i32 [[A]]
70 ; ((X & 1) | 2) & 1 -> ((X & 1) & 1) | (2 & 1) -> (X & 1) | 0 -> X & 1