1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 3
2 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
4 define i8 @avg_lsb(i8 %a, i8 %b) {
5 ; CHECK-LABEL: define i8 @avg_lsb(
6 ; CHECK-SAME: i8 [[A:%.*]], i8 [[B:%.*]]) {
7 ; CHECK-NEXT: [[REM:%.*]] = and i8 [[A]], 1
8 ; CHECK-NEXT: [[DIV2:%.*]] = and i8 [[REM]], [[B]]
9 ; CHECK-NEXT: ret i8 [[DIV2]]
13 %add = add nuw nsw i8 %rem1, %rem
14 %div2 = lshr i8 %add, 1
18 define i8 @avg_lsb_mismatch(i8 %a, i8 %b) {
19 ; CHECK-LABEL: define i8 @avg_lsb_mismatch(
20 ; CHECK-SAME: i8 [[A:%.*]], i8 [[B:%.*]]) {
21 ; CHECK-NEXT: [[REM:%.*]] = and i8 [[A]], 1
22 ; CHECK-NEXT: [[REM1:%.*]] = and i8 [[B]], 3
23 ; CHECK-NEXT: [[ADD:%.*]] = add nuw nsw i8 [[REM1]], [[REM]]
24 ; CHECK-NEXT: [[DIV2:%.*]] = lshr i8 [[ADD]], 1
25 ; CHECK-NEXT: ret i8 [[DIV2]]
29 %add = add nuw nsw i8 %rem1, %rem
30 %div2 = lshr i8 %add, 1
34 define <2 x i8> @avg_lsb_vector(<2 x i8> %a, <2 x i8> %b) {
35 ; CHECK-LABEL: define <2 x i8> @avg_lsb_vector(
36 ; CHECK-SAME: <2 x i8> [[A:%.*]], <2 x i8> [[B:%.*]]) {
37 ; CHECK-NEXT: [[REM:%.*]] = and <2 x i8> [[A]], <i8 1, i8 1>
38 ; CHECK-NEXT: [[DIV2:%.*]] = and <2 x i8> [[REM]], [[B]]
39 ; CHECK-NEXT: ret <2 x i8> [[DIV2]]
41 %rem = and <2 x i8> %a, <i8 1, i8 1>
42 %rem1 = and <2 x i8> %b, <i8 1, i8 1>
43 %add = add nuw nsw <2 x i8> %rem1, %rem
44 %div2 = lshr <2 x i8> %add, <i8 1, i8 1>