1 ; NOTE: Assertions have been autogenerated by update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
4 define i32 @func1(i32 %a, i32 %b) {
6 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 %a, 1
7 ; CHECK-NEXT: [[TMP3:%.*]] = or i32 [[TMP1]], %b
8 ; CHECK-NEXT: ret i32 [[TMP3]]
11 %tmp1 = and i32 %tmp, 1
12 %tmp2 = and i32 %b, -2
13 %tmp3 = or i32 %tmp1, %tmp2
17 define i32 @func2(i32 %a, i32 %b) {
18 ; CHECK-LABEL: @func2(
19 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 %a, 1
20 ; CHECK-NEXT: [[TMP3:%.*]] = or i32 [[TMP1]], %b
21 ; CHECK-NEXT: ret i32 [[TMP3]]
24 %tmp1 = and i32 1, %tmp
25 %tmp2 = and i32 -2, %b
26 %tmp3 = or i32 %tmp1, %tmp2
30 define i32 @func3(i32 %a, i32 %b) {
31 ; CHECK-LABEL: @func3(
32 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 %a, 1
33 ; CHECK-NEXT: [[TMP3:%.*]] = or i32 [[TMP1]], %b
34 ; CHECK-NEXT: ret i32 [[TMP3]]
37 %tmp1 = and i32 %tmp, 1
38 %tmp2 = and i32 %b, -2
39 %tmp3 = or i32 %tmp2, %tmp1
43 define i32 @func4(i32 %a, i32 %b) {
44 ; CHECK-LABEL: @func4(
45 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 %a, 1
46 ; CHECK-NEXT: [[TMP3:%.*]] = or i32 [[TMP1]], %b
47 ; CHECK-NEXT: ret i32 [[TMP3]]
50 %tmp1 = and i32 1, %tmp
51 %tmp2 = and i32 -2, %b
52 %tmp3 = or i32 %tmp2, %tmp1
57 ; and ({x}or X, Y), C --> {x}or X, (and Y, C)
58 ; ...in the following 5 tests.
60 define i8 @and_or_hoist_mask(i8 %a, i8 %b) {
61 ; CHECK-LABEL: @and_or_hoist_mask(
62 ; CHECK-NEXT: [[SH:%.*]] = lshr i8 %a, 6
63 ; CHECK-NEXT: [[B_MASKED:%.*]] = and i8 %b, 3
64 ; CHECK-NEXT: [[AND:%.*]] = or i8 [[SH]], [[B_MASKED]]
65 ; CHECK-NEXT: ret i8 [[AND]]
73 define <2 x i8> @and_xor_hoist_mask_vec_splat(<2 x i8> %a, <2 x i8> %b) {
74 ; CHECK-LABEL: @and_xor_hoist_mask_vec_splat(
75 ; CHECK-NEXT: [[SH:%.*]] = lshr <2 x i8> %a, <i8 6, i8 6>
76 ; CHECK-NEXT: [[B_MASKED:%.*]] = and <2 x i8> %b, <i8 3, i8 3>
77 ; CHECK-NEXT: [[AND:%.*]] = xor <2 x i8> [[SH]], [[B_MASKED]]
78 ; CHECK-NEXT: ret <2 x i8> [[AND]]
80 %sh = lshr <2 x i8> %a, <i8 6, i8 6>
81 %xor = xor <2 x i8> %sh, %b
82 %and = and <2 x i8> %xor, <i8 3, i8 3>
86 define i8 @and_xor_hoist_mask_commute(i8 %a, i8 %b) {
87 ; CHECK-LABEL: @and_xor_hoist_mask_commute(
88 ; CHECK-NEXT: [[C:%.*]] = mul i8 %b, 43
89 ; CHECK-NEXT: [[SH:%.*]] = lshr i8 %a, 6
90 ; CHECK-NEXT: [[C_MASKED:%.*]] = and i8 [[C]], 3
91 ; CHECK-NEXT: [[AND:%.*]] = xor i8 [[C_MASKED]], [[SH]]
92 ; CHECK-NEXT: ret i8 [[AND]]
94 %c = mul i8 %b, 43 ; thwart complexity-based ordering
101 define <2 x i8> @and_or_hoist_mask_commute_vec_splat(<2 x i8> %a, <2 x i8> %b) {
102 ; CHECK-LABEL: @and_or_hoist_mask_commute_vec_splat(
103 ; CHECK-NEXT: [[C:%.*]] = mul <2 x i8> %b, <i8 43, i8 43>
104 ; CHECK-NEXT: [[SH:%.*]] = lshr <2 x i8> %a, <i8 6, i8 6>
105 ; CHECK-NEXT: [[C_MASKED:%.*]] = and <2 x i8> [[C]], <i8 3, i8 3>
106 ; CHECK-NEXT: [[AND:%.*]] = or <2 x i8> [[C_MASKED]], [[SH]]
107 ; CHECK-NEXT: ret <2 x i8> [[AND]]
109 %c = mul <2 x i8> %b, <i8 43, i8 43> ; thwart complexity-based ordering
110 %sh = lshr <2 x i8> %a, <i8 6, i8 6>
111 %or = or <2 x i8> %c, %sh
112 %and = and <2 x i8> %or, <i8 3, i8 3>
116 ; Don't transform if the 'or' has multiple uses because that would increase instruction count.
118 define i8 @and_or_do_not_hoist_mask(i8 %a, i8 %b) {
119 ; CHECK-LABEL: @and_or_do_not_hoist_mask(
120 ; CHECK-NEXT: [[SH:%.*]] = lshr i8 %a, 6
121 ; CHECK-NEXT: [[OR:%.*]] = or i8 [[SH]], %b
122 ; CHECK-NEXT: [[AND:%.*]] = and i8 [[OR]], 3
123 ; CHECK-NEXT: [[EXTRA_USE_OF_OR:%.*]] = mul i8 [[OR]], [[AND]]
124 ; CHECK-NEXT: ret i8 [[EXTRA_USE_OF_OR]]
129 %extra_use_of_or = mul i8 %or, %and
130 ret i8 %extra_use_of_or